:root {
  /* Light mode defaults */
  --bg-body: #f3f4f6;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-topbar: #ffffff;
  --accent: #0ea5e9;
  --accent-soft: rgba(14,165,233,0.1);
  --accent-strong: #0369a1;
  --text-main: #0f172a;
  --text-muted: #6b7280;
  --border-subtle: rgba(148,163,184,0.5);
  --danger: #b91c1c;
  --success: #16a34a;
  --warning: #ca8a04;
}

:root[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-sidebar: #020617;
  --bg-card: #020617;
  --bg-topbar: #020617;
  --accent: #38bdf8;
  --accent-soft: rgba(56,189,248,0.1);
  --accent-strong: #0ea5e9;
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --border-subtle: rgba(148,163,184,0.3);
  --danger: #f97373;
  --success: #4ade80;
  --warning: #facc15;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(circle at top left, var(--bg-body), var(--bg-body));
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  width: 100%;
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 40% 0 0;
    max-width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.8);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 40;
  }
  .sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Sidebar */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid rgba(15,23,42,0.1);
  padding: 1.25rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 0.75rem;
  background: radial-gradient(circle at 30% 0%, var(--accent), var(--accent-strong) 40%, var(--bg-body) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #0b1120;
  box-shadow: 0 0 0 1px rgba(15,23,42,0.06), 0 10px 30px rgba(15,23,42,0.15);
}

.brand-title {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.brand-title span:first-child {
  font-weight: 600;
  letter-spacing: 0.06em;
  font-size: 0.85rem;
  text-transform: uppercase;
  color: var(--accent);
}

.brand-title span:last-child {
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sidebar-section-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0.6rem;
  color: var(--text-muted);
  font-size: 0.86rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  text-decoration: none;
}

.nav-item-main {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.nav-icon {
  width: 22px;
  height: 22px;
  border-radius: 0.45rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  background: rgba(148,163,184,0.12);
}

.nav-item.active {
  background: linear-gradient(90deg, var(--accent-soft), rgba(56,189,248,0.03));
  color: var(--accent-strong);
}

.nav-item:hover {
  background: rgba(148,163,184,0.12);
  transform: translateY(-1px);
}

.nav-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  margin-bottom: 0.5rem;
  border-top: 1px solid rgba(148,163,184,0.4);
  padding-top: 0.9rem;
}

.tenant-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(37,99,235,0.4);
  background: radial-gradient(circle at top left, rgba(59,130,246,0.18), rgba(248,250,252,0.9));
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.tenant-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(74,222,128,0.25);
}

