/* ============ Theme variables ============ */
:root, [data-theme="light"] {
  --bg: #f1f5f9; --surface: #ffffff; --surface2: #f8fafc;
  --text: #0f172a; --muted: #64748b; --border: #e2e8f0;
  --primary: #2563eb; --primary-hover: #1d4ed8; --primary-soft: #dbeafe;
  --success: #16a34a; --success-soft: #dcfce7;
  --warning: #d97706; --warning-soft: #fef3c7;
  --danger: #dc2626; --danger-soft: #fee2e2;
  --info: #0891b2; --info-soft: #cffafe;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
[data-theme="dark"] {
  --bg: #0b1220; --surface: #111a2e; --surface2: #16213a;
  --text: #e2e8f0; --muted: #8b9bb4; --border: #1f2c47;
  --primary: #3b82f6; --primary-hover: #60a5fa; --primary-soft: #1e3a8a;
  --success: #4ade80; --success-soft: #14351f;
  --warning: #fbbf24; --warning-soft: #3a2c0a;
  --danger: #f87171; --danger-soft: #3d1414;
  --info: #22d3ee; --info-soft: #0a3038;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg); color: var(--text); display: flex; min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1rem 0 .6rem; }
h3 { font-size: 1rem; margin: .8rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ============ Layout ============ */
.sidebar {
  width: 230px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: .5rem; padding: 1rem; font-weight: 700; border-bottom: 1px solid var(--border); }
.brand img { width: 32px; height: 32px; object-fit: contain; border-radius: 6px; }
.sidebar nav { flex: 1; padding: .5rem; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; margin: 2px 0;
  border-radius: 8px; color: var(--text); font-size: .95rem;
}
.sidebar nav a:hover { background: var(--surface2); }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-footer { padding: .8rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .4rem; }
.userline { font-size: .85rem; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; }
.content { padding: 1.2rem; max-width: 1300px; width: 100%; }

/* ============ Cards / stats ============ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.4rem; font-weight: 700; margin-top: .2rem; }
.stat.accent { border-left: 4px solid var(--primary); }
.stat.green { border-left: 4px solid var(--success); }
.stat.red { border-left: 4px solid var(--danger); }
.stat.amber { border-left: 4px solid var(--warning); }

/* ============ Forms ============ */
label { display: block; margin-bottom: .7rem; font-size: .88rem; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: .5rem .65rem; margin-top: .25rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface2); color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type="checkbox"], input[type="radio"] { width: auto; margin-right: .35rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; }
.inline-check { display: flex; align-items: center; font-weight: 400; }
fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 0 0 1rem; padding: .8rem 1rem; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .4rem; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .9rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); cursor: pointer; font: inherit; font-size: .9rem; text-decoration: none;
}
.btn:hover { background: var(--surface2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text); }
.btn-sm { padding: .25rem .55rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-wa { background: #25d366; border-color: #25d366; color: #fff; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
table.data tbody tr:hover { background: var(--surface2); }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--primary); }
table.data th .arrow { font-size: .7rem; }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--border); }

/* ============ Badges / alerts ============ */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: var(--surface2); color: var(--muted); }
.alert { padding: .7rem 1rem; border-radius: 10px; margin-bottom: .8rem; font-size: .92rem; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-info { background: var(--info-soft); color: var(--info); }

/* ============ Calendar ============ */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: .75rem; color: var(--muted); padding: .3rem 0; text-transform: uppercase; }
.cal .day {
  min-height: 86px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: .3rem .4rem; font-size: .78rem; position: relative; display: block; color: var(--text);
}
.cal .day:hover { border-color: var(--primary); }
.cal .day .num { font-weight: 700; }
.cal .day.other { opacity: .35; }
.cal .day.today { border: 2px solid var(--primary); }
.cal .day.locked { background: var(--danger-soft); }
.cal .pill { display: block; margin-top: 2px; padding: 1px 5px; border-radius: 5px; background: var(--primary-soft); color: var(--primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal .pill.lock { background: var(--danger-soft); color: var(--danger); }

/* ============ Tabs ============ */
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a { padding: .5rem .9rem; border-radius: 8px 8px 0 0; color: var(--muted); font-size: .9rem; font-weight: 500; }
.tabs a.active { color: var(--primary); background: var(--surface); border: 1px solid var(--border); border-bottom-color: var(--surface); margin-bottom: -1px; }

/* ============ Login ============ */
.login-body { align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 380px; margin: 2rem auto; text-align: center; }
.login-card form { text-align: left; margin-top: 1rem; }
.login-logo { width: 64px; height: 64px; object-fit: contain; }

/* ============ QR modal ============ */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal-bg.open { display: flex; }
.modal { background: var(--surface); border-radius: 14px; padding: 1.4rem; max-width: 420px; width: 92%; text-align: center; }
.modal img, .modal canvas { background: #fff; padding: 10px; border-radius: 10px; }

/* ============ Responsive ============ */
@media (max-width: 860px) {
  .sidebar { position: fixed; left: -240px; transition: left .2s; z-index: 40; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-btn { display: inline-flex; }
  .grid3, .grid4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .content { padding: .8rem; }
}
@media print {
  .sidebar, .topbar, .toolbar, .btn, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .content { padding: 0; max-width: none; }
  .card { border: none; box-shadow: none; }
}
