/* Semantic tokens; scale values stay fixed, only these flip per mode
   (prefers-color-scheme default, data-theme override wins both ways). */
:root {
  --accent: #d7261e;
  --accent-dark: #a81c16;
  --success: #12b76a;
  --warning: #f79009;
  --danger: #e4483d;

  --surface: #f7f7f7;
  --surface-raised: #ffffff;
  --surface-sunken: #ededed;
  --text-primary: #1f1f1f;
  --text-secondary: #5c5c5c;
  --border: #dedede;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: #141414;
    --surface-raised: #212121;
    --surface-sunken: #1a1a1a;
    --text-primary: #ededed;
    --text-secondary: #a5a5a5;
    --border: #3a3a3a;
  }
}
:root[data-theme="dark"] {
  --surface: #141414;
  --surface-raised: #212121;
  --surface-sunken: #1a1a1a;
  --text-primary: #ededed;
  --text-secondary: #a5a5a5;
  --border: #3a3a3a;
}

* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--text-secondary); font-size: 13px; margin: 4px 0 12px; }

.brand-mark { font-weight: 800; font-size: 17px; color: var(--accent); letter-spacing: .5px; }
.brand-mark span { color: var(--text-secondary); font-weight: 500; font-size: 13px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 340px; }
.login-card h1 { font-size: 18px; margin: 14px 0 6px; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; padding: 20px 14px; display: flex; flex-direction: column;
  background: var(--surface-raised); border-right: 1px solid var(--border);
}
.sidebar nav { margin-top: 22px; display: flex; flex-direction: column; gap: 2px; }
.nav-btn {
  text-align: left; padding: 9px 12px; border: 0; background: none; border-radius: 8px;
  color: var(--text-secondary); font-size: 14px; cursor: pointer;
}
.nav-btn:hover { background: var(--surface-sunken); }
.nav-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.whoami { font-size: 12px; color: var(--text-secondary); word-break: break-all; margin-bottom: 4px; }

.content { flex: 1; padding: 26px 30px; max-width: 1200px; }
h2 { font-size: 20px; margin-bottom: 14px; }
h3 { font-size: 14px; margin-bottom: 10px; color: var(--text-secondary); }

.card {
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px; margin-bottom: 18px; overflow-x: auto;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } .app { flex-direction: column; } .sidebar { width: 100%; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--surface-raised); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.tile .n { font-size: 26px; font-weight: 800; }
.tile .l { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--text-secondary); font-weight: 600; font-size: 12px; }
.table tr:last-child td { border-bottom: 0; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; }
.bars .bar { flex: 1; max-width: 28px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bars .bar:hover::after {
  content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: var(--surface); font-size: 11px; padding: 2px 6px;
  border-radius: 4px; white-space: nowrap; z-index: 2;
}

label { display: block; font-size: 12px; font-weight: 600; margin: 10px 0 4px; }
input, select {
  padding: 9px 10px; font-size: 14px; border-radius: 8px; width: 100%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-primary);
}
.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.filters input, .filters select { width: auto; }

.btn {
  padding: 10px 16px; font-size: 14px; font-weight: 600; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-raised); color: var(--text-primary); cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: auto; }
.btn.primary:active { background: var(--accent-dark); }
.btn.ghost { background: none; border: 0; color: var(--text-secondary); text-align: left; padding: 6px 8px; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.danger { color: var(--danger); }
form .btn.primary { width: 100%; margin-top: 14px; }

.row-between { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.row-between h2 { margin: 0; }

.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }
.banner {
  background: color-mix(in srgb, var(--warning) 14%, var(--surface-raised));
  border: 1px solid var(--warning); border-radius: 10px; padding: 12px 14px;
  font-size: 13px; margin-bottom: 16px; word-break: break-all;
}
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; font-size: 13px; color: var(--text-secondary); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.pill.ok { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.pill.warn { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.pill.bad { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.pill.muted { background: var(--surface-sunken); color: var(--text-secondary); }
.pill.brand { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }

/* Tenant switcher */
.tenant-switch { margin-top: 18px; }
.tenant-switch label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-secondary); }
.tenant-switch select { margin-top: 4px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal { width: 100%; max-width: 440px; margin: 0; max-height: 90vh; overflow-y: auto; }
.modal h3 { color: var(--text-primary); font-size: 17px; margin-bottom: 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .btn { width: auto; }
.field-row { margin-bottom: 4px; }
.field-row .hint { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.nav-empty { font-size: 12px; color: var(--text-secondary); padding: 8px 12px; }
