:root {
  --bg: #ece7e0;
  --bg-2: #f4f0ea;
  --panel: #ffffff;
  --panel-2: #f0ebe3;
  --line: #ddd5ca;
  --ink: #2a2520;
  --ink-dim: #6f655a;
  --ink-faint: #a1968a;
  --accent: #bf7d2c;
  --accent-2: #c2643a;
  --green: #4f8f3e;
  --red: #c0432e;
  --blue: #3f7d99;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(70,58,44,.12);
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --serif: "Fraunces", Georgia, "Songti SC", serif;
  --sans: "Hanken Grotesk", -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  background-image: radial-gradient(circle at 12% -10%, rgba(191,125,44,.06), transparent 45%),
                    radial-gradient(circle at 95% 0%, rgba(194,100,58,.05), transparent 40%);
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit; font-size: 14px;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--ink); border-radius: 9px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--ink-dim); margin: 0 0 5px; letter-spacing: .02em; }
.field { margin-bottom: 13px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

.btn {
  background: var(--accent); color: #211a10; border: none;
  padding: 10px 18px; border-radius: 9px; font-weight: 700; font-size: 14px;
  transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink-dim); border: 1px solid var(--line); }
.btn.ghost:hover { color: var(--ink); border-color: var(--ink-faint); }
.btn.danger { background: transparent; color: var(--red); border: 1px solid rgba(212,105,79,.4); }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 38px 34px; box-shadow: var(--shadow);
}
.brand { font-family: var(--serif); font-weight: 600; }
.login-card .brand { font-size: 30px; line-height: 1.1; margin-bottom: 4px; }
.login-card .brand em { color: var(--accent); font-style: italic; }
.login-sub { color: var(--ink-faint); font-size: 13px; margin-bottom: 26px; font-family: var(--mono); }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-2); border-right: 1px solid var(--line);
  padding: 22px 16px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { font-size: 21px; padding: 4px 10px 18px; }
.sidebar .brand em { color: var(--accent); font-style: italic; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  border-radius: 9px; color: var(--ink-dim); font-size: 14px; font-weight: 500;
  border: none; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--panel); color: var(--ink); }
.nav-item.active { background: var(--panel-2); color: var(--accent); }
.nav-item .ic { width: 18px; text-align: center; opacity: .9; }
.nav-badge { margin-left: auto; background: var(--accent-2); color: #1a120b;
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 20px; }
.nav-sep { height: 1px; background: var(--line); margin: 12px 6px; }
.nav-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); }
.nav-foot .uname { font-weight: 600; font-size: 14px; }
.nav-foot .urole { font-size: 12px; color: var(--ink-faint); font-family: var(--mono); }

.main { padding: 30px 38px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 24px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-family: var(--serif); font-weight: 600; font-size: 30px; letter-spacing: -.01em; }
.page-head p { color: var(--ink-faint); font-size: 13.5px; margin-top: 3px; }

