/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #fff8ea;
  --surface: #ffffff;
  --surface2: #fff0d1;
  --border: #ead9b8;
  --border2: #dcc39b;
  --brand-yellow: #f0d860;
  --brand-teal: #60c0c0;
  --brand-orange: #f07848;
  --brand-orange-deep: #d86018;
  --brand-blue: #4890a8;
  --brand-brown: #783000;
  --brand-amber: #f0a818;
  --accent: var(--brand-orange);
  --accent2: var(--brand-amber);
  --accent-dim: rgba(240,120,72,0.14);
  --green: #108903;
  --green-dim: rgba(16,137,3,0.12);
  --red: #c43d2b;
  --red-dim: rgba(196,61,43,0.1);
  --yellow: var(--brand-yellow);
  --text: #2f2118;
  --text2: #715d4c;
  --text3: #9b8069;
  --mono: 'Roboto Mono', monospace;
  --sans: 'Nunito Sans', sans-serif;
  --display: 'Poppins', sans-serif;
  --radius: 8px;
  --radius-lg: 14px;
  --shadow: 0 12px 32px rgba(120,48,0,0.12);
}
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Layout ── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: linear-gradient(180deg, rgba(240,216,96,.28), rgba(96,192,192,.12) 260px, rgba(255,255,255,.95)), var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 0 0 16px;
  overflow-y: auto;
}
.sidebar-toggle { display: none; }
.sidebar-nav { display: block; }
.logo {
  padding: 20px 18px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.logo-lockup { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 54px; height: 54px; object-fit: contain;
  background: #fff; border-radius: 14px; padding: 5px;
  border: 1px solid rgba(240,216,96,.35);
  box-shadow: 0 8px 22px rgba(120,48,0,.12);
}
.logo-mark {
  font-family: var(--display);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.5px;
  color: var(--text);
}
.logo-mark span { color: var(--accent); }
.logo-sub { font-size: 10px; color: var(--text3); letter-spacing: 2px; text-transform: uppercase; margin-top: 2px; font-family: var(--mono); }

.nav-section { padding: 0 12px; margin-top: 4px; }
.nav-label { font-size: 9px; letter-spacing: 2px; text-transform: uppercase; color: var(--text3); padding: 12px 8px 6px; font-family: var(--mono); }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius);
  color: var(--text2); font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all .15s; margin-bottom: 1px;
  position: relative;
}
.nav-item:hover { background: rgba(216,96,24,.14); color: var(--brand-brown); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(216,96,24,.20), rgba(96,192,192,.12));
  color: var(--brand-brown);
  font-weight: 800;
}
.nav-item.active::before { content:''; position:absolute; left:0; top:50%; transform:translateY(-50%); width:3px; height:20px; background: var(--brand-teal); border-radius: 0 3px 3px 0; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-badge { margin-left: auto; background: var(--red); color: #fff; font-size: 10px; font-family: var(--mono); padding: 1px 6px; border-radius: 20px; }

/* ── Main Content ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 56px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  background: linear-gradient(90deg, rgba(240,120,72,.10), rgba(96,192,192,.10), transparent 60%), var(--surface);
}
.page-title { font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: -0.3px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.period-tabs { display: flex; gap: 2px; background: #f3dfb8; padding: 3px; border-radius: var(--radius); border: 1px solid var(--border2); }
.period-tab { padding: 4px 12px; border-radius: 6px; font-size: 12px; color: var(--brand-brown); font-family: var(--mono); cursor: pointer; transition: all .15s; font-weight: 800; }
.period-tab.active { background: var(--brand-orange-deep); color: #fff; box-shadow: 0 2px 10px rgba(120,48,0,.16); }

.content { flex: 1; overflow-y: auto; padding: 24px 28px; }
.content::-webkit-scrollbar { width: 6px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Cards & Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  position: relative; overflow: hidden;
  box-shadow: 0 8px 22px rgba(120,48,0,.06);
}
.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
}
.stat-card.accent::before { background: linear-gradient(90deg, var(--brand-orange), var(--brand-yellow)); }
.stat-card.green::before { background: var(--green); }
.stat-card.red::before { background: var(--red); }
.stat-card.yellow::before { background: linear-gradient(90deg, var(--brand-yellow), var(--brand-teal)); }
.stat-label { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text3); font-family: var(--mono); margin-bottom: 10px; }
.stat-value { font-family: var(--mono); font-size: 26px; font-weight: 400; color: var(--text); line-height: 1; }
.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-sub { font-size: 11px; color: var(--text3); margin-top: 6px; font-family: var(--mono); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.customer-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(340px, .65fr); gap: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 22px rgba(120,48,0,.05);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-title { font-family: var(--display); font-weight: 700; font-size: 13px; letter-spacing: 0.2px; }
.card-body { padding: 4px 0; }
.card-body.padded { padding: 20px; }
.quote-result { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.quote-breakdown {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text2);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  padding: 14px;
}

/* ── Tables ── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 10px 16px;
  font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text3); font-family: var(--mono); font-weight: 400;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface2); }
.data-table tbody tr.is-selected { background: rgba(216,96,24,.12); }
.data-table .mono { font-family: var(--mono); }
.data-table .num { text-align: right; font-family: var(--mono); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; transition: all .15s;
  font-family: var(--sans); cursor: pointer;
}
.btn-primary { background: linear-gradient(135deg, var(--brand-orange), var(--brand-orange-deep)); color: #fff; box-shadow: 0 10px 22px rgba(216,96,24,.24); }
.btn-primary:hover { background: linear-gradient(135deg, var(--brand-amber), var(--brand-orange)); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border2); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--red-dim); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; width: 30px; height: 30px; justify-content: center; border-radius: 6px; }

/* ── Badges ── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-family: var(--mono);
}
.badge-lg { padding: 5px 10px; border-radius: 8px; font-size: 12px; font-weight: 800; text-transform: capitalize; }
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red   { background: var(--red-dim);   color: var(--red); }
.badge-yellow{ background: rgba(240,168,24,.18); color: #9a5700; }
.badge-gray  { background: var(--surface2);  color: var(--text3); }
.badge-accent{ background: var(--accent-dim); color: var(--accent); }
.badge-blue  { background: rgba(72,144,168,.14); color: var(--brand-blue); }
.badge-teal  { background: rgba(96,192,192,.18); color: #207878; }
.badge-brown { background: rgba(120,48,0,.12); color: var(--brand-brown); }
.btn-status-update {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 800;
  color: var(--brand-brown);
  background: #fff0d1;
  border: 1px solid var(--border2);
  box-shadow: 0 4px 12px rgba(120,48,0,.08);
}
.btn-status-update:hover { background: var(--brand-orange-deep); color: #fff; }

/* ── Modal ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  z-index: 100; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--radius-lg); width: 720px; max-width: 95vw;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slideUp .2s ease;
  display: flex; flex-direction: column;
}
.modal--wide { width: 1240px; max-width: 96vw; max-height: 94vh; }
.modal-body { flex: 1 1 auto; overflow-y: auto; }
.modal-header, .modal-footer { flex: 0 0 auto; }
@keyframes slideUp { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-title { font-family: var(--display); font-weight: 700; font-size: 16px; }
.modal-close { color: var(--text3); font-size: 20px; cursor: pointer; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Form Controls ── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.line-item-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) 88px minmax(110px, .8fr) 100px minmax(180px, 1fr) 110px 46px;
  gap: 12px; align-items: end;
  padding-bottom: 10px; margin-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}
.line-item-row:last-child { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.line-item-row input { min-width: 0; font-size: 15px; font-weight: 700; padding: 11px 12px; }
.line-item-row select { min-width: 0; font-size: 15px; font-weight: 700; padding: 11px 12px; width: 100%; }
.line-item-row label { white-space: nowrap; }
@media (max-width: 1100px) {
  .line-item-row { grid-template-columns: 1fr 1fr 1fr; }
  .line-item-row .form-group:last-child { grid-column: 1 / -1; text-align: right; }
}
@media (max-width: 600px) {
  .line-item-row { grid-template-columns: 1fr 1fr; }
}
label { display: block; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--text3); font-family: var(--mono); margin-bottom: 6px; }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; background: #fffdf8; border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 9px 12px; color: var(--text);
  transition: border-color .15s; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand-teal); box-shadow: 0 0 0 3px rgba(96,192,192,.18); }
select option { background: #fffdf8; color: var(--text); }
textarea { resize: vertical; min-height: 72px; }

/* ── Chart bars ── */
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 80px; padding: 0 4px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.bar-col { width: 100%; background: var(--accent-dim); border-radius: 4px 4px 0 0; transition: background .2s; position: relative; margin-top: auto; }
.bar-col:hover { background: var(--accent); }
.bar-label { font-size: 9px; color: var(--text3); font-family: var(--mono); }

/* ── Mini list ── */
.mini-list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
}
.mini-list-item:last-child { border-bottom: none; }
.mini-label { font-size: 13px; }
.mini-sub { font-size: 11px; color: var(--text3); font-family: var(--mono); margin-top: 1px; }
.mini-value { font-family: var(--mono); font-size: 13px; }

/* ── Low-stock indicator ── */
.stock-bar { height: 3px; background: var(--border2); border-radius: 2px; margin-top: 4px; }
.stock-fill { height: 100%; border-radius: 2px; background: var(--green); }
.stock-fill.low { background: var(--red); }
.stock-fill.warn { background: var(--yellow); }

/* ── Page sections ── */
.section { display: none; }
.section.active { display: block; }

/* ── Toolbar ── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 12px;
}
.data-table { min-width: 720px; }
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll .data-table { min-width: 900px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: #fffdf8; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 14px; flex: 1; max-width: 360px;
}
.search-box input { background: none; border: none; outline: none; color: var(--text); flex: 1; }

/* ── Empty state ── */
.empty { text-align: center; padding: 60px 20px; color: var(--text3); }
.empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.empty-text { font-size: 14px; }

/* ── Report ── */
.report-month-row { display: grid; grid-template-columns: 80px 1fr 1fr 1fr 1fr; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--border); gap: 12px; }
.report-month-row:last-child { border-bottom: none; }
.profit-bar { height: 6px; border-radius: 3px; }
.profit-positive { background: var(--green); }
.profit-negative { background: var(--red); }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #fff; border: 1px solid var(--border2);
  border-radius: var(--radius); padding: 12px 18px;
  font-size: 13px; box-shadow: var(--shadow);
  animation: slideUp .2s ease; display: flex; align-items: center; gap: 10px;
}
.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red); }

