/* =======================================================
   KSP Report Worker — Stylesheet
   Theme: KSP Warm Brown (จาก ksp-profile)
   โทน: น้ำตาลอุ่น, พื้นครีม, accent น้ำตาลเข้ม
======================================================= */

/* ─── Theme Variables (sync กับ ksp-profile) ─── */
:root {
  --bg: #f7f3ef;
  --paper: #fff;
  --ink: #3a2f27;
  --muted: #8b7e74;
  --line: #e7dfd8;
  --chip: #efe7df;
  --accent: #6b4a33;
  --accent-light: #efdccf;
  --accent-hover: #5a3d2b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(128, 98, 72, .12);
  --shadow-sm: 0 4px 12px rgba(128, 98, 72, .08);
  --success: #2e7d32;
  --success-bg: #eaf7ea;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --warning: #b58b63;
  --warning-bg: #fef3e2;
  --font: 'Noto Sans Thai', 'Inter', system-ui, -apple-system, sans-serif;
  --transition: .2s ease;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font: 15px/1.65 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ─── Screens ─── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100vh; }

/* ─── Login Screen ─── */
#login-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #f7efe8 0%, #efe1d3 50%, #e8d5c4 100%);
  padding: 20px;
}

.login-card {
  width: min(420px, 94vw);
  background: var(--paper);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 36px 28px;
  text-align: center;
  animation: fadeUp .5s ease;
}

.login-logo { margin-bottom: 12px; }
.login-logo svg { filter: drop-shadow(0 4px 8px rgba(107, 74, 51, .15)); }

.login-card h1 {
  margin: 8px 0 4px;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.login-sub {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 14px;
}

.login-footer {
  margin-top: 16px;
  font-size: 12px;
  color: var(--muted);
}

#google-signin-btn {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

/* ─── App Header ─── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(128, 98, 72, .06);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title {
  font-weight: 700;
  font-size: 17px;
  color: var(--accent);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--chip);
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: default;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
}

.user-dropdown-container {
  position: relative;
}

.dropdown-arrow {
  font-size: 10px;
  color: var(--muted);
  margin-left: 2px;
  transition: transform var(--transition);
}

.user-dropdown-container.active .dropdown-arrow {
  transform: rotate(180deg);
}

.user-chip { cursor: pointer; }
.user-chip:hover { background: #e6dacd; }

.user-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-sm);
  min-width: 160px;
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition);
  z-index: 100;
}

.user-dropdown-container.active .user-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
}

.dropdown-item:hover { background: var(--bg); }
.text-danger { color: var(--danger); }
.text-danger:hover { background: var(--danger-bg); color: #991b1b; }

/* ─── Tabs ─── */
.nav-tabs {
  display: flex;
  gap: 8px;
  background: var(--paper);
  padding: 8px;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.nav-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition);
}

.nav-tab:hover { background: var(--bg); }
.nav-tab.active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(107, 74, 51, .2); }

.view-content { display: none; flex-direction: column; gap: 16px; animation: fadeUp .3s ease; }
.view-content.active { display: flex; }

/* ─── Main Layout ─── */
.app-main {
  flex: 1;
  padding: 16px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ─── Card ─── */
.card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.label-icon { font-size: 16px; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 0 6px;
}

/* ─── Form Elements ─── */
.form-row { margin-bottom: 14px; }
.form-row:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(107, 74, 51, .08);
}

textarea.form-input {
  min-height: 80px;
  resize: vertical;
}

/* ─── Item Block ─── */
.report-item {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  animation: fadeUp .3s ease;
  transition: border-color var(--transition);
}

.report-item:hover { border-color: var(--accent-light); }

.item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.item-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.item-actions { display: flex; gap: 6px; }

.item-images {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.item-images .thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #fff;
}

.item-images .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-images .thumb .thumb-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition);
}
.item-images .thumb .thumb-remove:hover { background: rgba(0, 0, 0, .75); }

/* Task badge in item */
.task-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

/* ─── Tasks List ─── */
.tasks-list { display: flex; flex-direction: column; gap: 8px; }

.task-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.task-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.task-card.selected {
  border-color: var(--accent);
  background: var(--accent-light);
}

.task-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--muted);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  transition: all var(--transition);
}

.task-card.selected .task-checkbox {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.task-info { flex: 1; }
.task-title { font-weight: 600; font-size: 14px; }
.task-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }

.task-meta {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.priority-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  text-transform: uppercase;
}
.priority-pill.urgent { background: var(--danger-bg); color: var(--danger); }
.priority-pill.high { background: #fff3cd; color: #856404; }
.priority-pill.medium { background: var(--chip); color: var(--accent); }
.priority-pill.low { background: #e8f5e9; color: #2e7d32; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: default; transform: none; }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; width: 100%; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-accent {
  background: linear-gradient(135deg, var(--accent), #8b6043);
  color: #fff;
  box-shadow: 0 4px 16px rgba(107, 74, 51, .25);
}
.btn-accent:hover { box-shadow: 0 6px 20px rgba(107, 74, 51, .35); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 5px 12px;
  font-size: 12px;
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 5px 12px;
  font-size: 12px;
}
.btn-danger:hover { background: var(--danger-bg); }

.btn-icon { font-size: 18px; }

/* ─── Submit Section ─── */
.submit-section { text-align: center; padding-bottom: 32px; }
.submit-hint { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ─── Empty State ─── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}
.empty-icon { font-size: 40px; margin-bottom: 8px; opacity: .6; }
.empty-state p { margin: 0; font-size: 14px; }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--ink);
  color: #fff;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  z-index: 999;
  opacity: 0;
  transition: all .35s cubic-bezier(.22, .68, 0, 1.1);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ─── Animations ─── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(107, 74, 51, .15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  display: inline-block;
}

/* ─── Responsive ─── */
@media (max-width: 640px) {
  .app-main { padding: 12px; gap: 12px; }
  .card { padding: 14px; }
  .login-card { padding: 28px 18px; }
  .user-chip span { display: none; }
  .form-section .form-row { margin-bottom: 10px; }
}

@media (min-width: 768px) {
  .app-main { padding: 24px; gap: 20px; }
  .form-section { display: flex; gap: 16px; }
  .form-section .form-row { flex: 1; margin-bottom: 0; }
}
