/* ============ Design tokens ============ */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;

  --accent: #ea580c;
  --accent-light: #ffedd5;

  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --info: #0891b2;
  --info-light: #cffafe;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

  --sidebar-w: 250px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 4px 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0 0 8px 0; }
ul { margin: 0; padding: 0; }

/* ============ Layout ============ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: #0f172a;
  color: #cbd5e1;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 20;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 20px;
  color: #fff;
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar-brand .logo-badge {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
}
.sidebar-section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.09em;
  color: #566178; padding: 18px 20px 8px;
  font-weight: 700;
}
.sidebar-nav { flex: 1; padding: 4px 12px 20px; }
.sidebar-link {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 12px; margin: 1px 0;
  color: #97a3b8;
  font-size: 13.3px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { background: rgba(255,255,255,0.06); color: #f1f5f9; }
.sidebar-link.active {
  background: linear-gradient(135deg, var(--primary), #3b6fe0);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}
.sidebar-link .ic { width: 17px; height: 17px; flex-shrink: 0; display: flex; opacity: 0.85; }
.sidebar-link .ic svg { width: 100%; height: 100%; }
.sidebar-link.active .ic { opacity: 1; }
.sidebar-foot {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.07);
  font-size: 11.5px;
  color: #566178;
}

.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02), 0 2px 8px rgba(15, 23, 42, 0.03);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px;
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 17.5px; font-weight: 700; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-user {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
}
.topbar-user .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-light), #eef2ff);
  color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.15);
}
.role-tag {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 100px;
  background: var(--primary-light); color: var(--primary-dark); font-weight: 700;
}

[x-cloak] { display: none !important; }
.user-menu { position: relative; }
.user-menu-trigger {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 1px solid transparent; cursor: pointer; padding: 6px 10px 6px 6px; border-radius: 100px;
  font-family: inherit; text-align: left;
  transition: background 0.15s, border-color 0.15s;
}
.user-menu-trigger:hover, .user-menu-trigger.is-open { background: var(--surface-alt); border-color: var(--border); }
.user-menu-chevron { width: 14px; height: 14px; color: var(--text-faint); transition: transform 0.2s ease; flex-shrink: 0; }
.user-menu-chevron.is-rotated { transform: rotate(180deg); color: var(--text-muted); }
.user-menu-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); min-width: 210px; z-index: 30;
  padding: 6px;
  animation: menu-pop 0.12s ease-out;
}
@keyframes menu-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.user-menu-item {
  display: block; padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text); font-weight: 500;
}
.user-menu-item:hover { background: var(--surface-alt); }
.user-menu-item-danger { color: var(--danger); }
.user-menu-divider { height: 1px; background: var(--border); margin: 6px 4px; }

.content { padding: 24px; flex: 1; }
.content-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.content-header .subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ============ Flash messages ============ */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.flash {
  padding: 11px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; display: flex; align-items: center; gap: 8px;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-light); color: #14532d; border-color: #bbf7d0; }
