/* ============================================================
   Work Tracker — Design System  (Modern Clean)
   Shared tokens + components for index / dashboard / request
   ============================================================ */

/* ── Design tokens ─────────────────────────────────────────── */
:root {
  /* brand */
  --brand:        #2563eb;   /* blue-600  */
  --brand-dark:   #1d4ed8;
  --brand-soft:   #eff4ff;
  --navy:         #0f2747;   /* header / sidebar */
  --navy-2:       #16335c;

  /* surfaces */
  --bg:           #f1f5f9;   /* slate-100 */
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --border:       #e2e8f0;
  --border-strong:#cbd5e1;

  /* text */
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-faint:   #94a3b8;

  /* status */
  --green:        #16a34a;  --green-soft:  #dcfce7;  --green-ink:  #166534;
  --amber:        #f59e0b;  --amber-soft:  #fef3c7;  --amber-ink:  #92400e;
  --red:          #dc2626;  --red-soft:    #fee2e2;  --red-ink:    #991b1b;
  --blue-soft:    #dbeafe;  --blue-ink:    #1e40af;
  --violet-soft:  #ede9fe;  --violet-ink:  #5b21b6;
  --slate-soft:   #e2e8f0;  --slate-ink:   #475569;

  /* shape */
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* elevation */
  --sh-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.04);
  --sh:    0 4px 12px rgba(15,23,42,.06), 0 2px 4px rgba(15,23,42,.04);
  --sh-lg: 0 12px 40px rgba(15,23,42,.18);

  --ring: 0 0 0 3px rgba(37,99,235,.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Sarabun', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ── App header ────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  color: var(--text);
  display: flex; align-items: center; gap: .9rem;
  padding: 0 1.4rem; height: 60px;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--sh-sm);
}
.app-header .logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: var(--brand);
  display: grid; place-items: center;
  font-size: 1.1rem; font-weight: 800; letter-spacing: -.5px;
  box-shadow: 0 2px 8px rgba(37,99,235,.5);
}
/* brand logo (transparent) with a sweeping shine */
.brand-logo { position: relative; flex: none; display: inline-flex; align-items: center; }
.brand-logo img { display: block; height: 34px; width: auto; }
.brand-logo .shine {
  position: absolute; inset: 0; pointer-events: none;
  -webkit-mask: url(/logo.png) center / contain no-repeat;
          mask: url(/logo.png) center / contain no-repeat;
  background: linear-gradient(105deg, transparent 38%, rgba(255,255,255,.92) 50%, transparent 62%);
  background-repeat: no-repeat; background-size: 250% 100%; background-position: 200% 0;
  animation: logoShine 3.6s ease-in-out infinite;
}
.brand-logo.lg img { height: 46px; margin-bottom: .7rem; }
.brand-logo.lg .shine { bottom: .7rem; }
@keyframes logoShine { 0% { background-position: 200% 0; } 55%, 100% { background-position: -120% 0; } }

.app-header .title { display: flex; flex-direction: column; line-height: 1.15; }
.app-header .title b { font-size: 1.05rem; font-weight: 700; letter-spacing: .2px; }
.app-header .title small { font-size: .76rem; color: var(--text-muted); font-weight: 500; }
.app-header .spacer { margin-left: auto; }

/* header nav links */
.nav-link {
  color: var(--text-muted); text-decoration: none;
  font-size: .85rem; font-weight: 600;
  padding: .5rem .9rem; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; gap: .4rem;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand); color: #fff; }
.nav-link .dot {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill);
  background: var(--red); color: #fff; font-size: .7rem; font-weight: 800;
  display: inline-grid; place-items: center;
}

/* ── Layout ────────────────────────────────────────────────── */
.wrap { max-width: 1240px; margin: 0 auto; padding: 1.4rem 1.1rem 4rem; }
.grid { display: grid; gap: 1.1rem; }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: .3rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: .4rem; box-shadow: var(--sh-sm);
}
.tab {
  border: none; background: none; cursor: pointer; font-family: inherit;
  font-size: .9rem; font-weight: 600; color: var(--text-muted);
  padding: .6rem 1.1rem; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; gap: .45rem;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--brand); color: #fff; box-shadow: 0 1px 3px rgba(37,99,235,.4); }
.tab .dot {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill);
  background: var(--red); color: #fff; font-size: .7rem; font-weight: 800;
  display: inline-grid; place-items: center;
}