/* ── Branded Login ── */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; color: var(--text);
  background:
    radial-gradient(circle at 20% 10%, rgba(240,216,96,.40), transparent 25%),
    radial-gradient(circle at 82% 22%, rgba(96,192,192,.28), transparent 28%),
    linear-gradient(135deg, #fff8ea 0%, #fff2ce 58%, #ecfbfb 100%);
}
.login-card {
  width: 440px; max-width: 95vw;
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(240,216,96,.18);
  border-radius: 22px; padding: 24px;
  box-shadow: 0 18px 60px rgba(120,48,0,.18);
}
.login-brand { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.login-logo {
  width: 86px; height: 86px; object-fit: contain;
  background: #fff; border-radius: 22px; padding: 7px;
  border: 2px solid rgba(240,216,96,.45);
}
.login-title { font-family: var(--display); font-weight: 800; font-size: 24px; letter-spacing: -0.4px; }
.login-title span { color: var(--brand-orange-deep); }
.login-kicker { color: var(--brand-teal); font-family: var(--mono); font-size: 10px; letter-spacing: 2px; text-transform: uppercase; margin-top: 4px; }

/* Responsive */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }

  .app { flex-direction: column; height: auto; overflow: visible; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0;
    overflow: visible;
  }
  .logo {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 12px 12px;
  }
  .brand-logo { width: 42px; height: 42px; border-radius: 12px; }
  .logo-sub { display: none; }
  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #fff0d1;
    border: 1px solid var(--border2);
    font-weight: 800;
  }
  .sidebar[aria-expanded="false"] .sidebar-nav { display: none; }
  .sidebar[aria-expanded="true"] .sidebar-nav { display: block; }
  .sidebar-nav { padding-bottom: 10px; }
  .nav-section { padding: 0 10px; }
  .nav-item { padding: 12px 12px; font-size: 14px; }

  .topbar { flex-wrap: wrap; height: auto; padding: 12px 12px; gap: 10px; }
  .page-title { flex: 1 1 auto; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .period-tabs { flex: 1 1 auto; }
  .content { padding: 16px 12px; }

  .toolbar { flex-wrap: wrap; gap: 10px; }
  .search-box { max-width: 100%; flex: 1 1 100%; }
  .toolbar > div { flex: 1 1 auto; }
  .btn { padding: 10px 14px; }
}

