:root {
  --primary: #2dd4bf;
  --primary-dark: #14b8a6;
  --primary-light: #5eead4;
  --primary-container: #ccfbf1;
  --secondary: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --sidebar: 280px;
}

[data-theme='dark'] {
  --bg: #0f172a;
  --surface: #1f2937;
  --surface-soft: #111827;
  --text: #f9fafb;
  --muted: #9ca3af;
  --border: #374151;
  --shadow: 0 18px 38px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.material-symbols-rounded {
  font-size: 20px;
  line-height: 1;
  vertical-align: middle;
}

.boot-screen,
.loading-state,
.empty-state,
.error-state {
  min-height: 280px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
  text-align: center;
}

.boot-screen {
  min-height: 100vh;
}

.boot-screen img {
  width: 72px;
  height: 72px;
  border-radius: 18px;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--primary-container);
  border-top-color: var(--primary-dark);
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 10%, rgba(45, 212, 191, 0.14), transparent 30%),
    linear-gradient(180deg, var(--bg), var(--surface-soft));
}

.login-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-brand {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-brand img {
  width: 78px;
  height: 78px;
  border-radius: 20px;
}

.login-brand h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
}

.form-stack {
  display: grid;
  gap: 16px;
}

.field-label {
  display: block;
  margin: 0 0 8px;
  color: var(--text);
  font-weight: 700;
  text-align: left;
}

.text-input,
.select-input,
.search-box input {
  width: 100%;
  min-height: 50px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-soft);
  color: var(--text);
  outline: none;
  padding: 0 14px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.text-input:focus,
.select-input:focus,
.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.14);
  background: var(--surface);
}

.text-input.area {
  min-height: 108px;
  resize: vertical;
  padding: 14px;
}

.btn {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  color: var(--text);
}

.btn.primary {
  min-height: 50px;
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 12px 22px rgba(20, 184, 166, 0.24);
}

.btn.secondary {
  background: var(--primary-container);
  color: #0f766e;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.danger {
  background: var(--danger);
  color: #ffffff;
}

.btn.compact {
  min-height: 40px;
  padding: 0 12px;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  font-weight: 800;
  padding: 4px;
}

.auth-error {
  display: none;
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.22);
  border-radius: var(--radius);
  padding: 12px;
}

.auth-error.show {
  display: block;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-row img {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

.brand-row strong {
  display: block;
  font-size: 18px;
}

.brand-row span,
.topbar p,
.metric-card p,
.metric-card span,
.table-toolbar p,
.split-legend,
.detail-muted {
  color: var(--muted);
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  font-weight: 800;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: var(--primary-container);
  color: #0f766e;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.content {
  min-width: 0;
  padding: 24px;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 28px;
  line-height: 1.15;
}

.topbar p {
  margin: 0;
}

.top-actions,
.row-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
}

.mobile-menu {
  display: none;
}

.grid {
  display: grid;
  gap: 16px;
}

.metrics-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.two-col {
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
}

.metric-card,
.panel,
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.metric-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
}

.metric-card p,
.metric-card strong,
.metric-card span {
  display: block;
}

.metric-card p {
  margin: 0 0 5px;
  font-weight: 700;
}

.metric-card strong {
  font-size: 24px;
}

.metric-icon,
.state-icon,
.dialog-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-lg);
  display: grid;
  place-items: center;
  background: var(--primary-container);
  color: #0f766e;
}

.metric-icon.success,
.split-bars .success,
.split-legend i.success {
  background: rgba(16, 185, 129, 0.16);
  color: var(--secondary);
}

.metric-icon.warning,
.split-bars .warning,
.split-legend i.warning {
  background: rgba(245, 158, 11, 0.16);
  color: var(--warning);
}

.metric-icon.danger,
.state-icon.danger,
.dialog-icon.danger,
.split-bars .danger,
.split-legend i.danger {
  background: rgba(239, 68, 68, 0.14);
  color: var(--danger);
}

.metric-icon.info,
.split-bars .info,
.split-legend i.info {
  background: rgba(59, 130, 246, 0.14);
  color: var(--info);
}

.panel {
  padding: 18px;
}

.panel h2,
.table-toolbar h2 {
  margin: 0;
  font-size: 18px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.activity-list {
  display: grid;
  gap: 12px;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--surface-soft);
  border-radius: var(--radius);
}

.activity-item strong,
.activity-item span {
  display: block;
}

.bar-chart {
  height: 260px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  align-items: end;
  padding-top: 8px;
}

.bar-item {
  min-width: 0;
  display: grid;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.bar-track {
  height: 210px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--surface-soft);
  border-radius: var(--radius);
  overflow: hidden;
}

.bar-track span {
  width: 100%;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(180deg, var(--primary-light), var(--primary-dark));
}

.split-bars {
  display: flex;
  overflow: hidden;
  height: 14px;
  border-radius: 999px;
  background: var(--surface-soft);
}

.split-bars span {
  display: block;
}

.split-bars .primary,
.split-legend i.primary {
  background: var(--primary);
}

.split-legend {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.split-legend span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.split-legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 8px;
}

.table-card {
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.table-toolbar p {
  margin: 4px 0 0;
}

.table-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-box {
  min-width: 260px;
  min-height: 44px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-soft);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}

.search-box input {
  min-height: 42px;
  border: 0;
  box-shadow: none;
  background: transparent;
  padding: 0;
}

.select-input {
  width: auto;
  min-height: 44px;
  border-radius: var(--radius);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

th button {
  border: 0;
  background: transparent;
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  font-weight: 800;
  text-transform: uppercase;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.status-badge.success {
  color: #047857;
  background: rgba(16, 185, 129, 0.14);
}

.status-badge.warning {
  color: #b45309;
  background: rgba(245, 158, 11, 0.16);
}

.status-badge.danger {
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.14);
}

.status-badge.info {
  color: #1d4ed8;
  background: rgba(59, 130, 246, 0.14);
}

.status-badge.owner {
  color: #0f766e;
  background: rgba(45, 212, 191, 0.18);
}

.status-badge.tenant {
  color: #6d28d9;
  background: rgba(139, 92, 246, 0.16);
}

.truncate-cell {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.reason-cell {
  display: inline-block;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}

.pagination div {
  display: flex;
  gap: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.detail-tile {
  padding: 14px;
  background: var(--surface-soft);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.detail-tile span,
.detail-tile strong {
  display: block;
}

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: grid;
  gap: 10px;
}

.toast {
  transform: translateY(12px);
  opacity: 0;
  min-width: 280px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success .material-symbols-rounded {
  color: var(--secondary);
}

.toast.error .material-symbols-rounded {
  color: var(--danger);
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.48);
}

.dialog {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 22px;
}

.dialog h3 {
  margin: 16px 0 8px;
  font-size: 20px;
}

.dialog p {
  color: var(--muted);
  line-height: 1.5;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

@media (max-width: 1100px) {
  .metrics-grid,
  .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: grid;
  }

  .content {
    padding: 16px;
  }

  .topbar,
  .table-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .table-tools,
  .search-box,
  .table-tools .btn,
  .select-input {
    width: 100%;
  }

  .metrics-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .login-card {
    padding: 24px;
    border-radius: 20px;
  }

  .metric-card {
    align-items: flex-start;
  }
}
