:root {
  --brand: #b4161a;
  --brand-dark: #7f0f12;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #222;
  --muted: #666;
  --border: #e3e5e8;
  --warn: #f7b500;
  --ok: #1a8a3a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; color: var(--text); background: var(--bg); }
.hidden { display: none !important; }

/* Login page */
.login-page { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--card); padding: 32px; border-radius: 10px; box-shadow: 0 4px 18px rgba(0,0,0,0.08); width: 360px; }
.brand { color: var(--brand); margin: 0; font-size: 28px; }
.subtitle { color: var(--muted); margin: 4px 0 24px; font-size: 13px; }
.login-card label { display: block; font-size: 13px; margin-top: 14px; color: #333; }
.login-card input { width: 100%; padding: 10px; margin-top: 4px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.login-card button { width: 100%; margin-top: 20px; padding: 11px; background: var(--brand); color: #fff; border: 0; border-radius: 6px; font-size: 15px; cursor: pointer; }
.login-card button:hover { background: var(--brand-dark); }
.banner { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }
.banner-warn { background: #fff5d6; color: #8a6d00; border: 1px solid #f7d978; }
.status-line { margin-top: 14px; font-size: 13px; color: var(--muted); min-height: 18px; }
.footer { margin-top: 30px; color: var(--muted); font-size: 12px; }

/* App shell */
.app-page { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr; grid-template-areas: "top top" "side main"; min-height: 100vh; }
.topbar { grid-area: top; background: var(--brand); color: #fff; display: flex; align-items: center; padding: 0 18px; gap: 20px; }
.brand-small { font-weight: 700; letter-spacing: .5px; }
.scope-bar { flex: 1; font-size: 13px; opacity: 0.95; }
.user-box { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-box button { background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.4); border-radius: 4px; padding: 5px 10px; cursor: pointer; }
.role-badge { background: rgba(255,255,255,0.22); border-radius: 4px; padding: 2px 7px; font-size: 11px; text-transform: uppercase; }

.sidebar { grid-area: side; background: #fff; border-right: 1px solid var(--border); padding: 16px 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { padding: 11px 18px; font-size: 14px; color: #333; cursor: pointer; border-left: 3px solid transparent; }
.sidebar li:hover { background: #f0f1f4; }
.sidebar li.active { background: #fbeaea; border-left-color: var(--brand); color: var(--brand); font-weight: 600; }

main { grid-area: main; padding: 22px 26px; overflow: auto; }
main h2 { margin-top: 0; color: #222; }

table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 6px; overflow: hidden; }
th, td { padding: 9px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
th { background: #f0f1f4; font-weight: 600; color: #555; }

.card { background: #fff; padding: 18px; border-radius: 8px; margin-bottom: 18px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.btn { background: var(--brand); color: #fff; border: 0; padding: 8px 14px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.btn:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: #fff; border-radius: 8px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); border-top: 3px solid var(--brand); }
.stat-label { color: var(--muted); font-size: 12px; text-transform: capitalize; margin-bottom: 8px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--brand); }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.inline-actions { display: flex; gap: 10px; }
.filters-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.filters-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.filters-row input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.mini-summary { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 14px; }

#toast-host { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: #333; color: #fff; padding: 10px 14px; border-radius: 5px; font-size: 13px; max-width: 320px; }
.toast.error { background: #b4161a; }
.toast.ok { background: #1a8a3a; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; z-index: 1100; }
.modal-card { background: #fff; padding: 24px 28px; border-radius: 10px; max-width: 380px; }
.modal-card h3 { margin-top: 0; color: var(--brand); }
.modal-card button { margin-top: 18px; background: var(--brand); color: #fff; border: 0; padding: 9px 18px; border-radius: 5px; cursor: pointer; }

.scope-bar.branch-head { background: #f7b500; color: #222; padding: 4px 10px; border-radius: 4px; }

@media (max-width: 900px) {
  .app-page { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr; grid-template-areas: "top" "side" "main"; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar ul { display: flex; overflow: auto; }
  .sidebar li { border-left: 0; border-bottom: 3px solid transparent; white-space: nowrap; }
  .sidebar li.active { border-bottom-color: var(--brand); }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; }
}
