* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "Segoe UI", "Sarabun", "Tahoma", sans-serif;
  background: #f4f6fb; color: #1f2937;
}
.hidden { display: none !important; }
.screen { min-height: 100vh; }
.muted { color: #6b7280; font-size: 13px; }
.small { font-size: 11px; }
.mt { margin-top: 12px; display: block; }
code { background: #f1f5f9; padding: 1px 5px; border-radius: 3px; font-size: 12px; }

/* ===== LOGIN ===== */
#loginScreen {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #064e3b 0%, #0f766e 50%, #0e7490 100%);
}
.login-card {
  background: #fff; padding: 32px; border-radius: 14px;
  width: 460px; max-width: 92vw;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; color: #064e3b; }
.login-card .subtitle { margin: 0 0 20px; color: #6b7280; font-size: 13px; }
.login-tabs { display: flex; gap: 4px; margin: 0 0 14px; border-bottom: 2px solid #e5e7eb; }
.login-tabs .lt {
  flex: 1; background: transparent; border: 0; padding: 8px;
  font-weight: 600; color: #6b7280; cursor: pointer; border-bottom: 3px solid transparent;
}
.login-tabs .lt.active { color: #0f766e; border-bottom-color: #0f766e; }
.login-card label { display: block; font-size: 13px; margin: 12px 0 4px; color: #374151; }
.login-card select, .login-card input {
  width: 100%; padding: 10px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px;
}
.login-card button.primary {
  width: 100%; margin-top: 16px; padding: 12px;
  background: #0f766e; color: #fff; border: 0; border-radius: 8px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.login-card button.primary:hover { background: #115e59; }
.user-mgmt { margin-top: 18px; border-top: 1px solid #e5e7eb; padding-top: 12px; }
.user-mgmt summary { cursor: pointer; color: #0f766e; font-size: 13px; }
.user-mgmt .row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr auto; gap: 6px; margin-top: 10px; }
.user-mgmt .row input, .user-mgmt .row select {
  padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 12px;
}
.user-mgmt .row button {
  background: #10b981; color: #fff; border: 0; padding: 0 10px; border-radius: 6px; cursor: pointer;
}

/* ===== TOPBAR ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: #064e3b; color: #fff; padding: 10px 16px; flex-wrap: wrap; gap: 8px;
}
.topbar .brand { font-weight: 700; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav .tab {
  background: transparent; color: #cbd5e1; border: 0; padding: 8px 12px;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.topbar nav .tab:hover { background: #065f46; color: #fff; }
.topbar nav .tab.active { background: #0f766e; color: #fff; }
.topbar nav .tab.admin-only { background: #7c3aed; color: #fff; }
.topbar nav .tab.admin-only.active { background: #6d28d9; }

/* Grouped dropdown nav */
.navgrp { position: relative; display: inline-block; }
.navgrp-btn {
  background: transparent; color: #cbd5e1; border: 0; padding: 8px 12px;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.navgrp-btn:hover, .navgrp:hover .navgrp-btn { background: #065f46; color: #fff; }
.navgrp-menu {
  display: none; position: absolute; top: 100%; left: 0; margin-top: 4px;
  background: #064e3b; border: 1px solid #065f46; border-radius: 6px;
  box-shadow: 0 8px 20px rgba(0,0,0,.4); min-width: 200px; padding: 4px;
  z-index: 50;
}
.navgrp:hover .navgrp-menu { display: block; }
.navgrp-menu .tab {
  display: block; width: 100%; text-align: left;
  background: transparent; color: #d1fae5; border: 0;
  padding: 8px 12px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
.navgrp-menu .tab:hover { background: #065f46; color: #fff; }
.navgrp-menu .tab.active { background: #0f766e; color: #fff; }
.navgrp.has-active > .navgrp-btn { background: #0f766e; color: #fff; }

/* highlight on hover for tables */
table.gtbl tbody tr:nth-child(even) { background: #f9fafb; }
table.gtbl tbody tr:hover { background: #ecfdf5; }

/* search results */
.searchhit { box-shadow: 0 0 0 2px #f59e0b inset; }
.topbar .userbox { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.topbar .userbox button {
  background: #064e3b; color: #fff; border: 1px solid #065f46; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.topbar .userbox button:hover { background: #065f46; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.tabpanel { display: none; }
.tabpanel.active { display: block; }
h2 { margin: 0 0 16px; color: #064e3b; }
h3 { margin: 24px 0 10px; color: #374151; }

/* ===== CARDS ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.card {
  background: #fff; border-radius: 10px; padding: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
  border-left: 4px solid #0f766e;
}
.card .num { font-size: 26px; font-weight: 700; color: #064e3b; }
.card .lbl { font-size: 13px; color: #374151; margin-top: 4px; }
.card.warn { border-left-color: #f59e0b; }
.card.warn .num { color: #b45309; }
.card.big .num { color: #16a34a; }
.card.big { border-left-color: #16a34a; }
.card.danger { border-left-color: #ef4444; }
.card.danger .num { color: #b91c1c; }
.card .hint { font-size: 11px; color: #0f766e; margin-top: 4px; }
.card.link { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.card.link:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.1); }

/* group color cards */
.card.g-AR    { border-left-color: #0ea5e9; }
.card.g-AR    .num { color: #0369a1; }
.card.g-AP    { border-left-color: #f59e0b; }
.card.g-AP    .num { color: #b45309; }
.card.g-COST  { border-left-color: #ec4899; }
.card.g-COST  .num { color: #be185d; }
.card.g-ASSET { border-left-color: #8b5cf6; }
.card.g-ASSET .num { color: #6d28d9; }

/* ===== Group badges ===== */
.gbadge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px;
  background: #ecfeff; color: #0e7490; font-weight: 600;
}
.gbadge.g-AR    { background: #dbeafe; color: #1e3a8a; }
.gbadge.g-AP    { background: #fef3c7; color: #92400e; }
.gbadge.g-COST  { background: #fce7f3; color: #9d174d; }
.gbadge.g-ASSET { background: #ede9fe; color: #5b21b6; }
.gbadge.g-OTHER { background: #f3f4f6; color: #374151; }

/* ===== FILTERS ===== */
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input {
  padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; background: #fff;
}
.filters input { min-width: 150px; }
.filters .grow { flex: 1; min-width: 180px; }
.filters button {
  background: #e5e7eb; color: #374151; border: 0; padding: 8px 12px;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.filters button:hover { background: #d1d5db; }
.filters button.primary { background: #0f766e; color: #fff; }
.filters button.primary:hover { background: #115e59; }
.filters .legend { font-size: 12px; color: #6b7280; margin-left: 8px; }
.filter-banner {
  background: #ecfdf5; border: 1px solid #a7f3d0; padding: 8px 12px;
  border-radius: 6px; margin-bottom: 10px; color: #065f46; font-size: 13px;
}

/* ===== DAILY MATRIX ===== */
.matrix-wrap {
  background: #fff; border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.05);
  overflow: auto; max-height: calc(100vh - 220px);
}
table.matrix {
  border-collapse: separate; border-spacing: 0; font-size: 12px; min-width: 100%;
}
table.matrix th, table.matrix td {
  border-right: 1px solid #e5e7eb; border-bottom: 1px solid #e5e7eb; padding: 6px 8px;
  vertical-align: top; background: #fff;
}
table.matrix thead th {
  position: sticky; top: 0; z-index: 5;
  background: #064e3b; color: #fff; text-align: center;
  font-weight: 600; padding: 8px 6px; white-space: nowrap;
  border-right: 1px solid #065f46;
}
table.matrix thead th.col-item { z-index: 6; left: 0; min-width: 280px; max-width: 360px; text-align: left; }
table.matrix thead th.col-date { min-width: 120px; }
table.matrix tbody td.cell-item {
  position: sticky; left: 0; z-index: 3; background: #fff;
  font-weight: 600; min-width: 280px; max-width: 360px;
  border-right: 2px solid #d1d5db; cursor: pointer;
}
table.matrix tbody td.cell-item:hover { background: #f0fdfa; }
table.matrix tbody tr.grp-head td {
  background: linear-gradient(90deg, #ecfdf5, #fff); color: #065f46; font-weight: 700;
  font-size: 13px; padding: 6px 10px; border-top: 2px solid #10b981;
}
table.matrix tbody tr.grp-head td.cell-item { background: #d1fae5; color: #065f46; }
table.matrix tbody td.cell-data {
  cursor: pointer; min-width: 120px; max-width: 220px;
  white-space: pre-wrap; word-break: break-word; line-height: 1.35;
}
table.matrix tbody td.cell-data:hover { background: #fef9c3; }
table.matrix tbody td.cell-data.s-done    { background: #dcfce7; }
table.matrix tbody td.cell-data.s-pending { background: #fef3c7; }
table.matrix tbody td.cell-data.s-issue   { background: #fee2e2; color: #991b1b; }
table.matrix tbody td.cell-data.s-na      { background: #f3f4f6; color: #6b7280; }
table.matrix tbody td.cell-data.is-today  { box-shadow: inset 0 0 0 2px #0f766e; }
table.matrix tbody td.cell-data .v { font-size: 11px; color: #065f46; }
table.matrix tbody td.cell-data.s-issue .v { color: #991b1b; }
table.matrix tbody td.cell-data.s-pending .v { color: #92400e; }

/* ===== Generic Tables ===== */
.tbl-wrap { background:#fff; border-radius:10px; box-shadow:0 1px 3px rgba(0,0,0,.05); overflow:auto; }
table.gtbl { border-collapse: collapse; width: 100%; font-size: 13px; }
table.gtbl th, table.gtbl td { padding: 8px 10px; border-bottom: 1px solid #e5e7eb; text-align: left; }
table.gtbl th { background: #064e3b; color: #fff; font-weight: 600; position: sticky; top: 0; z-index: 2; }
table.gtbl tbody tr:hover { background: #f0fdfa; }
table.gtbl td.center, table.gtbl th.center { text-align: center; }
table.gtbl td.right, table.gtbl th.right { text-align: right; }
table.gtbl td.num { font-variant-numeric: tabular-nums; text-align: right; }

/* status pills */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
}
.pill.s-sent      { background: #fef3c7; color: #92400e; }
.pill.s-returned  { background: #dcfce7; color: #166534; }
.pill.s-wait_tech { background: #fee2e2; color: #991b1b; }
.pill.s-scrapped  { background: #f3f4f6; color: #374151; }
.pill.s-moved     { background: #fef3c7; color: #92400e; }
.pill.s-permanent { background: #ddd6fe; color: #5b21b6; }
.pill.s-done      { background: #dcfce7; color: #166534; }
.pill.s-pending   { background: #fef3c7; color: #92400e; }
.pill.s-issue     { background: #fee2e2; color: #991b1b; }
.pill.s-na        { background: #f3f4f6; color: #6b7280; }

/* ===== FORM ===== */
.form {
  background: #fff; padding: 20px; border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05); max-width: 900px;
}
.form label { display: block; font-size: 13px; color: #374151; margin: 10px 0 4px; }
.form input, .form select, .form textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px;
  font-family: inherit; font-size: 14px;
}
.form .grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 16px; }
.form .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 16px; }
.form .req { color: #ef4444; }
button.primary {
  background: #0f766e; color: #fff; border: 0; padding: 10px 18px;
  border-radius: 8px; cursor: pointer; font-weight: 600;
}
button.primary:hover { background: #115e59; }
button.success { background: #16a34a; color:#fff; border:0; padding: 8px 14px; border-radius: 6px; cursor: pointer; }
button.success:hover { background: #15803d; }
button.danger { background: #ef4444; color:#fff; border:0; padding: 8px 14px; border-radius: 6px; cursor: pointer; }
button.danger:hover { background: #dc2626; }
button.icon { background: transparent; border:0; cursor:pointer; font-size: 16px; padding: 4px 6px; }
button.icon:hover { background: #f3f4f6; border-radius: 6px; }

/* ===== MODAL ===== */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 14px;
}
.modal {
  background: #fff; border-radius: 12px; padding: 22px 24px;
  width: 640px; max-width: 96vw; max-height: 92vh; overflow: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.modal h3 { margin: 0 0 6px; color: #064e3b; }
.modal .sub { color: #6b7280; font-size: 12px; margin-bottom: 14px; }
.modal .actions {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap;
}

/* ===== SIGNATURE PAD ===== */
.sigpad-wrap {
  border: 1px dashed #94a3b8; border-radius: 8px; background: #fff; margin-top: 6px;
}
.sigpad { width: 100%; height: 130px; border-radius: 8px; touch-action: none; cursor: crosshair; display:block; }
.sig-row { display:flex; gap: 8px; margin-top: 4px; }
.sig-row button { background:#e5e7eb; border:0; padding:4px 10px; border-radius:6px; cursor:pointer; font-size:12px; }
img.sigimg { max-width: 200px; border: 1px solid #e5e7eb; border-radius: 6px; padding: 4px; background:#fff; }

/* ===== Status chips for value row ===== */
.svals { display:flex; gap: 4px; flex-wrap: wrap; margin-top:4px; }
.svals .chip {
  display: inline-block; font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: #e5e7eb; color: #374151; cursor: pointer;
}
.svals .chip:hover { background: #d1d5db; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  table.matrix thead th.col-item, table.matrix tbody td.cell-item { min-width: 200px; max-width: 240px; }
  .form .grid2, .form .grid3 { grid-template-columns: 1fr; }
}

/* tax/cost summary */
.summary-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap:12px; margin-top: 14px; }
.summary-grid .box {
  background:#fff; border-radius:10px; padding:14px; box-shadow:0 1px 3px rgba(0,0,0,.05);
  border-left: 4px solid #0f766e;
}
.summary-grid .box .lab { font-size:12px; color:#6b7280; }
.summary-grid .box .val { font-size:18px; font-weight:700; color:#064e3b; margin-top:4px; }

/* legend strip */
.legend-strip { display:flex; gap: 10px; flex-wrap: wrap; align-items:center; }
.legend-strip .it { display:flex; gap:6px; align-items:center; font-size:11px; color:#374151; }
.legend-strip .sw { width:14px; height:14px; border-radius:3px; }
.legend-strip .sw.done    { background:#dcfce7; border:1px solid #86efac; }
.legend-strip .sw.pending { background:#fef3c7; border:1px solid #fde68a; }
.legend-strip .sw.issue   { background:#fee2e2; border:1px solid #fca5a5; }
.legend-strip .sw.na      { background:#f3f4f6; border:1px solid #d1d5db; }
.legend-strip .sw.today   { background:#fff; border:2px solid #0f766e; }