.flash-error { background: var(--danger-light); color: #7f1d1d; border-color: #fecaca; }
.flash-info { background: var(--info-light); color: #164e63; border-color: #a5f3fc; }

/* ============ Cards / KPI ============ */
.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 700px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, transform 0.2s;
}
.card-pad { padding: 20px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 14.5px; }
.card-body { padding: 20px; }

.kpi-card { padding: 20px 20px; position: relative; overflow: hidden; }
.kpi-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.kpi-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.kpi-value { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-icon {
  position: absolute; top: 16px; right: 16px;
  width: 38px; height: 38px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 700;
}
.kpi-foot { font-size: 12px; color: var(--text-faint); margin-top: 6px; }
.tone-blue .kpi-icon { background: var(--primary-light); color: var(--primary-dark); }
.tone-orange .kpi-icon { background: var(--accent-light); color: var(--accent); }
.tone-green .kpi-icon { background: var(--success-light); color: var(--success); }
.tone-red .kpi-icon { background: var(--danger-light); color: var(--danger); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s, border-color 0.12s;
}
.btn:hover { border-color: var(--text-faint); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); border-color: var(--primary-dark); color: #fff; box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25); }
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-dark), var(--primary-dark)); border-color: var(--primary-dark); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 7px 9px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ============ Forms ============ */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 700px) { .form-grid, .form-grid-3 { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field .hint { font-size: 11.5px; color: var(--text-faint); }
input, select, textarea {
  font-family: inherit; font-size: 13.5px; line-height: 1.4;
  padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  outline: none; width: 100%; box-sizing: border-box;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
textarea { resize: vertical; min-height: 70px; }
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 8 10 12 14 8'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px 14px;
}
select:disabled { cursor: not-allowed; opacity: 0.6; }
select::-ms-expand { display: none; }

.password-field { position: relative; }
.password-field input { padding-right: 42px; }
.password-toggle {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; padding: 0;
  color: var(--text-faint); border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.password-toggle:hover { color: var(--text-muted); background: var(--surface-alt); }
.password-toggle svg { width: 18px; height: 18px; }
.password-toggle .icon-eye-off { display: none; }
.password-toggle.is-visible .icon-eye { display: none; }
.password-toggle.is-visible .icon-eye-off { display: block; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
fieldset { border: none; padding: 0; margin: 0 0 20px 0; }
legend { font-size: 13px; font-weight: 700; margin-bottom: 10px; color: var(--text); }

/* ============ Table ============ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: 700;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  white-space: nowrap;
}
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.mono { font-family: "SF Mono", ui-monospace, Menlo, monospace; }
.empty-row td { text-align: center; padding: 36px 16px; color: var(--text-faint); }
tfoot td { padding: 12px 16px; font-weight: 700; border-top: 2px solid var(--border); }

.line-item-table input, .line-item-table select { padding: 7px 10px; font-size: 13px; }
.line-item-table select { padding-right: 32px; background-position: right 10px center; background-size: 12px 12px; }
.line-item-table td { padding: 6px 8px; }

/* ============ Badges ============ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 100px;
  font-size: 11.5px; font-weight: 700;
}
.badge-green { background: var(--success-light); color: #166534; }
.badge-amber { background: var(--warning-light); color: #92400e; }
.badge-red { background: var(--danger-light); color: #991b1b; }
.badge-gray { background: #f1f5f9; color: var(--text-muted); }
.badge-blue { background: var(--primary-light); color: var(--primary-dark); }

/* ============ Misc ============ */
.divider { height: 1px; background: var(--border); margin: 18px 0; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 10px; }
.pill-tabs { display: flex; gap: 6px; background: var(--surface-alt); padding: 4px; border-radius: 100px; width: fit-content; }
.pill-tab { padding: 6px 14px; border-radius: 100px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.pill-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.stat-strip { display: flex; gap: 24px; flex-wrap: wrap; }
.stat-strip .stat { min-width: 140px; }
.stat .label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.stat .value { font-size: 19px; font-weight: 700; }
.low-stock-row { background: var(--danger-light) !important; }
.link-action { color: var(--primary); font-weight: 600; }
.link-action:hover { text-decoration: underline; }
.actions-cell { display: flex; gap: 6px; align-items: center; }
.actions-cell form { display: inline-flex; }
.btn-icon-danger { color: var(--text-faint); }
.btn-icon-danger:hover { background: var(--danger-light); border-color: var(--danger); color: var(--danger); }
.btn-icon-danger svg { width: 15px; height: 15px; display: block; }
.page-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search-input { max-width: 260px; }
.helper-note {
  background: var(--info-light); color: #164e63; border: 1px solid #a5f3fc;
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 12.5px; margin-bottom: 16px;
}

/* ============ Login page ============ */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, rgba(37, 99, 235, 0.35), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(234, 88, 12, 0.25), transparent 45%),
    linear-gradient(135deg, #0b1220, #14243f 55%, #0f2557);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 40px 34px;
  animation: login-in 0.35s ease-out;
}
@keyframes login-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-logo {
  width: 54px; height: 54px; border-radius: 15px; margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center; font-size: 24px; color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.4);
}
.login-card h1 { text-align: center; font-size: 20px; letter-spacing: -0.01em; }
.login-card .subtitle { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 26px; }
.login-demo-hint {
  margin-top: 18px; font-size: 12px; color: var(--text-muted);
  background: var(--surface-alt); border-radius: var(--radius-sm); padding: 10px 14px; line-height: 1.6;
}

/* ============ Print (invoice) ============ */
@media print {
  .no-print { display: none !important; }
  .main-area { margin-left: 0; }
  body { background: #fff; }
}
.print-invoice { max-width: 720px; margin: 0 auto; }
.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
