:root {
  --bg: #0a0e17;
  --bg-elev: #111827;
  --bg-card: #151e30;
  --bg-input: #0d1320;
  --border: #243047;
  --border-strong: #334361;
  --text: #e6edf7;
  --text-muted: #8b9bb4;
  --accent: #f59e0b;
  --accent-strong: #ea580c;
  --accent-soft: rgba(245, 158, 11, 0.14);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.15);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, 0.15);
  --purple: #a855f7;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 12px; }
.mono { font-family: var(--mono); }
.text-right { text-align: right; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid transparent; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s ease; color: var(--text); background: var(--bg-card); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-strong)); color: #0a0e17; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: #1d293e; border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: #263550; }
.btn-danger { background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.3); }
.btn-success { background: rgba(16, 185, 129, 0.18); border-color: rgba(16, 185, 129, 0.5); color: #6ee7b7; }
.btn-success:hover:not(:disabled) { background: rgba(16, 185, 129, 0.3); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }

/* Inputs */
.input, input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"], input[type="date"], select, textarea {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; outline: none; width: 100%;
}
.input-sm { padding: 5px 8px; font-size: 12px; width: auto; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
textarea { resize: vertical; min-height: 76px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-muted); }
.field > span { font-weight: 600; color: #c9d6ea; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* Badges & Alerts */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--green-soft); color: #34d399; border: 1px solid rgba(16,185,129,0.3); }
.badge-red { background: var(--red-soft); color: #f87171; border: 1px solid rgba(239,68,68,0.35); }
.badge-amber { background: var(--accent-soft); color: #fbbf24; border: 1px solid rgba(245,158,11,0.35); }
.badge-blue { background: var(--blue-soft); color: #60a5fa; border: 1px solid rgba(59,130,246,0.35); }
.badge-gray { background: rgba(139,155,180,0.14); color: #9fb0c9; border: 1px solid rgba(139,155,180,0.25); }

.alert { padding: 10px 12px; border-radius: 8px; font-size: 12.5px; border: 1px solid; }
.alert-danger { background: var(--red-soft); border-color: rgba(239,68,68,0.45); color: #fecaca; }
.alert-warning { background: var(--accent-soft); border-color: rgba(245,158,11,0.45); color: #fde68a; }
.alert-info { background: var(--blue-soft); border-color: rgba(59,130,246,0.45); color: #bfdbfe; }
.alert-success { background: var(--green-soft); border-color: rgba(16,185,129,0.45); color: #a7f3d0; }

/* Login */
.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at 20% 20%, rgba(234, 88, 12, 0.14), transparent 45%), radial-gradient(circle at 80% 80%, rgba(245, 158, 11, 0.1), transparent 45%), var(--bg); }
.login-card { width: 100%; max-width: 440px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45); }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.login-brand h1 { margin: 0; font-size: 20px; }
.login-brand p { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.brand-emblem { width: 44px; height: 44px; border-radius: 11px; background: linear-gradient(135deg, var(--accent), var(--accent-strong)); color: #0a0e17; font-size: 22px; font-weight: 800; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.brand-emblem.sm { width: 34px; height: 34px; font-size: 17px; border-radius: 9px; }
.demo-accounts { margin-top: 22px; padding-top: 16px; border-top: 1px dashed var(--border); }
.demo-title { font-size: 11.5px; color: var(--text-muted); margin-bottom: 10px; }
.demo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.demo-chip { background: var(--bg-input); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; color: var(--text); text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.demo-chip:hover { border-color: var(--accent); background: #161f33; }
.demo-chip strong { font-size: 12px; color: var(--accent); font-family: var(--mono); }
.demo-chip span { font-size: 11px; color: var(--text-muted); }

/* App Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 224px; background: var(--bg-elev); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; position: sticky; top: 0; height: 100vh; }
.sidebar-header { padding: 18px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.sidebar-title { font-weight: 700; font-size: 15px; }
.sidebar-sub { font-size: 11px; color: var(--text-muted); }
.sidebar-nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav-item { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 9px 12px; border-radius: 8px; border: none; background: transparent; color: var(--text-muted); font-size: 13.5px; font-weight: 500; cursor: pointer; text-align: left; transition: all 0.12s; }
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #fbbf24; font-weight: 600; }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.admin-name { font-weight: 600; font-size: 13px; }
.admin-role { font-size: 11.5px; color: var(--accent); }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; padding: 0 24px; border-bottom: 1px solid var(--border); background: rgba(17, 24, 39, 0.85); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
.topbar-left h2 { margin: 0; font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.zone-picker-wrap { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); }
.page-content { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 18px; }

/* Cards & Grids */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.kpi-label { font-size: 12px; color: var(--text-muted); }
.kpi-value { font-size: 24px; font-weight: 700; font-family: var(--mono); }
.kpi-sub { font-size: 11.5px; color: var(--text-muted); }

.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 14.5px; font-weight: 700; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filter-bar .field { min-width: 140px; flex: 1; }
.filter-bar .field.sm { flex: 0 0 130px; min-width: 120px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.8px; }
th { text-align: left; padding: 10px 10px; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; font-size: 12px; }
td { padding: 10px 10px; border-bottom: 1px solid rgba(36, 48, 71, 0.55); vertical-align: middle; }
tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.row-clickable { cursor: pointer; }
.currency-pills { display: grid; grid-template-columns: repeat(2, minmax(90px, 1fr)); gap: 3px 10px; font-size: 11.5px; font-family: var(--mono); }
.currency-pills span { color: var(--text-muted); }
.currency-pills b { color: var(--text); font-weight: 600; }

/* Tabs inside pages */
.subtabs { display: flex; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 14px; }
.subtab { padding: 6px 14px; border-radius: 7px; border: 1px solid var(--border); background: transparent; color: var(--text-muted); font-size: 13px; cursor: pointer; font-weight: 600; }
.subtab.active { background: var(--accent-soft); border-color: rgba(245,158,11,0.5); color: #fbbf24; }

/* Zone cards */
.zone-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.zone-card { background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.zone-card-top { display: flex; align-items: center; justify-content: space-between; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(3, 6, 12, 0.65); z-index: 40; display: flex; justify-content: flex-end; }
.drawer { width: min(760px, 95vw); height: 100vh; background: var(--bg-elev); border-left: 1px solid var(--border-strong); display: flex; flex-direction: column; box-shadow: -16px 0 40px rgba(0,0,0,0.5); }
.drawer-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.drawer-header h3 { margin: 0; font-size: 16px; }
.drawer-body { padding: 18px 20px 32px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }

.role-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.role-card.active-role { border-color: var(--accent); }
.role-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(3, 6, 12, 0.72); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal-box { width: min(580px, 96vw); max-height: 90vh; background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: 12px; display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6); }
.modal-header { padding: 15px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; font-size: 15.5px; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* Item search dropdown & attachments */
.item-search-results { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-input); }
.item-search-row { padding: 7px 10px; border-bottom: 1px solid rgba(36,48,71,0.5); display: flex; align-items: center; justify-content: space-between; cursor: pointer; font-size: 12.5px; }
.item-search-row:hover { background: rgba(245,158,11,0.1); }
.att-list { display: flex; flex-direction: column; gap: 8px; }
.att-row { display: grid; grid-template-columns: 1fr 110px 90px auto; gap: 8px; align-items: center; background: var(--bg-input); border: 1px solid var(--border); padding: 8px 10px; border-radius: 8px; }

/* Permission matrix */
.perm-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.perm-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-input); font-size: 12.5px; cursor: pointer; }
.perm-item input { width: auto; }

/* Toast */
.toast-container { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,0.45); border: 1px solid; background: var(--bg-elev); }
.toast-ok { border-color: var(--green); color: #a7f3d0; }
.toast-err { border-color: var(--red); color: #fecaca; }

.scope-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.scope-box { padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-input); font-size: 12.5px; }
.scope-box strong { display: block; margin-bottom: 4px; font-size: 13px; }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-size: 12.5px; cursor: pointer; }
.checkbox-line input { width: auto; }

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .zone-cards { grid-template-columns: 1fr; }
  .scope-compare, .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
}