/* ---------- Cards & grids ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1024px){ .grid.cols-4{grid-template-columns:repeat(2,1fr)} .grid.cols-3{grid-template-columns:repeat(2,1fr)} }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.stat .num { font-family: var(--serif); font-size: 38px; font-weight: 600; line-height: 1; }
.stat .lbl { color: var(--ink-faint); font-size: 12.5px; margin-top: 8px; letter-spacing: .03em; }
.stat.accent .num { color: var(--accent); }

.list-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--panel);
  margin-bottom: 10px;
}
.list-item:hover { border-color: var(--ink-faint); }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 600; font-size: 15px; }
.li-sub { color: var(--ink-faint); font-size: 12.5px; margin-top: 2px; }
.li-actions { display: flex; gap: 7px; flex-shrink: 0; align-items: center; }

.tag {
  display: inline-block; font-size: 11px; font-family: var(--mono);
  padding: 2px 9px; border-radius: 20px; border: 1px solid var(--line);
  color: var(--ink-dim); background: var(--bg-2); white-space: nowrap;
}
.tag.open { color: var(--green); border-color: rgba(127,174,110,.4); }
.tag.assigned { color: var(--blue); border-color: rgba(111,155,181,.4); }
.tag.in_progress { color: var(--accent); border-color: rgba(224,164,88,.4); }
.tag.review { color: var(--accent-2); border-color: rgba(212,121,79,.4); }
.tag.done { color: var(--ink-faint); }
.tag.income { color: var(--green); border-color: rgba(127,174,110,.4); }
.tag.expense { color: var(--red); border-color: rgba(212,105,79,.4); }
.tag.dot::before { content: '●'; margin-right: 5px; }

.muted { color: var(--ink-faint); }
.empty { text-align: center; color: var(--ink-faint); padding: 50px 20px; font-family: var(--mono); font-size: 13px; }
.section-title { font-family: var(--serif); font-size: 19px; font-weight: 600; margin: 6px 0 14px; }

table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: 11.5px; color: var(--ink-faint); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--line); letter-spacing: .04em; text-transform: uppercase; }
table.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--bg-2); font-size: 14px; }
table.tbl tr:hover td { background: var(--bg-2); }
.amt-income { color: var(--green); font-weight: 600; font-family: var(--mono); }
.amt-expense { color: var(--red); font-weight: 600; font-family: var(--mono); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(50,42,34,.45); display: grid; place-items: center;
  z-index: 50; padding: 20px; backdrop-filter: blur(3px); }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-head { padding: 20px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-family: var(--serif); font-size: 21px; font-weight: 600; }
.modal-body { padding: 18px 22px 22px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }
.x { background: none; border: none; color: var(--ink-faint); font-size: 22px; line-height: 1; }

.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  padding: 12px 22px; border-radius: 10px; box-shadow: var(--shadow); z-index: 99;
  font-size: 14px; animation: pop .2s; }
.toast.err { border-color: rgba(212,105,79,.5); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-h { font-size: 11px; color: var(--ink-faint); text-align: center; padding: 4px; font-family: var(--mono); }
.cal-cell { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  min-height: 92px; padding: 6px; font-size: 12px; }
.cal-cell.other { opacity: .35; }
.cal-cell.today { border-color: var(--accent); }
.cal-date { color: var(--ink-faint); font-family: var(--mono); font-size: 11px; }
.cal-ev { background: var(--accent); color: #1a120b; border-radius: 5px; padding: 1px 5px;
  margin-top: 3px; font-size: 10.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }

.lock-screen { display: grid; place-items: center; padding: 60px 20px; }
.lock-card { max-width: 380px; width: 100%; text-align: center; }
.lock-icon { font-size: 42px; margin-bottom: 10px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.pill-tabs { display: inline-flex; gap: 4px; background: var(--bg-2); padding: 4px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 18px; }
.pill-tabs button { background: none; border: none; color: var(--ink-dim); padding: 7px 16px; border-radius: 7px; font-size: 13px; font-weight: 600; }
.pill-tabs button.active { background: var(--accent); color: #211a10; }
.err-text { color: var(--red); font-size: 13px; margin-top: 8px; }

/* ---------- table scroll wrapper (used on narrow screens) ---------- */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Mobile top bar + drawer (hidden on desktop) ---------- */
.mobile-topbar { display: none; }
.scrim { display: none; }
.hamburger {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  font-size: 20px; line-height: 1; padding: 6px 12px; border-radius: 9px;
}

