:root {
  color-scheme: light;
  --bg: #f6f8f5;
  --surface: #ffffff;
  --surface-soft: #eef4ed;
  --ink: #18201c;
  --muted: #59665e;
  --line: #dbe4dc;
  --accent: #f6c944;
  --accent-strong: #b87b00;
  --green: #2e7d59;
  --danger: #b42318;
  --danger-bg: #ffe7e3;
  --shadow: 0 8px 22px rgba(24, 32, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

a {
  color: inherit;
  text-decoration: none;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 850;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: #141414;
  background: var(--accent);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}

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

.side-nav a {
  min-height: 38px;
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.side-nav a:hover,
.side-nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--surface-soft);
}

.workspace {
  position: relative;
  padding: 28px clamp(20px, 4vw, 46px) 42px;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.page-kicker {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 13px;
  font-weight: 850;
}

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

h1 {
  margin-bottom: 0;
  font-size: 32px;
  line-height: 1.15;
  text-wrap: balance;
}

h2 {
  margin-bottom: 6px;
  font-size: 18px;
  line-height: 1.25;
}

.account-box {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 5px 5px 5px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.login-panel,
.panel {
  max-width: 980px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel {
  display: grid;
  grid-template-columns: minmax(240px, 0.75fr) minmax(320px, 1fr);
  gap: 24px;
  padding: 24px;
}

.login-copy p,
.panel-head p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.api-status {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  margin-top: 18px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 13px;
  font-weight: 800;
}

.api-status.ready {
  border-color: #b8ddc5;
  color: #1f6847;
  background: #ecf8ef;
}

.api-status.warn {
  border-color: #f3d68a;
  color: #7a5400;
  background: #fff8df;
}

.api-status.error {
  border-color: #f2b8b2;
  color: var(--danger);
  background: var(--danger-bg);
}

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

.key-form {
  grid-template-columns: minmax(220px, 1fr) 120px auto;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid #cbd8cd;
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
}

input::placeholder {
  color: #657267;
}

input:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(246, 201, 68, 0.45);
  outline-offset: 2px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 7px;
  font-weight: 850;
}

.primary-button {
  border: 1px solid #d8a900;
  color: #151515;
  background: var(--accent);
}

.secondary-button,
.ghost-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--surface);
}

.danger-button {
  border: 1px solid #f2b8b2;
  color: var(--danger);
  background: var(--danger-bg);
}

.notice {
  grid-column: 1 / -1;
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.dashboard {
  display: grid;
  gap: 18px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-width: 980px;
}

.summary-strip div {
  min-height: 92px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.summary-strip span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.summary-strip strong {
  font-size: 28px;
  line-height: 1;
}

.panel {
  padding: 20px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.key-reveal {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #d7c15d;
  border-radius: 8px;
  background: #fff8d7;
}

.key-reveal span {
  display: block;
  margin-bottom: 6px;
  color: #604600;
  font-size: 12px;
  font-weight: 850;
}

code {
  display: block;
  overflow-wrap: anywhere;
  color: #20242d;
  font: 750 13px/1.55 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

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

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 12px 10px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

thead th {
  border-top: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  color: #0c5133;
  background: #dff3e8;
  font-size: 12px;
  font-weight: 900;
}

.status-pill.revoked {
  color: #7a271a;
  background: #ffe7e3;
}

.device-list {
  display: grid;
  gap: 10px;
}

.device-item,
.empty-state {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.device-item strong {
  display: block;
  margin-bottom: 4px;
}

.device-item span,
.empty-state {
  color: var(--muted);
  font-size: 14px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  min-width: 220px;
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

[hidden] {
  display: none !important;
}

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

  .sidebar {
    position: static;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    height: auto;
  }

  .side-nav {
    display: flex;
    flex-wrap: wrap;
  }

  .login-panel,
  .key-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 20px 14px 32px;
  }

  .app-topbar,
  .panel-head,
  .device-item,
  .key-reveal {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .account-box {
    width: 100%;
    justify-content: space-between;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}