/* ── Card ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}
.card-head {
  display: flex; align-items: center; gap: .6rem;
  padding: 1rem 1.3rem; border-bottom: 1px solid var(--border);
}
.card-head h2 {
  font-size: .98rem; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: .55rem;
}
.card-head h2::before {
  content: ''; width: 4px; height: 17px; border-radius: 2px;
  background: var(--brand); display: inline-block;
}
.card-head .spacer { margin-left: auto; }
.card-body { padding: 1.2rem 1.3rem; }
.card-body.tight { padding: .5rem .6rem; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .85rem 1rem;
}
.col-full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: .32rem; }
.field > span {
  font-size: .8rem; font-weight: 600; color: var(--text-muted);
}
.field .req { color: var(--red); }

input, select, textarea {
  width: 100%;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: .55rem .75rem;
  font-size: .92rem; font-family: inherit; color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: var(--ring);
}
textarea { resize: vertical; min-height: 64px; line-height: 1.5; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center;
  padding-right: 2rem;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  border: 1.5px solid transparent; border-radius: var(--r-sm);
  padding: .55rem 1.15rem; font-size: .88rem; font-weight: 600;
  font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  transition: background .15s, box-shadow .15s, transform .08s, border-color .15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(37,99,235,.4); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(.95); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--brand); color: var(--brand); }
.btn-soft { background: var(--brand-soft); color: var(--brand-dark); }
.btn-soft:hover { background: #e0eaff; }
.btn-sm { padding: .34rem .7rem; font-size: .78rem; border-radius: 7px; }
.btn-danger-soft { background: var(--red-soft); color: var(--red-ink); }
.btn-danger-soft:hover { background: #fecaca; }
.btn-icon { padding: .4rem .5rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: .55rem; align-items: center; }

/* ── Toolbar / filter ──────────────────────────────────────── */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .65rem;
  padding: .85rem 1.3rem; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.toolbar .inline { display: inline-flex; align-items: center; gap: .4rem; font-size: .84rem; font-weight: 600; color: var(--text-muted); }
.toolbar input[type=date] { width: 155px; }

/* ── Table ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .855rem; }
thead th {
  position: sticky; top: 0;
  background: var(--surface-2); color: var(--text-muted);
  font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  text-align: left; white-space: nowrap;
  padding: .7rem .9rem; border-bottom: 1px solid var(--border);
}
tbody td { padding: .62rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--brand-soft); }
.ellip { max-width: 230px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty td { text-align: center; padding: 2.4rem; color: var(--text-faint); font-style: italic; }

/* row flash for newly arrived requests */
@keyframes flashRow { from { background: #fff7cc; } to { background: transparent; } }
tr.flash td { animation: flashRow 2.4s ease-out; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .6rem; border-radius: var(--r-pill);
  font-size: .73rem; font-weight: 700; white-space: nowrap; line-height: 1.4;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.plain::before { display: none; }
.b-green  { background: var(--green-soft);  color: var(--green-ink); }
.b-amber  { background: var(--amber-soft);  color: var(--amber-ink); }
.b-red    { background: var(--red-soft);    color: var(--red-ink); }
.b-blue   { background: var(--blue-soft);   color: var(--blue-ink); }
.b-violet { background: var(--violet-soft); color: var(--violet-ink); }
.b-slate  { background: var(--slate-soft);  color: var(--slate-ink); }

/* ── Stat cards ────────────────────────────────────────────── */
.stats {
  display: grid; gap: .85rem;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 1.05rem 1.2rem;
  box-shadow: var(--sh-sm); position: relative; overflow: hidden;
}
.stat::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--brand);
}
.stat.s-red::before    { background: var(--red); }
.stat.s-amber::before  { background: var(--amber); }
.stat.s-green::before  { background: var(--green); }
.stat .k { font-size: .78rem; color: var(--text-muted); font-weight: 600; }
.stat .v { font-size: 2rem; font-weight: 800; line-height: 1.1; margin-top: .15rem; }
.stat .sub { font-size: .74rem; color: var(--text-faint); margin-top: .15rem; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--navy); color: #fff;
  padding: .75rem 1.25rem; border-radius: var(--r-pill);
  font-size: .88rem; font-weight: 600; box-shadow: var(--sh-lg);
  opacity: 0; transition: opacity .25s, transform .25s; z-index: 300; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Modal ─────────────────────────────────────────────────── */
.overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(15,23,42,.5); backdrop-filter: blur(2px);
  align-items: center; justify-content: center; padding: 1rem;
}
.overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--r-lg);
  width: min(680px, 100%); max-height: 90vh; overflow-y: auto;
  box-shadow: var(--sh-lg);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 1rem; font-weight: 700; }
.modal-x { background: none; border: none; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--text-faint); }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 1.3rem; }

/* ── Helpers ───────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.hint { font-size: .8rem; color: var(--text-muted); line-height: 1.55; }
.mt { margin-top: .8rem; }
.hide { display: none !important; }
