:root {
  color-scheme: dark;
  --bg: #111315;
  --surface: #181b1e;
  --surface-2: #202428;
  --surface-3: #292e33;
  --line: #353b41;
  --line-soft: #2a2f34;
  --text: #f1f3f4;
  --muted: #9da5ad;
  --green: #47c58b;
  --green-soft: #17382b;
  --amber: #e5b958;
  --amber-soft: #3d321b;
  --red: #ed7272;
  --red-soft: #401f22;
  --cyan: #58b8c8;
  --cyan-soft: #19353b;
  --focus: #79d6a8;
  --sidebar: 224px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; letter-spacing: 0; }

button { color: inherit; }

.hidden { display: none !important; }

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

.login-panel {
  width: min(100%, 390px);
  padding: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.38);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.brand-block h1 { margin: 0; font-size: 20px; line-height: 1.25; }
.brand-block p { margin: 4px 0 0; color: var(--muted); }

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 7px;
  background: var(--green);
  color: #0b2118;
  font-size: 15px;
  font-weight: 800;
}

.brand-mark.small { width: 34px; height: 34px; font-size: 12px; }

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}

.login-panel label + label { margin-top: 16px; }

input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #121518;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

textarea { resize: vertical; min-height: 210px; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); box-shadow: 0 0 0 2px rgba(121, 214, 168, 0.14); }
input:disabled, select:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; }

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 13px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

button:disabled { opacity: .42; cursor: not-allowed; }

