/* ==========================================================================
   NitiCraft — main stylesheet (mobile-first, no framework)
   Font: Bai Jamjuree (self-hosted, OFL) · Palette: cream & brown
   Variable names kept from the original navy/green theme; values remapped.
   ========================================================================== */

/* --- Bai Jamjuree (self-hosted) ------------------------------------------ */
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:400; font-display:swap; src:url("../fonts/baijamjuree-400-latin.woff2") format("woff2"); unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:400; font-display:swap; src:url("../fonts/baijamjuree-400-latin-ext.woff2") format("woff2"); unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:400; font-display:swap; src:url("../fonts/baijamjuree-400-thai.woff2") format("woff2"); unicode-range:U+02D7,U+0303,U+0331,U+0E01-0E5B,U+200C-200D,U+25CC; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:500; font-display:swap; src:url("../fonts/baijamjuree-500-latin.woff2") format("woff2"); unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:500; font-display:swap; src:url("../fonts/baijamjuree-500-latin-ext.woff2") format("woff2"); unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:500; font-display:swap; src:url("../fonts/baijamjuree-500-thai.woff2") format("woff2"); unicode-range:U+02D7,U+0303,U+0331,U+0E01-0E5B,U+200C-200D,U+25CC; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:600; font-display:swap; src:url("../fonts/baijamjuree-600-latin.woff2") format("woff2"); unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:600; font-display:swap; src:url("../fonts/baijamjuree-600-latin-ext.woff2") format("woff2"); unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:600; font-display:swap; src:url("../fonts/baijamjuree-600-thai.woff2") format("woff2"); unicode-range:U+02D7,U+0303,U+0331,U+0E01-0E5B,U+200C-200D,U+25CC; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:700; font-display:swap; src:url("../fonts/baijamjuree-700-latin.woff2") format("woff2"); unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:700; font-display:swap; src:url("../fonts/baijamjuree-700-latin-ext.woff2") format("woff2"); unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face { font-family:"Bai Jamjuree"; font-style:normal; font-weight:700; font-display:swap; src:url("../fonts/baijamjuree-700-thai.woff2") format("woff2"); unicode-range:U+02D7,U+0303,U+0331,U+0E01-0E5B,U+200C-200D,U+25CC; }

:root {
  /* dark neutrals (sidebar, headings) — now warm coffee brown */
  --navy: #43342a;
  --navy-700: #5a4536;
  --navy-050: #f1e7d6;
  /* primary accent — warm caramel brown */
  --green: #a06a43;
  --green-600: #895a37;
  --green-050: #f0e4d5;
  --ink: #3b2f26;
  --muted: #8c7b69;
  --line: #e7dcc7;
  --bg: #f7f1e4;
  --card: #fffdf7;
  --danger: #b23a2e;
  --danger-bg: #f7e5df;
  --warn: #8a5a12;
  --warn-bg: #f6ecd6;
  --ok: #5f7a44;
  --ok-bg: #ebefdb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(67, 52, 42, .10), 0 8px 26px rgba(67, 52, 42, .08);
  --maxw: 1180px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: "Bai Jamjuree", "Segoe UI", Tahoma, "Sarabun", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--green-600); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; color: var(--navy); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

img { max-width: 100%; height: auto; }

/* --- Layout -------------------------------------------------------------- */
.app { display: flex; min-height: 100vh; flex-direction: column; }
.app__body { display: flex; flex: 1; }
.content { flex: 1; padding: 1rem; max-width: 100%; overflow-x: hidden; }
.container { max-width: var(--maxw); margin: 0 auto; }

@media (min-width: 768px) {
  .content { padding: 1.75rem 2rem; }
}

