/* =======================================================
   KSP Finance Worker — Stylesheet
   Theme: Finance Blue (based on ksp-report-worker)
   โทน: น้ำเงินมืด บัญชีมืออาชีพ
======================================================= */

/* ─── Theme Variables ─── */
:root {
  --bg: #f0f4f8;
  --paper: #fff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --chip: #e0e7ef;
  --accent: #1e3a8a;
  --accent-light: #dbeafe;
  --accent-hover: #1e40af;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(30, 58, 138, .10);
  --shadow-sm: 0 4px 12px rgba(30, 58, 138, .06);
  --success: #166534;
  --success-bg: #dcfce7;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --warning: #854d0e;
  --warning-bg: #fef9c3;
  --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, #e0e7ef 0%, #bfdbfe 50%, #93c5fd 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(30, 58, 138, .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: linear-gradient(135deg, #1e3a8a, #2563eb);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 12px rgba(30, 58, 138, .15);
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-title { font-weight: 700; font-size: 17px; color: #fff; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.15);
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  cursor: pointer;
  transition: background var(--transition);
}
.user-chip:hover { background: rgba(255,255,255,0.25); }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.3);
}

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

.dropdown-arrow { font-size: 10px; color: rgba(255,255,255,.7); margin-left: 2px; }

.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-menu.active {
  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);
  overflow-x: auto;
}

.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);
  white-space: nowrap;
}
.nav-tab:hover { background: var(--bg); }
.nav-tab.active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(30, 58, 138, .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: 1100px;
  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); }

/* ─── 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(30, 58, 138, .08);
}
textarea.form-input { min-height: 80px; resize: vertical; }

/* ─── Table ─── */
.table-container { width: 100%; overflow-x: auto; border-radius: 8px; border: 1px solid var(--line); margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
th { background: #f8fafc; padding: 12px 16px; text-align: left; font-weight: 600; color: #334155; border-bottom: 2px solid var(--line); position: sticky; top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td { padding: 10px 16px; border-bottom: 1px solid var(--line); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:hover td { background: #f1f5f9; }
.amount-col { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
/* Column widths for list table */
.col-date { width: 90px; }
.col-doc { width: 150px; }
.col-name { width: auto; min-width: 200px; }
.col-amount { width: 120px; }
.col-status { width: 110px; }

/* ─── Source Badge ─── */
.source-badge { padding: 2px 6px; border-radius: 6px; font-size: 10px; font-weight: 700; }
.source-badge.src-fa { background: #e0f2fe; color: #0369a1; }
.source-badge.src-ksp { background: #fae8ff; color: #7e22ce; }

/* ─── Status Badges ─── */
.status-badge { padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; display: inline-block; white-space: nowrap; }
.status-badge.st-wait { background: #e0f2fe; color: #0284c7; }
.status-badge.st-done { background: #dcfce7; color: #166534; }
.status-badge.st-partial { background: #fef9c3; color: #854d0e; }
.status-badge.st-void { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }
.status-badge.st-default { background: #f1f5f9; color: #475569; }

/* ─── Editor Form ─── */
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.editor-grid .span-2 { grid-column: span 2; }
.item-row { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.item-row input { flex: 1; }
.item-row .item-total { min-width: 100px; text-align: right; font-weight: 600; color: var(--accent); }
.totals-box { width: 320px; margin-left: auto; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.totals-row { display: flex; justify-content: space-between; }
.totals-row.grand { font-size: 16px; border-top: 2px solid var(--line); padding-top: 8px; margin-top: 4px; font-weight: 700; color: var(--accent); }

@media (max-width: 640px) {
  .editor-grid { grid-template-columns: 1fr; }
  .editor-grid .span-2 { grid-column: span 1; }
  .totals-box { width: 100%; }
  table { font-size: 12px; }
  th, td { padding: 8px 10px; }
}

/* ─── 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), #3b82f6);
  color: #fff;
  box-shadow: 0 4px 16px rgba(30, 58, 138, .25);
}
.btn-accent:hover { box-shadow: 0 6px 20px rgba(30, 58, 138, .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); }

/* ─── 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; }

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

/* ─── Responsive ─── */
/* ─── Payment Recorder ─── */
.nav-tab-pay { background: linear-gradient(135deg, #f59e0b22, #f59e0b08); border: 1px solid #f59e0b44; }
.nav-tab-pay.active { background: linear-gradient(135deg, #f59e0b, #d97706); color: #fff !important; border-color: #d97706; }

.pay-step { display: flex; gap: 16px; padding: 16px; border-radius: 12px; background: var(--row-hover); }
.pay-step-num {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; flex-shrink: 0;
}
.pay-step-content { flex: 1; display: flex; flex-direction: column; gap: 8px; }

.cust-results {
  max-height: 200px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg);
}
.cust-results .cust-item {
  padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line);
  transition: background .15s;
}
.cust-results .cust-item:hover { background: var(--accent-light); }
.cust-results .cust-item:last-child { border-bottom: none; }
.cust-results .cust-id { font-size: 11px; color: var(--muted); font-weight: 600; }
.cust-results .cust-name { font-weight: 600; color: var(--heading); }
.cust-results .cust-phone { font-size: 12px; color: var(--muted); }

.cust-selected-card {
  padding: 12px 16px; border-radius: 10px; background: linear-gradient(135deg, #dbeafe, #ede9fe);
  border: 1px solid #93c5fd; display: flex; justify-content: space-between; align-items: center;
}
.cust-selected-card .cust-info { display: flex; flex-direction: column; gap: 2px; }
.cust-selected-card .cust-info .name { font-weight: 700; color: var(--heading); }
.cust-selected-card .cust-info .meta { font-size: 12px; color: var(--muted); }

.doc-radio-list { display: flex; flex-direction: column; gap: 4px; max-height: 250px; overflow-y: auto; }
.doc-radio-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  transition: all .15s;
}
.doc-radio-item:hover { border-color: var(--accent); background: var(--accent-light); }
.doc-radio-item.selected { border-color: var(--accent); background: #dbeafe; }
.doc-radio-item input[type="radio"] { accent-color: var(--accent); }

.file-drop-zone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 24px;
  text-align: center; cursor: pointer; transition: all .2s;
  background: var(--bg);
}
.file-drop-zone:hover, .file-drop-zone.drag-over {
  border-color: var(--accent); background: var(--accent-light);
}
.file-preview { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.file-preview img { max-height: 120px; border-radius: 8px; margin-top: 8px; }

.pay-result {
  padding: 16px; border-radius: 12px;
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  border: 1px solid #34d399;
}
.pay-result .pay-ref {
  font-size: 22px; font-weight: 800; color: #065f46; letter-spacing: 1px;
}
.pay-result .pay-msg { font-size: 13px; color: #047857; margin-top: 4px; }

/* Payment status badges */
.pay-status { padding: 2px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.pay-status.unused { background: #fef3c7; color: #92400e; }
.pay-status.used { background: #d1fae5; color: #065f46; }
.pay-status.cancelled { background: #fee2e2; color: #991b1b; }

@media (max-width: 640px) {
  .app-main { padding: 12px; gap: 12px; }
  .card { padding: 14px; }
  .login-card { padding: 28px 18px; }
  .user-chip span { display: none; }
  .pay-step { flex-direction: column; gap: 10px; }
  .pay-step-num { width: 28px; height: 28px; font-size: 12px; }
}
