:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e5e9f2;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #E4110A;
  --primary-dark: #B50D08;
  --primary-soft: #fdecea;
  --success: #16a34a;
  --success-soft: #e9f9ef;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warning: #d97706;
  --warning-soft: #fff5e6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, 0.12);
  --sidebar-w: 244px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 .2em; font-weight: 650; color: #111827; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(rgba(15, 23, 42, .55), rgba(15, 23, 42, .62)), url('/img/login-bg.jpg') center / cover no-repeat;
  padding: 20px;
}
.login-logo { max-width: 190px; height: auto; display: block; margin: 0 auto 4px; }
.side-logo { height: 60px; width: auto; min-width: 96px; flex: 0 0 auto; display: block; }
.login-card {
  background: var(--surface); width: 100%; max-width: 400px; border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 36px 32px; border: 1px solid var(--border);
}
.login-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-card .brand .logo { width: 40px; height: 40px; border-radius: 10px;
  background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.login-card h1 { font-size: 20px; }
.login-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
  position: fixed; top: 0; left: 0; bottom: 0; display: flex; flex-direction: column; z-index: 40;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.sidebar .brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--primary);
  color: #fff; display: grid; place-items: center; font-weight: 800; }
.sidebar .brand b { font-size: 15px; }
.nav { padding: 12px 10px; overflow-y: auto; flex: 1; }
.nav .group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #9aa3b2;
  padding: 14px 12px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px;
  color: #374151; font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: #f3f5fa; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav a .ico { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav a.active .ico { color: var(--primary); }

.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 30; }
.topbar .page-title { font-size: 16px; font-weight: 650; }
.topbar .right { display: flex; align-items: center; gap: 14px; }
.balance-chip { display: flex; align-items: center; gap: 8px; background: var(--success-soft); color: var(--success);
  padding: 6px 12px; border-radius: 20px; font-weight: 650; font-size: 13px; }
.demo-chip { background: var(--warning-soft); color: var(--warning); padding: 5px 11px; border-radius: 20px;
  font-size: 12px; font-weight: 650; }
.user-menu { display: flex; align-items: center; gap: 9px; cursor: pointer; position: relative; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.dropdown { position: absolute; right: 0; top: 44px; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 180px; padding: 6px; display: none; }
.dropdown.open { display: block; }
.dropdown a { display: block; padding: 9px 12px; border-radius: 7px; color: #374151; }
.dropdown a:hover { background: #f3f5fa; }

.content { padding: 24px; max-width: 1200px; width: 100%; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .cols-3, .cols-2 { grid-template-columns: 1fr; } .cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .cols-4 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; }
.card h3.card-title { font-size: 14px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
.stat .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 750; color: #111827; }
.stat .value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .ico-badge { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); float: right; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: #374151; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], input[type=date], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text); transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(228, 17, 10, .13); }
textarea { resize: vertical; min-height: 90px; }
.field { margin-bottom: 16px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 160px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 8px; cursor: pointer; }
.check input { width: auto; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 10px 16px; border-radius: 9px;
  border: 1px solid transparent; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  background: var(--primary); color: #fff; transition: background .15s, opacity .15s; }
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #fff; color: #374151; border-color: var(--border); }
.btn.secondary:hover { background: #f3f5fa; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn-row { display: flex; gap: 10px; align-items: center; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f9fafc; color: #6b7280; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
tbody tr:hover { background: #fafbfe; }
td.wrap, th.wrap { white-space: normal; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 650; }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge.amber { background: var(--warning-soft); color: var(--warning); }
.badge.gray { background: #eef0f4; color: #6b7280; }

/* ---------- Misc ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 12px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.pill { padding: 7px 14px; border-radius: 20px; background: #fff; border: 1px solid var(--border);
  cursor: pointer; font-weight: 600; font-size: 13px; color: #374151; }
.pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.counter-box { display: flex; gap: 16px; flex-wrap: wrap; padding: 12px 14px; background: #f9fafc;
  border: 1px solid var(--border); border-radius: 9px; margin-top: 8px; font-size: 13px; }
.counter-box b { color: #111827; }
.alert { padding: 11px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 14px; font-weight: 500; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--success-soft); color: var(--success); }
.alert.info { background: var(--primary-soft); color: var(--primary-dark); }

/* Toast */
#toasts { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast { background: #111827; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
  font-size: 13.5px; font-weight: 500; min-width: 220px; max-width: 340px; animation: slidein .2s ease; }
.toast.ok { background: #15803d; } .toast.err { background: #b91c1c; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); display: none; align-items: flex-start;
  justify-content: center; z-index: 90; padding: 40px 16px; overflow-y: auto; }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 560px;
  padding: 24px; animation: slidein .18s ease; }
.modal h3 { font-size: 17px; margin-bottom: 16px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal.lg { max-width: 720px; }

.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; }
.spinner.dark { border-color: rgba(37,99,235,.25); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: grid; place-items: center; padding: 60px; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.text-muted { color: var(--muted); }
.mt0 { margin-top: 0; } .mb0 { margin-bottom: 0; }
.flex { display: flex; } .between { justify-content: space-between; } .items-center { align-items: center; }
.gap { gap: 10px; } .wrap { flex-wrap: wrap; }

/* ---------- Mobil / responsive ---------- */
.menu-toggle { display: none; }
.topbar-logo { display: none; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(17, 24, 39, .5); z-index: 45; }
.sidebar-overlay.open { display: block; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; z-index: 60; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex !important; padding: 7px 10px; }
  .topbar-logo { display: block; height: 26px; width: auto; min-width: 46px; flex: 0 0 auto; object-fit: contain; }
  .page-title { display: none; }
  .user-info { display: none; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .right { gap: 8px; }
  .content { padding: 16px 14px; }
  .balance-chip { padding: 5px 10px; font-size: 12px; }
  .demo-chip { padding: 4px 8px; font-size: 11px; }
  .avatar { width: 32px; height: 32px; }
  .page-head h2 { font-size: 18px; }
  .modal-bg { padding: 16px 12px; align-items: flex-start; }
}

@media (max-width: 520px) {
  .content { padding: 14px 10px; }
  .demo-chip { display: none !important; }
  th, td { padding: 9px 10px; }
  .card { padding: 16px 14px; }
  .modal { padding: 18px; border-radius: 12px; }
  .login-card { padding: 26px 20px; }
  .page-head { gap: 10px; }
  .page-head .btn, .page-head .btn-row { width: 100%; }
  .page-head .btn-row .btn { flex: 1; justify-content: center; }
  .stat .value { font-size: 22px; }
}
