:root {
  --bg: #f3f1ec;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #667085;
  --line: #e7e2d9;
  --sidebar: #14171c;
  --sidebar-muted: #a8b0bd;
  --accent: #c4511a;
  --accent-ink: #fff8f4;
  --good: #0f766e;
  --good-bg: #e7f6f3;
  --warn: #9a3412;
  --warn-bg: #fff1e8;
  --shadow: 0 1px 2px rgba(22, 24, 29, 0.04), 0 12px 32px rgba(22, 24, 29, 0.06);
  --radius: 16px;
  font-family: "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }

body { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: #fff;
  text-decoration: none;
  padding: 0 8px;
}

.mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--sidebar-muted); font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav a, .logout button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #d5d8e0;
  text-decoration: none;
  background: transparent;
  border: 0;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.nav a:hover, .logout button:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, 0.1); color: #fff; }

.nav svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }

.logout { margin-top: auto; }

.shell { padding: 28px 32px 48px; min-width: 0; }

.page-head { margin-bottom: 22px; }
.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}
h1 { margin: 0; font-size: 32px; letter-spacing: -0.04em; font-weight: 680; }
.lede { margin: 8px 0 0; color: var(--muted); max-width: 62ch; }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.stack { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.section-label {
  margin: 14px 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.span-2 { grid-column: span 2; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #3d4450; font-weight: 600; }

input, select, textarea {
  width: 100%;
  border: 1px solid #ddd6cc;
  background: #fcfbf9;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: #c4511a;
  box-shadow: 0 0 0 3px rgba(196, 81, 26, 0.15);
  background: #fff;
}

.actions { display: flex; gap: 10px; align-items: center; margin-top: 14px; }

button.text-btn {
  background: transparent;
  border: 0;
  color: var(--warn);
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
  padding: 8px 4px;
}

button.primary, a.primary {
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  text-decoration: none;
  cursor: pointer;
  font-weight: 650;
}

button.primary:hover, a.primary:hover { background: #2a2e37; }

a.ghost {
  color: var(--ink);
  text-decoration: none;
  font-weight: 650;
  padding: 10px 12px;
  border-radius: 10px;
}

a.ghost:hover { background: #efece6; }

.hint { margin: 12px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.notice, .warn {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 14px;
}

.notice { background: var(--good-bg); color: #115e59; }
.warn { background: var(--warn-bg); color: var(--warn); }

.table-card { padding: 0; overflow: auto; }
.table-card header, .panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 16px 18px 0;
}
.panel-head h2 { margin: 0; }
.panel-head span { color: var(--muted); font-size: 13px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  padding: 14px 12px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td {
  padding: 11px 12px;
  border-bottom: 1px solid #f0ece6;
  vertical-align: middle;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfaf8; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.customer { font-weight: 700; }
.empty { color: var(--muted); padding: 22px 18px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.stat strong { display: block; margin-top: 6px; font-size: 22px; letter-spacing: -0.04em; }

.chat { display: flex; flex-direction: column; gap: 12px; min-height: 180px; }
.bubble {
  max-width: 760px;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.45;
}
.bubble.user { background: var(--ink); color: #fff; margin-left: auto; }
.bubble.assistant { background: var(--surface); border: 1px solid var(--line); }
.ask { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.ask textarea { min-height: 56px; resize: vertical; }

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
}
.login-hero {
  background:
    radial-gradient(900px 500px at 10% 10%, rgba(196, 81, 26, 0.35), transparent 55%),
    var(--sidebar);
  color: #fff;
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.login-hero h1 { font-size: 56px; line-height: 0.95; max-width: 10ch; }
.login-hero p { color: #c9cdd6; max-width: 36ch; font-size: 18px; }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(400px, 100%); }
.login-card h2 { font-size: 28px; letter-spacing: -0.04em; margin: 0 0 8px; }

.mobile-bar, .tabbar { display: none; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: -4px 0 16px;
  }
  .mobile-bar .brand { color: var(--ink); }
  .mobile-bar .brand small { display: none; }
  .mobile-actions { display: flex; align-items: center; gap: 8px; }
  .mobile-bar a,
  .mobile-bar button {
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 14px;
    min-height: 40px;
    cursor: pointer;
    text-decoration: none;
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
  }
  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: #fff;
    border-top: 1px solid var(--line);
    padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-height: 52px;
    justify-content: center;
    text-decoration: none;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    border-radius: 12px;
  }
  .tabbar a.active { color: var(--accent); background: #fff4ee; }
  .tabbar svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
  .shell {
    padding: 16px 16px calc(92px + env(safe-area-inset-bottom));
  }
  .layout, .login-page, .ask { grid-template-columns: 1fr; }
  .card, .stat, .grid, .stack, .layout, label, .shell { min-width: 0; max-width: 100%; }
  .grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .shell > * + * { margin-top: 14px; }
  .page-head { margin-bottom: 0; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat strong { font-size: 20px; overflow-wrap: anywhere; }
  .login-hero { display: none; }
  .login-panel { padding: 24px 18px; align-items: start; }
  .login-card h2 { font-size: 32px; }
  h1 { font-size: 28px; }
  .lede { font-size: 15px; }
  input, select, textarea, button.primary, a.primary {
    font-size: 16px;
    min-height: 48px;
    max-width: 100%;
    min-width: 0;
  }
  input[type="date"], input[type="file"] { display: block; width: 100%; }
  textarea { min-height: 96px; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions .primary, .actions .ghost { text-align: center; }
  .ask { align-items: stretch; }
  .card { padding: 16px; border-radius: 14px; }
  .table-card { overflow: hidden; }
  table { min-width: 0; }
  table, thead, tbody, th, td, tr { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr {
    padding: 8px 14px 12px;
    border-bottom: 1px solid var(--line);
  }
  td {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    border: 0;
    padding: 5px 0;
    text-align: right;
  }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: left;
  }
  td.blank { display: none; }
  td.customer { font-size: 16px; }
  td.empty { display: block; text-align: left; }
  td.empty::before { content: none; }
  .num { text-align: right; }
}

.check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}
.check input { width: 18px; height: 18px; min-height: 18px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { min-width: 0; }