/* ============================================================
   RESPONSIVE  —  phones & small tablets
   ============================================================ */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .shell { grid-template-columns: 1fr; }

  /* top bar with hamburger */
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 30;
    background: var(--bg-2); border-bottom: 1px solid var(--line);
    padding: 11px 14px;
  }
  .mobile-topbar .brand { font-family: var(--serif); font-weight: 600; font-size: 19px; }
  .mobile-topbar .brand em { color: var(--accent); font-style: italic; }

  /* sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 248px;
    height: 100vh; transform: translateX(-100%);
    transition: transform .25s ease; z-index: 50;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .sidebar .brand { display: none; }          /* shown in top bar instead */
  .nav-item { padding: 13px 12px; font-size: 15px; }  /* bigger tap targets */

  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(8,6,5,.6); z-index: 40; }

  /* content spacing */
  .main { padding: 18px 15px 48px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-head h1 { font-size: 25px; }
  .page-head > div:last-child { width: 100%; }   /* action buttons row full width */
  .page-head .btn { width: 100%; }

  /* grids collapse */
  .grid.cols-2 { grid-template-columns: 1fr; }
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .stat .num { font-size: 28px; }

  /* form rows stack */
  .row { flex-direction: column; gap: 0; }

  /* list rows wrap so tags/buttons don't overflow */
  .list-item { flex-wrap: wrap; }
  .li-actions { width: 100%; justify-content: flex-end; margin-top: 8px; }

  /* tables: let cards scroll horizontally */
  .card { overflow-x: auto; }
  table.tbl { min-width: 460px; }

  /* calendar: keep 7 columns but allow horizontal scroll */
  .cal { min-width: 560px; }
  .cal-cell { min-height: 70px; }

  /* modals fill the screen width with safe margins */
  .modal { max-width: 100%; margin: 0 8px; }
  .pill-tabs { width: 100%; display: flex; }
  .pill-tabs button { flex: 1; }
}

/* tablet: 2-up stats but roomier */
@media (min-width: 761px) and (max-width: 1024px) {
  .main { padding: 26px 24px 56px; }
}

/* ---------- Logo & brand ---------- */
.login-logo { display: block; width: 170px; max-width: 70%; height: auto; margin: 0 auto 6px; }
.side-brand { padding: 4px 8px 16px; }
.side-brand img { width: 130px; height: auto; display: block; }
.topbar-logo { height: 30px; width: auto; }
.login-alt { text-align: center; margin-top: 16px; font-size: 13px; color: var(--ink-faint); }
.login-copyright, .login-alt + .login-copyright { text-align: center; margin-top: 14px; font-size: 11px; color: var(--ink-faint); font-family: var(--mono); letter-spacing: .03em; }

/* ---------- App footer ---------- */
.app-footer {
  margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line);
  text-align: center; font-size: 11.5px; color: var(--ink-faint);
  font-family: var(--mono); letter-spacing: .03em;
}

/* ---------- multi-select checkboxes ---------- */
.chk { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink); cursor: pointer; }
.chk input { width: auto; }
.chk-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 14px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 12px; }
@media (max-width: 760px) { .chk-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------- crew (member + duty) editor ---------- */
.crew-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.crew-row .crew-user { flex: 1.1; }
.crew-row .crew-duty { flex: 1.4; }
.crew-del { background: var(--bg-2); border: 1px solid var(--line); color: var(--red);
  border-radius: 8px; width: 34px; height: 38px; flex-shrink: 0; font-size: 16px; line-height: 1; }

/* ---------- registration card ---------- */
.login-card-wide { max-width: 460px; }
.reg-title { font-family: var(--serif); font-size: 21px; font-weight: 600; text-align: center; margin-bottom: 18px; }

/* ---------- agreement reading box + signature pad ---------- */
.agreement-box {
  max-height: 240px; overflow-y: auto; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 9px; padding: 14px 16px;
  font-size: 12.5px; line-height: 1.6; color: var(--ink-dim);
}
.agreement-box h3 { font-size: 14px; color: var(--ink); margin: 12px 0 4px; }
.agreement-box p { margin-bottom: 7px; }
.sig-wrap { background: #fff; border: 1px dashed var(--line); border-radius: 9px; }
.sig-pad { width: 100%; height: 180px; touch-action: none; display: block; cursor: crosshair; }