/* Phone: full-screen modals + stacked form rows */
@media (max-width: 760px) {
  .modal-overlay { align-items: stretch; justify-content: stretch; padding: 0; }
  .modal, .modal--wide {
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    border-radius: 0; border: none;
  }
  .modal-header { padding: 14px 16px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
  .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; position: sticky; bottom: 0; background: var(--surface); z-index: 2; }
  .form-row { grid-template-columns: 1fr; }
  .modal-title { font-size: 15px; }
  .data-table th, .data-table td { padding: 8px 10px; }

  /* Phone: hybrid tables become stacked cards */
  .card .card-body { overflow: visible; }
  .table-scroll { overflow-x: visible; }
  .data-table { min-width: 0; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin: 10px 0;
    padding: 10px 12px;
    box-shadow: 0 6px 18px rgba(120,48,0,.06);
  }
  .data-table td {
    border-bottom: 1px dashed var(--border);
    padding: 8px 0;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
  }
  .data-table td:last-child { border-bottom: none; }
  .data-table td::before {
    content: attr(data-label);
    font-size: 10px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text3);
    font-family: var(--mono);
    flex: 0 0 auto;
    max-width: 45%;
  }
  .data-table td.num { text-align: right; }
  .data-table td > button { width: 100%; }
}

/* Samsung S25-class phones (~412–430 CSS px): tighten spacing and reduce cramping */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .topbar-actions { flex-wrap: wrap; gap: 8px; }
  #periodTabs { width: 100%; justify-content: space-between; }
  #addBtn { width: 100%; justify-content: center; }

  .card-header { padding: 14px 14px; }
  .card-body.padded { padding: 14px; }

  .data-table tr { padding: 10px 10px; }
  .data-table td { flex-direction: column; align-items: flex-start; }
  .data-table td::before { max-width: 100%; }
  .data-table td.num { align-self: stretch; text-align: left; }

  .btn { width: 100%; justify-content: center; }
  .btn.btn-icon { width: 40px; height: 40px; }
  /* Keep primary actions tappable, but don't let Update Status dominate */
  .btn-status-update { width: auto; justify-content: center; padding: 8px 10px; font-size: 12px; }

  .search-box { padding: 10px 12px; }
  .search-box input { font-size: 15px; }
}