.usage {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.usage-bar-outer {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(148,163,184,0.25);
  overflow: hidden;
}

.usage-bar-inner {
  height: 100%;
  width: 58%;
  background: linear-gradient(90deg, #22c55e, #facc15);
  box-shadow: 0 0 12px rgba(34,197,94,0.7);
}

.small-link {
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
}

.small-link:hover { text-decoration: underline; }

/* Main area */
.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  backdrop-filter: blur(24px);
  background: radial-gradient(circle at top left, rgba(248,250,252,0.96), rgba(241,245,249,0.98));
}

:root[data-theme="dark"] .main {
  background: radial-gradient(circle at top left, rgba(15,23,42,0.96), rgba(15,23,42,0.98));
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid rgba(148,163,184,0.4);
  background: var(--bg-topbar);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.mobile-menu-btn {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 0.75rem;
  border: 1px solid rgba(148,163,184,0.7);
  background: radial-gradient(circle at top left, var(--bg-body), var(--bg-sidebar));
  color: var(--text-muted);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

@media (max-width: 768px) {
  .mobile-menu-btn { display: flex; }
}

.page-title {
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.topbar-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.filter-pill {
  padding: 0.26rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.6);
  color: var(--text-muted);
  background: rgba(248,250,252,0.9);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

:root[data-theme="dark"] .filter-pill {
  background: rgba(15,23,42,0.8);
  border-color: rgba(51,65,85,0.9);
}

.filter-pill span.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 6px rgba(56,189,248,0.7);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.7);
  background: radial-gradient(circle at top, var(--bg-body), var(--bg-sidebar));
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: pointer;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.7);
  background: radial-gradient(circle at top left, var(--bg-body), var(--bg-sidebar));
  font-size: 0.78rem;
  color: var(--text-muted);
}

.user-avatar {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 0%, var(--accent), var(--accent-strong) 40%, var(--bg-body) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #0b1120;
}

/* Content wrapper */
.content {
  padding: 1rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.content-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: space-between;
  align-items: flex-start;
}

.content-header-main {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.content-header-main h1 {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.status-pill {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(22,163,74,0.12);
  color: var(--success);
  border: 1px solid rgba(34,197,94,0.5);
}

.content-header-main p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.content-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.btn {
  border-radius: 0.55rem;
  border: 1px solid rgba(37,99,235,0.8);
  background: linear-gradient(135deg, #0ea5e9, #22c55e);
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  color: #0b1120;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(34,197,94,0.25);
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border-color: rgba(37,99,235,0.4);
  box-shadow: none;
}

/* Cards, grids, table, badges, form, etc. */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
}

@media (max-width: 992px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-card);
  border-radius: 0.9rem;
  border: 1px solid rgba(148,163,184,0.5);
  box-shadow: 0 18px 45px rgba(15,23,42,0.08);
  padding: 0.7rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

:root[data-theme="dark"] .card {
  border-color: rgba(30,64,175,0.7);
  box-shadow: 0 18px 45px rgba(15,23,42,0.9);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pill-soft {
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(148,163,184,0.12);
  border: 1px solid rgba(148,163,184,0.6);
  font-size: 0.7rem;
}

.kpi-value {
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kpi-trend {
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.kpi-trend.positive { color: var(--success); }
.kpi-trend.negative { color: var(--danger); }

.grid-main {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(0, 1.2fr);
  gap: 0.8rem;
  align-items: flex-start;
}

@media (max-width: 1024px) {
  .grid-main { grid-template-columns: 1fr; }
}

.card-title {
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.45rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title span {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* Table */
.table-wrapper {
  border-radius: 0.6rem;
  border: 1px solid rgba(148,163,184,0.5);
  overflow: hidden;
  background: rgba(248,250,252,0.9);
}

:root[data-theme="dark"] .table-wrapper {
  background: rgba(15,23,42,0.9);
  border-color: rgba(30,64,175,0.7);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

thead {
  background: rgba(241,245,249,0.96);
}

:root[data-theme="dark"] thead {
  background: rgba(15,23,42,0.96);
}

th, td {
  padding: 0.5rem 0.65rem;
  text-align: left;
}

th {
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(148,163,184,0.7);
}

tbody tr:nth-child(even) {
  background: rgba(249,250,251,0.9);
}

:root[data-theme="dark"] tbody tr:nth-child(even) {
  background: rgba(15,23,42,0.98);
}

tbody tr:hover {
  background: rgba(226,232,240,0.9);
}

:root[data-theme="dark"] tbody tr:hover {
  background: rgba(15,23,42,0.9);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
}

.badge-success {
  background: rgba(22,163,74,0.18);
  color: var(--success);
  border: 1px solid rgba(34,197,94,0.5);
}

.badge-warning {
  background: rgba(250,204,21,0.18);
  color: var(--warning);
  border: 1px solid rgba(250,204,21,0.6);
}

.badge-danger {
  background: rgba(248,113,113,0.18);
  color: var(--danger);
  border: 1px solid rgba(248,113,113,0.6);
}

.tag {
  font-size: 0.68rem;
  padding: 0.14rem 0.38rem;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.7);
  color: var(--text-muted);
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem 0.5rem;
  margin-bottom: 0.4rem;
}

@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.76rem;
}

.form-field label { color: var(--text-muted); }

.form-field input,
.form-field select {
  border-radius: 0.55rem;
  border: 1px solid rgba(148,163,184,0.7);
  background: rgba(248,250,252,0.95);
  padding: 0.3rem 0.45rem;
  color: var(--text-main);
  font-size: 0.78rem;
  outline: none;
}

:root[data-theme="dark"] .form-field input,
:root[data-theme="dark"] .form-field select {
  background: rgba(15,23,42,0.95);
  border-color: rgba(51,65,85,0.9);
  color: var(--text-main);
}

.form-field input:focus,
.form-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(56,189,248,0.6);
}

.form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
  flex-wrap: wrap;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 30px;
  height: 16px;
  border-radius: 999px;
  background: rgba(148,163,184,0.7);
  position: relative;
  transition: background 0.2s ease;
}

.switch-thumb {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #e5e7eb;
  position: absolute;
  top: 1px;
  left: 1px;
  transition: transform 0.2s ease, background 0.2s ease;
}

.switch input:checked + .switch-track { background: #22c55e; }
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(14px);
  background: #ffffff;
}

.pill-mini {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px dashed rgba(148,163,184,0.7);
  color: var(--text-muted);
}

/* Tiny sparkline */
.sparkline {
  margin-top: 0.2rem;
  width: 100%;
  height: 24px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(56,189,248,0.08), rgba(56,189,248,0.01));
  position: relative;
  overflow: hidden;
}

.sparkline-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(56,189,248,0.4), rgba(56,189,248,0.05));
  clip-path: polygon(0 70%, 10% 55%, 20% 60%, 30% 40%, 40% 42%, 50% 35%, 60% 48%, 70% 30%, 80% 45%, 90% 32%, 100% 38%, 100% 100%, 0 100%);
  opacity: 0.9;
}

.sparkline-line {
  position: absolute;
  inset: 0;
  border-bottom: 1px dashed rgba(148,163,184,0.4);
}