.primary { background: var(--green); color: #092218; font-weight: 750; }
.primary:hover:not(:disabled) { background: #61d49d; }
.secondary { background: var(--surface-2); border-color: var(--line); color: var(--text); }
.secondary:hover:not(:disabled) { background: var(--surface-3); border-color: #48515a; }
.danger { background: var(--red-soft); border-color: #744047; color: #ffb4b4; }
.danger:hover:not(:disabled) { background: #54262b; border-color: #96525a; }
.wide { width: 100%; margin-top: 22px; }
.compact { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.icon-button { width: 34px; height: 34px; min-height: 34px; padding: 0; display: grid; place-items: center; background: transparent; border-color: transparent; color: var(--muted); font-size: 20px; }
.icon-button:hover { color: var(--text); background: var(--surface-3); }

.form-error { min-height: 20px; margin-top: 10px; color: #ff9a9a; font-size: 13px; white-space: pre-wrap; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #15181b;
  border-right: 1px solid var(--line-soft);
  z-index: 30;
  transition: width .18s ease, transform .18s ease;
}

.sidebar-head { height: 64px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--line-soft); }
.sidebar-title { min-width: 0; white-space: nowrap; overflow: hidden; }
.sidebar-head .icon-button { margin-left: auto; }

.nav-list { padding: 13px 10px; display: grid; align-content: start; gap: 5px; }
.nav-item {
  width: 100%;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 11px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--green-soft); border-color: #285c45; color: #a4f0c9; }
.nav-symbol { width: 20px; flex: 0 0 20px; text-align: center; font-size: 17px; }

.sidebar-user { min-height: 68px; display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-top: 1px solid var(--line-soft); }
.avatar { width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; border-radius: 50%; background: var(--cyan-soft); color: #a6e9f3; font-weight: 800; }
.sidebar-user-copy { min-width: 0; display: grid; }
.sidebar-user-copy strong, .sidebar-user-copy span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-copy span { color: var(--muted); font-size: 12px; }
.sidebar-user .icon-button { margin-left: auto; }

.app-shell.sidebar-collapsed { --sidebar: 68px; }
.sidebar-collapsed .sidebar-title,
.sidebar-collapsed .nav-item span:last-child,
.sidebar-collapsed .sidebar-user-copy { display: none; }
.sidebar-collapsed .sidebar-head { justify-content: center; padding-inline: 8px; }
.sidebar-collapsed .sidebar-head .icon-button { position: absolute; left: 49px; width: 24px; background: var(--surface-2); border: 1px solid var(--line); }
.sidebar-collapsed .nav-item { justify-content: center; padding-inline: 0; }
.sidebar-collapsed .sidebar-user { justify-content: center; padding-inline: 6px; }
.sidebar-collapsed .sidebar-user .icon-button { display: none; }

.workspace { min-width: 0; }
.topbar { min-height: 64px; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 10px 22px; background: rgba(17, 19, 21, .96); border-bottom: 1px solid var(--line-soft); backdrop-filter: blur(10px); }
.topbar h2 { margin: 0; font-size: 18px; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }
.mobile-menu { display: none; }

.quota-pill { min-height: 32px; display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 6px; background: var(--amber-soft); border: 1px solid #665329; color: #f3d58f; font-size: 12px; white-space: nowrap; }

.content { width: min(100%, 1780px); margin: 0 auto; padding: 20px 22px 40px; }
.view { display: none; }
.view.active { display: block; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.metric { min-height: 86px; padding: 14px 15px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); display: grid; align-content: space-between; }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { font-size: 23px; font-variant-numeric: tabular-nums; }
.metric-good strong { color: var(--green); }
.metric-bad strong { color: var(--red); }
.metric-money strong { color: var(--amber); }

.toolbar { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; padding: 13px; margin-bottom: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.toolbar label { min-width: 138px; }
.toolbar .grow { flex: 1 1 260px; }
.toolbar .align-end { align-self: end; }

.segmented-scroll { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: thin; }
.segment { min-height: 34px; flex: 0 0 auto; padding: 5px 10px; background: transparent; border-color: var(--line); color: var(--muted); }
.segment:hover { color: var(--text); background: var(--surface-2); }
.segment.active { color: #b5f4d3; background: var(--green-soft); border-color: #32694f; }
.segment.issue.active { color: #ffb0b0; background: var(--red-soft); border-color: #754048; }

.data-surface, .form-surface, .job-surface, .quota-band {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 2; background: #1c2024; color: var(--muted); font-size: 11px; font-weight: 650; text-transform: none; }
tbody tr:hover { background: rgba(255, 255, 255, .018); }
tbody tr:last-child td { border-bottom: 0; }
td.numeric { text-align: right; }
.account-main { max-width: 280px; display: grid; }
.account-main strong, .account-main span { overflow: hidden; text-overflow: ellipsis; }
.account-main span { color: var(--muted); font-size: 11px; }
.cost { color: #f1cc7c; font-weight: 700; }
.muted { color: var(--muted); }
.issue-text { max-width: 360px; overflow: hidden; text-overflow: ellipsis; color: #ffaaaa; font-size: 11px; }
.link-button { min-height: 30px; padding: 4px 8px; background: transparent; border-color: var(--line); color: #a9e9f2; }
.link-button:hover { background: var(--cyan-soft); }

.status-badge { min-height: 24px; display: inline-flex; align-items: center; padding: 2px 7px; border: 1px solid var(--line); border-radius: 5px; font-size: 11px; white-space: nowrap; }
.status-healthy { color: #9ce8c1; background: var(--green-soft); border-color: #2d6049; }
.status-temporary, .status-rate_limited { color: #f0d18a; background: var(--amber-soft); border-color: #67552e; }
.status-unauthorized, .status-forbidden, .status-error, .status-deleted { color: #ffabab; background: var(--red-soft); border-color: #714048; }

.pagination { min-height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-top: 1px solid var(--line-soft); color: var(--muted); }
.pagination div { display: flex; gap: 7px; }
.empty-state { padding: 44px 20px; text-align: center; color: var(--muted); }
.loading-line { height: 3px; overflow: hidden; background: var(--surface-3); }
.loading-line::after { content: ""; display: block; width: 33%; height: 100%; background: var(--green); animation: loading 1s ease-in-out infinite alternate; }
@keyframes loading { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.quota-band { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 12px; overflow: hidden; }
.quota-band > div { min-height: 76px; padding: 13px 16px; display: grid; border-right: 1px solid var(--line-soft); }
.quota-band > div:last-child { border-right: 0; }
.quota-band span { color: var(--muted); font-size: 12px; }
.quota-band strong { align-self: end; font-size: 22px; }

.form-surface { padding: 16px; margin-bottom: 18px; }
.form-row { display: grid; grid-template-columns: minmax(220px, 420px); margin-bottom: 13px; }
.bulk-input-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); gap: 12px; }
.form-actions { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; color: var(--muted); }

.job-surface { padding: 15px; margin-bottom: 18px; }
.job-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.job-head > div { min-width: 0; display: flex; align-items: center; gap: 9px; }
.job-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-head > span { color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-track { height: 8px; border-radius: 4px; background: #0f1113; overflow: hidden; border: 1px solid var(--line-soft); }
.progress-bar { width: 0; height: 100%; background: var(--green); transition: width .25s ease; }
.danger-progress { background: var(--red); }
.job-events, .job-results { display: grid; gap: 6px; margin-top: 12px; max-height: 280px; overflow: auto; }
.event-row, .result-row, .job-row { padding: 9px 10px; border: 1px solid var(--line-soft); border-radius: 5px; background: #14171a; }
.event-row { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 9px; }
.event-row span:first-child { color: var(--muted); }
.result-row { display: flex; align-items: start; gap: 9px; }
.result-row .result-copy { min-width: 0; display: grid; }
.result-copy span { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.job-list { display: grid; gap: 8px; }
.job-row { display: grid; grid-template-columns: minmax(180px, 1fr) 120px 140px auto; align-items: center; gap: 12px; }
.job-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-row span { color: var(--muted); font-size: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 10px; }
.section-head h3 { margin: 0; font-size: 15px; }

.inline-form { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) 150px auto; align-items: end; gap: 10px; }
.inline-form .form-error { grid-column: 1 / -1; margin: 0; }
.users-table input { min-width: 90px; min-height: 34px; padding: 6px 8px; }
.users-table .password-input { min-width: 130px; }

.mobile-cards { display: none; }
.account-card, .user-card { border-bottom: 1px solid var(--line-soft); padding: 13px; }
.card-head { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.card-head strong { overflow-wrap: anywhere; }
.card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 12px; margin-top: 11px; }
.card-field { display: grid; gap: 2px; min-width: 0; }
.card-field span:first-child { color: var(--muted); font-size: 11px; }
.card-field span:last-child { overflow: hidden; text-overflow: ellipsis; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.desktop-table .card-actions { margin-top: 0; flex-wrap: nowrap; }

.detail-dialog { width: min(980px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; overflow: auto; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 30px 100px rgba(0, 0, 0, .55); }
.detail-dialog::backdrop { background: rgba(0, 0, 0, .72); }
.dialog-head { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; background: #191c1f; border-bottom: 1px solid var(--line); }
.dialog-head > div { min-width: 0; display: flex; align-items: center; gap: 10px; }
.dialog-head h3 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.detail-dialog > h4 { margin: 18px 16px 8px; font-size: 13px; }
.detail-facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.detail-fact { min-height: 70px; display: grid; align-content: center; gap: 4px; padding: 11px 13px; background: var(--surface); }
.detail-fact span { color: var(--muted); font-size: 11px; }
.detail-fact strong { overflow-wrap: anywhere; }
.owner-edit { display: flex; align-items: end; gap: 9px; padding: 14px 16px 0; }
.owner-edit label { width: min(100%, 320px); }
.dialog-actions { display: flex; justify-content: flex-end; padding: 14px 16px 0; }
.detail-table { margin: 0 16px 16px; width: auto; border: 1px solid var(--line-soft); border-radius: 5px; }

.stats-metrics { grid-template-columns: repeat(3, minmax(150px, 1fr)); }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 100; max-width: min(420px, calc(100vw - 36px)); padding: 11px 13px; border-radius: 6px; background: #26302c; border: 1px solid #436052; color: #c8f1dc; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red-soft); border-color: #76444a; color: #ffc1c1; }

@media (max-width: 1050px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .inline-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inline-form button { align-self: end; }
  .detail-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 780px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; width: min(84vw, 280px); transform: translateX(-105%); box-shadow: 16px 0 50px rgba(0, 0, 0, .45); }
  .app-shell.menu-open .sidebar { transform: translateX(0); }
  .sidebar-collapsed .sidebar-title,
  .sidebar-collapsed .nav-item span:last-child,
  .sidebar-collapsed .sidebar-user-copy { display: initial; }
  .sidebar-collapsed .sidebar-head { justify-content: flex-start; padding: 0 14px; }
  .sidebar-collapsed .sidebar-head .icon-button { position: static; width: 34px; margin-left: auto; background: transparent; border: 0; }
  .sidebar-collapsed .nav-item { justify-content: flex-start; padding: 8px 13px; }
  .sidebar-collapsed .sidebar-user { justify-content: flex-start; padding: 11px 12px; }
  .sidebar-collapsed .sidebar-user .icon-button { display: grid; }
  .mobile-menu { display: grid; }
  .topbar { padding-inline: 12px; }
  .topbar-actions .secondary { display: none; }
  .content { padding: 14px 12px 30px; }
  .desktop-table { display: none; }
  .mobile-cards { display: block; }
  .toolbar { align-items: stretch; }
  .toolbar label, .toolbar .grow { flex: 1 1 calc(50% - 8px); min-width: 140px; }
  .quota-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quota-band > div { padding: 11px; }
  .quota-band > div:nth-child(2n) { border-right: 0; }
  .quota-band > div:nth-child(-n + 2) { border-bottom: 1px solid var(--line-soft); }
  .bulk-input-grid { grid-template-columns: 1fr; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .form-actions button { width: 100%; }
  .job-row { grid-template-columns: 1fr auto; }
  .job-row > span:nth-child(3) { display: none; }
  .inline-form { grid-template-columns: 1fr; }
  .detail-dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
}

@media (max-width: 520px) {
  .login-shell { padding: 12px; }
  .login-panel { padding: 22px 18px; }
  .topbar h2 { font-size: 16px; }
  .topbar p { display: none; }
  .quota-pill { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  .metrics-grid, .stats-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 76px; padding: 12px; }
  .metric strong { font-size: 19px; }
  .toolbar label, .toolbar .grow { flex-basis: 100%; }
  .quota-band { grid-template-columns: 1fr; }
  .quota-band > div { min-height: 58px; grid-template-columns: 1fr auto; align-items: center; border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .quota-band > div:last-child { border-bottom: 0; }
  .quota-band strong { align-self: center; }
  .card-grid { grid-template-columns: 1fr; }
  .detail-facts { grid-template-columns: 1fr; }
  .owner-edit { align-items: stretch; flex-direction: column; }
  .owner-edit label, .owner-edit button { width: 100%; }
}
