:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #0f172a;
  --sub: #475569;
  --primary: #0f766e;
  --primary-600: #115e59;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --info: #2563eb;
  --badge-bg: #f1f5f9;
  --surface: #f8fafc;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
html, body { height: 100%; }
body { background: var(--surface); color: var(--text); line-height: 1.6; }

#app { display: flex; flex-direction: column; min-height: 100vh; }

.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar { background: radial-gradient(circle at top, #134e4a, var(--bg)); color: #f8fafc; display: flex; flex-direction: column; padding: 24px 20px; gap: 18px; }
.brand { display: flex; flex-direction: column; gap: 4px; }
.brand-title { font-weight: 700; font-size: 18px; letter-spacing: 0.02em; }
.brand-sub { font-size: 12px; opacity: 0.8; }
.nav { display: flex; flex-direction: column; gap: 8px; }
.nav-item { display: flex; align-items: center; gap: 10px; color: rgba(248, 250, 252, 0.85); text-decoration: none; padding: 10px 12px; border-radius: 10px; transition: background 120ms ease, color 120ms ease; font-size: 14px; }
.nav-item.active { background: rgba(255, 255, 255, 0.16); color: #fff; font-weight: 600; }
.nav-item:hover { background: rgba(255, 255, 255, 0.12); }
.nav-group { margin-top: 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.18em; opacity: 0.7; padding: 0 12px; }
.main { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 28px; background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.breadcrumb { font-size: 13px; color: var(--sub); }
.userbar { display: flex; align-items: center; gap: 12px; }
.userinfo { text-align: right; }
.userinfo .name { font-weight: 600; font-size: 14px; }
.userinfo .role { font-size: 12px; color: var(--sub); }
.content { padding: 24px 28px; display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 1px 1px rgba(15, 23, 42, 0.01), 0 8px 24px rgba(15, 23, 42, 0.03); }
.card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.card-body { padding: 18px 22px; display: flex; flex-direction: column; gap: 16px; }
.card-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
h1, h2, h3, h4 { font-weight: 700; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.subtitle { color: var(--sub); font-size: 13px; margin-top: 4px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 220px; flex: 1; }
.field label { font-size: 13px; font-weight: 600; }
.input, .select, .textarea { border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; font-size: 14px; background: #fff; color: var(--text); }
.textarea { min-height: 90px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid rgba(15, 118, 110, 0.25); border-color: rgba(15, 118, 110, 0.6); }
.btn { display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; border: 1px solid transparent; padding: 9px 16px; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer; background: var(--surface); color: var(--text); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.ghost { background: transparent; color: var(--sub); }
.btn.danger { background: rgba(220, 38, 38, 0.08); color: var(--danger); border-color: rgba(220, 38, 38, 0.25); }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 960px; font-size: 14px; }
thead th { text-align: left; font-weight: 600; background: var(--surface); color: var(--sub); padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:hover { background: rgba(248, 250, 252, 0.8); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--badge-bg); color: var(--sub); font-size: 12px; font-weight: 600; }
.badge.ok { background: rgba(22, 163, 74, 0.12); color: var(--ok); }
.badge.warn { background: rgba(217, 119, 6, 0.12); color: var(--warn); }
.badge.danger { background: rgba(220, 38, 38, 0.12); color: var(--danger); }
.badge.info { background: rgba(37, 99, 235, 0.12); color: var(--info); }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; box-shadow: 0 1px 1px rgba(15, 23, 42, 0.01); }
.kpi .label { color: var(--sub); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 800; }
.kpi .sub { color: var(--sub); font-size: 12px; }
.tabbar { display: flex; flex-wrap: wrap; gap: 8px; border-bottom: 1px solid var(--border); padding: 0 22px; }
.tab { background: transparent; border: none; padding: 10px 14px; font-size: 14px; color: var(--sub); font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--primary); border-color: var(--primary); }
.hidden { display: none !important; }
.flex { display: flex; gap: 10px; flex-wrap: wrap; }
.justify-end { justify-content: flex-end; }
.muted { color: var(--sub); }
.small { font-size: 12px; }
.full { width: 100%; }
.alert { border-radius: 10px; padding: 10px 14px; font-size: 13px; border: 1px solid var(--border); background: var(--surface); }
.alert.error { border-color: rgba(220, 38, 38, 0.4); background: rgba(220, 38, 38, 0.06); color: var(--danger); }
.alert.ok { border-color: rgba(22, 163, 74, 0.4); background: rgba(22, 163, 74, 0.06); color: var(--ok); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(circle at top, #134e4a, var(--bg)); }
.login-card { width: min(420px, 100%); background: #fff; border-radius: 16px; border: 1px solid var(--border); box-shadow: 0 40px 60px rgba(15, 23, 42, 0.18); overflow: hidden; }
.login-head { padding: 24px 26px 10px; }
.login-body { padding: 10px 26px 26px; display: flex; flex-direction: column; gap: 14px; }
/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: min(680px, 100%); box-shadow: 0 30px 60px rgba(15, 23, 42, 0.3); margin: auto; }
.modal.wide { width: min(960px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.icon-btn { background: transparent; border: none; font-size: 18px; cursor: pointer; color: var(--sub); line-height: 1; }

/* toast */
#toast-container { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--bg); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 10px 24px rgba(15,23,42,0.25); animation: toast-in 160ms ease; }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* small utilities */
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.chip { display:inline-flex; gap:6px; align-items:center; padding:4px 10px; border-radius:999px; background: var(--badge-bg); font-size:12px; }
.empty { padding: 22px; text-align: center; color: var(--sub); font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.line-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--surface); }
.line-item .line-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.serial-list { display: flex; flex-wrap: wrap; gap: 6px; }
.serial-chip { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; font-size: 12px; }
.scroll-y { max-height: 60vh; overflow-y: auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.toolbar .field { min-width: 160px; }

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; flex-direction: row; align-items: center; overflow-x: auto; padding: 14px 18px; gap: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .nav-group { display: none; }
  .content { padding: 18px; }
}
