:root {
  --purple: #8b5cf6;
  --purple-dim: #6d3fd6;
  --blue: #38bdf8;
  --orange: #fb923c;
  --green: #34d399;
  --red: #f87171;

  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html[data-theme="dark"] {
  --bg: #0e0e15;
  --bg-elevated: #15151f;
  --bg-card: #1a1a26;
  --bg-hover: #22222f;
  --border: #2a2a3a;
  --text: #eceef2;
  --text-muted: #9497a8;
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
}

html[data-theme="light"] {
  --bg: #f4f5f9;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f0eefc;
  --border: #e2e3ec;
  --text: #191a23;
  --text-muted: #666a80;
  --shadow: 0 2px 10px rgba(30,30,60,0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 24px;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  flex-shrink: 0;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.3px; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  padding: 16px 10px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
}
.nav-link:hover { background: var(--bg-hover); text-decoration: none; }
.nav-link.active { background: var(--bg-hover); color: var(--purple); }
.nav-link.active::before {
  content: ""; position: absolute; left: -12px; top: 6px; bottom: 6px; width: 3px;
  background: var(--purple); border-radius: 2px;
}
.nav-icon { width: 18px; text-align: center; opacity: 0.85; }
.nav-badge {
  margin-left: auto; background: var(--orange); color: #1a1005; font-size: 10.5px;
  font-weight: 700; padding: 1px 6px; border-radius: 10px;
}

.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

/* ---------- Main area ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.topbar-title { font-size: 18px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.theme-toggle {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-card);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px; color: var(--text);
}
.theme-toggle:hover { background: var(--bg-hover); }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 5px; border-radius: 20px;
  background: var(--bg-card); border: 1px solid var(--border);
  cursor: pointer; font-size: 13px;
}
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--orange));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 11px;
}

.content { padding: 26px 28px 60px; max-width: 1180px; }

/* ---------- Cards / primitives ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}
.card-title {
  font-size: 15px; font-weight: 700; margin: 0 0 4px;
  display: flex; align-items: center; justify-content: space-between;
}
.card-sub { color: var(--text-muted); font-size: 12.5px; margin-bottom: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: var(--font);
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn-primary:hover { background: var(--purple-dim); }
.btn-outline-blue { border-color: var(--blue); color: var(--blue); background: transparent; }
.btn-outline-orange { border-color: var(--orange); color: var(--orange); background: transparent; }
.btn-danger { border-color: var(--red); color: var(--red); background: transparent; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-icon { padding: 7px 9px; }

.badge {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px;
}
.badge-purple { background: rgba(139,92,246,0.15); color: var(--purple); }
.badge-blue { background: rgba(56,189,248,0.15); color: var(--blue); }
.badge-orange { background: rgba(251,146,60,0.15); color: var(--orange); }
.badge-green { background: rgba(52,211,153,0.15); color: var(--green); }
.badge-red { background: rgba(248,113,113,0.15); color: var(--red); }
.badge-muted { background: var(--bg-hover); color: var(--text-muted); }

input, select, textarea {
  font-family: var(--font);
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13.5px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.15);
}
label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 5px; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 160px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.3px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.progress {
  height: 10px; border-radius: 6px; background: var(--bg);
  border: 1px solid var(--border); overflow: hidden;
}
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--purple), var(--blue)); border-radius: 6px; transition: width 0.3s; }
.progress-bar.warn { background: linear-gradient(90deg, var(--orange), var(--red)); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; opacity: 0.5; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 15.5px; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; }

.toast-stack { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--bg-card); border: 1px solid var(--border); border-left: 4px solid var(--purple);
  border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); font-size: 13px; min-width: 240px;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }

.client-picker { min-width: 220px; }

.section-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.section-header h2 { margin: 0; font-size: 20px; }

.text-muted { color: var(--text-muted); }
.mb-0 { margin-bottom: 0 !important; }
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.wrap { flex-wrap: wrap; }
.justify-between { justify-content: space-between; }

.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 34px 30px; box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand .brand-mark { margin: 0 auto 12px; width: 44px; height: 44px; border-radius: 12px; }
.login-brand h1 { font-size: 18px; margin: 0 0 2px; }
.login-brand p { color: var(--text-muted); font-size: 12.5px; margin: 0; }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 500; height: 100vh; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 18px 16px 50px; }
  .topbar { padding: 12px 16px; }
}