/* --- Topbar ------------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: .75rem;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: .6rem 1rem; position: sticky; top: 0; z-index: 30;
}
.topbar__logo { display: flex; align-items: center; gap: .5rem; }
.topbar__logo img { height: 30px; width: auto; }
.topbar__spacer { flex: 1; }
.topbar__user { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--muted); }

.iconbtn {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 1.1rem;
}
.menu-toggle { display: inline-flex; }
@media (min-width: 992px) { .menu-toggle { display: none; } }

.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: .72rem; line-height: 18px; text-align: center;
}

/* --- Sidebar ---------------------------------------------------------- */
.sidebar {
  background: var(--navy); color: #e6dccb; width: 240px; flex-shrink: 0;
  padding: 1rem .6rem; position: fixed; inset: 0 auto 0 0; z-index: 40;
  transform: translateX(-100%); transition: transform .2s ease; overflow-y: auto;
}
.sidebar.is-open { transform: translateX(0); }
.sidebar a {
  display: flex; align-items: center; gap: .6rem; color: #e6dccb; text-decoration: none;
  padding: .6rem .7rem; border-radius: 8px; font-size: .94rem;
}
.sidebar a:hover { background: var(--navy-700); color: #fff; }
.sidebar a.is-active { background: var(--green); color: #fff; }
.sidebar__group { margin: .3rem 0 .8rem; }
.sidebar__label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: #b9a892; padding: .4rem .7rem; }
.sidebar__backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
.sidebar__backdrop.is-open { display: block; }

@media (min-width: 992px) {
  .sidebar { position: sticky; height: 100vh; top: 0; transform: none; }
  .sidebar__backdrop { display: none !important; }
}

/* --- Cards / grid --------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1.1rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid--stats { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .grid--stats { grid-template-columns: repeat(4, 1fr); } }

.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 1rem; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: .8rem;
}
.stat > div { min-width: 0; }
.stat__icon {
  width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 1.25rem; line-height: 1;
  background: var(--green-050); color: var(--green-600);
}
.stat__num { font-size: 1.5rem; font-weight: 700; color: var(--navy); line-height: 1.2; word-break: break-word; }
.stat__label { color: var(--muted); font-size: .86rem; }
.stat--a .stat__icon { background: #efe4d4; color: #7a5636; }
.stat--b .stat__icon { background: #e7ddef; color: #6a4b86; }
.stat--c .stat__icon { background: #e6efd9; color: #5f7a44; }
.stat--d .stat__icon { background: #f6e2d3; color: #b06a3c; }

/* --- Dashboard ------------------------------------------------------ */
.dash-hero {
  background: linear-gradient(120deg, var(--navy), #5a4230);
  color: #f4e9da; border-radius: 16px; padding: 1.3rem 1.5rem; margin-bottom: 1.1rem;
}
.dash-hero h1 { color: #fff; margin: 0 0 .15rem; font-size: 1.5rem; }
.dash-hero .muted { color: #d9c9b3; }

.dash-cols { display: grid; grid-template-columns: 1fr; gap: 1.1rem; }
@media (min-width: 1000px) { .dash-cols { grid-template-columns: minmax(0,1.9fr) minmax(0,1fr); } }
.dash-main, .dash-side { min-width: 0; }

.chart { display: flex; align-items: flex-end; gap: .45rem; height: 170px; margin-top: .8rem; }
.chart__bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: .3rem; height: 100%; }
.chart__fill {
  width: 100%; max-width: 36px; min-height: 4px; border-radius: 7px 7px 0 0;
  background: linear-gradient(180deg, var(--green), var(--green-600));
}
.chart__val { font-size: .78rem; font-weight: 700; color: var(--navy); }
.chart__lbl { font-size: .72rem; color: var(--muted); }

.feed-item { padding: .55rem 0; border-bottom: 1px solid var(--line); }
.feed-item:last-child { border-bottom: 0; padding-bottom: 0; }

/* --- Buttons ------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid transparent; border-radius: 8px; padding: .55rem 1rem;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2;
  background: var(--navy); color: #fff;
}
.btn:hover { background: var(--navy-700); }
.btn--green { background: var(--green); }
.btn--green:hover { background: var(--green-600); }
.btn--ghost { background: transparent; color: var(--navy); border-color: var(--line); }
.btn--ghost:hover { background: var(--navy-050); }
.btn--danger { background: var(--danger); }
.btn--sm { padding: .35rem .65rem; font-size: .85rem; }
.btn--block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* --- Forms ------------------------------------------------------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .92rem; }
.field .hint { color: var(--muted); font-size: .82rem; margin-top: .25rem; }
.input, select, textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink);
}
.input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy-050); border-color: var(--navy-700); }
.field--error .input, .field--error select { border-color: var(--danger); }
.field__err { color: var(--danger); font-size: .82rem; margin-top: .25rem; }
.form-row { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-row--2 { grid-template-columns: 1fr 1fr; } }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }

/* --- Alerts / flash ------------------------------------------- */
.alert { border-radius: 8px; padding: .7rem .9rem; margin-bottom: 1rem; font-size: .92rem; border: 1px solid transparent; }
.alert--error { background: var(--danger-bg); color: var(--danger); border-color: #eccbc9; }
.alert--success { background: var(--ok-bg); color: var(--ok); border-color: #c7e3d5; }
.alert--warn { background: var(--warn-bg); color: var(--warn); border-color: #ecd9b3; }
.alert--info { background: var(--navy-050); color: var(--navy-700); border-color: #e6dccb; }

/* --- Tables --------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table.data { width: 100%; border-collapse: collapse; min-width: 560px; }
table.data th, table.data td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); font-size: .92rem; }
table.data th { background: var(--navy-050); color: var(--navy); font-weight: 700; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }

.pill { display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pill--pending { background: var(--warn-bg); color: var(--warn); }
.pill--received { background: var(--navy-050); color: var(--navy-700); }
.pill--claimed { background: var(--ok-bg); color: var(--ok); }
.pill--off { background: #eee; color: #666; }

/* --- Auth / install centered card --------------------------- */
.centerpage { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem; }
.authcard { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 420px; padding: 1.6rem; }
.authcard--wide { max-width: 640px; }
.authcard__logo { text-align: center; margin-bottom: 1.1rem; }
.authcard__logo img { height: 54px; width: auto; }

/* --- Wizard steps ------------------------------------------ */
.steps { display: flex; gap: .4rem; margin-bottom: 1.3rem; flex-wrap: wrap; }
.steps li { list-style: none; flex: 1; min-width: 120px; font-size: .82rem; color: var(--muted); border-top: 3px solid var(--line); padding-top: .4rem; }
.steps li.is-active { color: var(--navy); border-top-color: var(--navy); font-weight: 700; }
.steps li.is-done { color: var(--green); border-top-color: var(--green); }
.checklist { list-style: none; padding: 0; margin: 0 0 1rem; }
.checklist li { display: flex; align-items: baseline; gap: .5rem; padding: .4rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.checklist li:last-child { border-bottom: 0; }
.checklist .ok { color: var(--ok); font-weight: 700; }
.checklist .bad { color: var(--danger); font-weight: 700; }
.checklist .warn { color: var(--warn); font-weight: 700; }

/* --- Courier radio grid ---------------------------------- */
.courier-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .5rem; }
.courier-opt { position: relative; cursor: pointer; }
.courier-opt input { position: absolute; opacity: 0; }
.courier-opt__body {
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .4rem; text-align: center;
  height: 100%; background: var(--card); transition: border-color .15s, background .15s;
}
.courier-opt__body img { height: 28px; width: auto; object-fit: contain; }
.courier-opt__mark { font-size: 1.4rem; line-height: 1; }
.courier-opt__name { font-size: .8rem; color: var(--muted); }
.courier-opt input:checked + .courier-opt__body { border-color: var(--green); background: var(--green-050); }
.courier-opt input:checked + .courier-opt__body .courier-opt__name { color: var(--green-600); font-weight: 600; }
.courier-opt input:focus-visible + .courier-opt__body { outline: 2px solid var(--navy-050); }

/* --- Camera scanner modal -------------------------------- */
.scanner-modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.scanner-modal[hidden] { display: none; }
.scanner-modal__box { background: var(--card); border-radius: 12px; padding: 1rem; width: 100%; max-width: 380px; }
.scanner-modal__box video { width: 100%; border-radius: 8px; background: #000; aspect-ratio: 4/3; object-fit: cover; }
.scanner-modal__hint { text-align: center; color: var(--muted); font-size: .9rem; margin: .6rem 0; }

/* --- Utilities -------------------------------------------- */
.muted { color: var(--muted); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; }
.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }
.inline-form { display: inline; }
.nowrap { white-space: nowrap; }
