:root {
  color-scheme: light;
  --bg: #f4f7f5;
  --ink: #17211b;
  --muted: #5f6d66;
  --line: #cbd8d0;
  --panel: #ffffff;
  --panel-soft: #f8fbf9;
  --header-soft: #eef5f1;
  --hover: #f7fbf9;
  --input-bg: #ffffff;
  --secondary-bg: #dce7e1;
  --badge-bg: #e7eeea;
  --ok-bg: #d8f0e2;
  --danger-bg: #f9dedb;
  --warn-bg: #ffe5bf;
  --usage-low-bg: #e5f5eb;
  --usage-low-line: #b9dec6;
  --usage-medium-bg: #eef3dc;
  --usage-medium-line: #d8e2a5;
  --usage-high-bg: #fff0cf;
  --usage-high-line: #f0cb78;
  --usage-full-bg: #f9dedb;
  --usage-full-line: #e2aaa3;
  --usage-unknown-bg: #f1f4f2;
  --accent: #0f8f6f;
  --accent-dark: #09664f;
  --warn: #b66b00;
  --danger: #b3261e;
  --ok: #0b7a42;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111412;
  --ink: #edf3ef;
  --muted: #a7b2ac;
  --line: #35413a;
  --panel: #191f1b;
  --panel-soft: #151b17;
  --header-soft: #202a24;
  --hover: #1f2a24;
  --input-bg: #101511;
  --secondary-bg: #2a352e;
  --badge-bg: #26302a;
  --ok-bg: #173524;
  --danger-bg: #3a201f;
  --warn-bg: #382b17;
  --usage-low-bg: #173524;
  --usage-low-line: #2b6842;
  --usage-medium-bg: #34381e;
  --usage-medium-line: #6a7433;
  --usage-high-bg: #3f321b;
  --usage-high-line: #8a6724;
  --usage-full-bg: #3a201f;
  --usage-full-line: #7a3d38;
  --usage-unknown-bg: #222924;
  --accent: #2fb58f;
  --accent-dark: #238368;
  --warn: #f0b44a;
  --danger: #ff8b83;
  --ok: #6fd39a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

button:hover {
  background: var(--accent-dark);
}

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

button:disabled:hover {
  background: var(--accent);
}

button.secondary {
  color: var(--ink);
  background: var(--secondary-bg);
}

button.secondary:disabled:hover {
  background: var(--secondary-bg);
}

button.warn {
  background: var(--warn);
}

button.danger {
  background: var(--danger);
}

button.profile-action--new {
  background: #1687d9;
  color: #fff;
}

button.profile-action--new:hover {
  background: #0f6fb4;
}

button.profile-action--activate {
  background: #188038;
  color: #fff;
}

button.profile-action--activate:hover {
  background: #116329;
}

button.profile-action--refresh {
  background: #f4c430;
  color: #211800;
}

button.profile-action--refresh:hover {
  background: #d9a915;
}

button.profile-action--autoblock {
  background: #f47b20;
  color: #fff;
}

button.profile-action--autoblock:hover,
button.profile-action--autoblock:disabled,
button.profile-action--autoblock:disabled:hover {
  background: #f47b20;
  color: #fff;
  opacity: 0.85;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--input-bg);
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 96px;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.login form {
  display: grid;
  gap: 14px;
}

.dashboard {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

.topbar,
.panel-head,
.top-actions,
.summary,
.meta-grid {
  display: flex;
  gap: 12px;
}

.topbar {
  align-items: center;
  justify-content: space-between;
  margin: 0;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.refresh-status {
  color: var(--muted);
  font-size: 13px;
  min-width: 132px;
  text-align: right;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 34px;
}

h2 {
  font-size: 22px;
}

h3 {
  margin: 18px 0 8px;
  font-size: 16px;
}

.summary {
  flex-wrap: wrap;
  margin: 0;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.stat,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stat {
  min-width: 132px;
  padding: 10px 12px;
}

.stat strong {
  display: block;
  font-size: 22px;
}

.panel {
  padding: 18px;
  margin: 20px;
}

.panel-head {
  align-items: center;
  justify-content: space-between;
}

.profile-panel {
  padding: 0;
  overflow: hidden;
  margin: 0;
  border-left: 0;
  border-right: 0;
  border-radius: 0;
}

.profile-panel .panel-head {
  padding: 18px;
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.profiles-table-wrap {
  width: 100%;
  overflow-x: visible;
  padding: 0 20px 20px;
}

.profiles-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14px;
}

.profiles-table th,
.profiles-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.profiles-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--header-soft);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.profiles-table tbody tr {
  cursor: pointer;
}

.profiles-table tbody tr:hover,
.profiles-table tbody tr.selected {
  background: var(--hover);
}

.profiles-table tbody tr.rotation-excluded td {
  opacity: 0.58;
}

.profiles-table tbody tr.rotation-excluded.selected td,
.profiles-table tbody tr.rotation-excluded:hover td {
  opacity: 0.72;
}

.profiles-table tbody tr.selected td:first-child {
  box-shadow: inset 4px 0 0 var(--accent);
}

.profiles-table th:nth-child(1),
.profiles-table td:nth-child(1) {
  width: 13%;
}

.profiles-table th:nth-child(2),
.profiles-table td:nth-child(2) {
  width: 9%;
}

.profiles-table th:nth-child(3),
.profiles-table td:nth-child(3) {
  width: 6%;
}

.profiles-table th:nth-child(4),
.profiles-table td:nth-child(4) {
  width: 10%;
}

.profiles-table th:nth-child(5),
.profiles-table td:nth-child(5) {
  width: 11%;
}

.profiles-table th:nth-child(6),
.profiles-table td:nth-child(6) {
  width: 10%;
}

.profiles-table th:nth-child(7),
.profiles-table td:nth-child(7) {
  width: 12%;
}

.profiles-table th:nth-child(8),
.profiles-table td:nth-child(8) {
  width: 8%;
}

.profiles-table th:nth-child(9),
.profiles-table td:nth-child(9) {
  width: 11%;
}

.profiles-table th:nth-child(10),
.profiles-table td:nth-child(10) {
  width: 10%;
}

.profile-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.badge {
  border-radius: 8px;
  padding: 2px 6px;
  background: var(--badge-bg);
  color: var(--ink);
  font-size: 12px;
}

.badge.ready {
  background: var(--ok-bg);
  color: var(--ok);
}

.badge.expired,
.badge.auth_error,
.badge.needs_login {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge.blocked_locally {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.usage_limited,
.badge.cloud_timeout {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.no_entitlement,
.badge.cloud_error {
  background: var(--danger-bg);
  color: var(--danger);
}

.muted,
.small {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.token-line,
.clamp {
  overflow-wrap: anywhere;
}

.usage-chip {
  display: block;
  width: 100%;
  margin-bottom: 4px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--header-soft);
  color: var(--ink);
}

.usage-chip.small {
  font-size: 12px;
}

.usage-chip.usage-low {
  background: var(--usage-low-bg);
  border-color: var(--usage-low-line);
}

.usage-chip.usage-medium {
  background: var(--usage-medium-bg);
  border-color: var(--usage-medium-line);
}

.usage-chip.usage-high {
  background: var(--usage-high-bg);
  border-color: var(--usage-high-line);
}

.usage-chip.usage-full {
  background: var(--usage-full-bg);
  border-color: var(--usage-full-line);
  color: var(--danger);
}

.usage-chip.usage-unknown {
  background: var(--usage-unknown-bg);
}

.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.row-actions button {
  min-height: 30px;
  padding: 4px 5px;
  font-size: 12px;
}

.action-hint {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

pre {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-soft);
  color: var(--ink);
  max-height: 420px;
}

.error {
  color: var(--danger);
  min-height: 20px;
}

@media (max-width: 900px) {
  .topbar,
  .panel-head {
    display: block;
  }

  .topbar,
  .summary {
    padding: 12px;
  }

  .panel {
    margin: 12px;
  }

  .profile-panel {
    margin: 0;
  }

  .profiles-table-wrap {
    padding: 0 20px 20px;
  }

  .profiles-table {
    font-size: 12px;
  }

  .profiles-table th,
  .profiles-table td {
    padding: 5px;
  }

  .row-actions {
    grid-template-columns: 1fr;
  }

  .row-actions button,
  .badge,
  .small {
    font-size: 11px;
  }
}
