/* Scales and roles follow the Refactoring UI starter tokens: decide once, reuse everywhere. */
:root {
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 64px;

  --text-xs: 12px; --text-sm: 14px; --text-base: 16px; --text-lg: 18px;
  --text-xl: 20px; --text-2xl: 24px; --text-3xl: 30px;
  --weight-normal: 400; --weight-bold: 600;

  --grey-100: hsl(210, 36%, 96%);
  --grey-200: hsl(212, 33%, 89%);
  --grey-300: hsl(211, 27%, 84%);
  --grey-400: hsl(209, 23%, 60%);
  --grey-500: hsl(210, 22%, 49%);
  --grey-600: hsl(209, 28%, 39%);
  --grey-700: hsl(209, 34%, 30%);
  --grey-800: hsl(211, 39%, 23%);
  --grey-900: hsl(209, 61%, 16%);

  --primary-100: hsl(205, 92%, 92%);
  --primary-200: hsl(205, 97%, 85%);
  --primary-300: hsl(205, 90%, 76%);
  --primary-400: hsl(206, 82%, 58%);
  --primary-500: hsl(208, 88%, 38%);
  --primary-600: hsl(209, 88%, 33%);
  --primary-900: hsl(215, 88%, 18%);

  --red-100: hsl(360, 100%, 95%);
  --red-500: hsl(360, 67%, 44%);
  --red-800: hsl(360, 85%, 25%);
  --yellow-100: hsl(49, 100%, 92%);
  --yellow-800: hsl(38, 100%, 19%);
  --green-100: hsl(152, 68%, 92%);
  --green-800: hsl(156, 100%, 13%);

  --shadow-1: 0 1px 3px hsla(0, 0%, 0%, .2);
  --shadow-4: 0 10px 24px hsla(0, 0%, 0%, .2);
  --radius: 8px;
  --radius-full: 9999px;

  --surface: var(--grey-100);
  --surface-raised: #fff;
  --border: var(--grey-200);
  --border-strong: var(--grey-500);
  --text-primary: var(--grey-900);
  --text-secondary: var(--grey-700);
  --text-tertiary: var(--grey-600);
  --action: var(--primary-500);
  --action-hover: var(--primary-600);
  --action-text: #fff;
  --link: var(--primary-500);
  --danger-text: var(--red-500);
  --focus: var(--primary-400);

  --ok-bg: var(--green-100);   --ok-text: var(--green-800);
  --warn-bg: var(--yellow-100); --warn-text: var(--yellow-800);
  --bad-bg: var(--red-100);    --bad-text: var(--red-800);
  --idle-bg: var(--grey-200);  --idle-text: var(--grey-800);
  --info-bg: var(--primary-100); --info-text: var(--primary-900);

  --console-bg: hsl(209, 61%, 12%);
  --console-text: var(--grey-200);
  --console-warn: hsl(45, 95%, 65%);
  --console-err: hsl(0, 90%, 75%);
  --console-cmd: var(--primary-300);

  --toast-bg: var(--grey-900);
  --toast-text: #fff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: var(--grey-900);
    --surface-raised: var(--grey-800);
    --border: var(--grey-700);
    --border-strong: var(--grey-400);
    --text-primary: var(--grey-200);
    --text-secondary: var(--grey-300);
    --text-tertiary: hsl(209, 23%, 66%);
    --action: var(--primary-400);
    --action-hover: var(--primary-300);
    --action-text: var(--grey-900);
    --link: var(--primary-300);
    --danger-text: hsl(0, 85%, 72%);

    --ok-bg: hsl(154, 70%, 16%);  --ok-text: hsl(152, 68%, 82%);
    --warn-bg: hsl(42, 80%, 16%); --warn-text: hsl(49, 100%, 80%);
    --bad-bg: hsl(0, 60%, 22%);   --bad-text: hsl(0, 100%, 88%);
    --idle-bg: var(--grey-700);   --idle-text: var(--grey-100);
    --info-bg: hsl(209, 70%, 24%); --info-text: var(--primary-200);

    --toast-bg: var(--grey-200);
    --toast-text: var(--grey-900);
    --shadow-1: 0 1px 3px hsla(0, 0%, 0%, .4);
    --shadow-4: 0 10px 24px hsla(0, 0%, 0%, .5);
  }
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--surface);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2 { margin: 0; line-height: 1.25; font-weight: var(--weight-bold); }
h2 { font-size: var(--text-lg); }

.wrap { max-width: 1024px; margin: 0 auto; padding: 0 var(--space-4); }

/* top bar */
.topbar { background: var(--surface-raised); border-bottom: 1px solid var(--border); }
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding-top: var(--space-3); padding-bottom: var(--space-3);
}
.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand img { border-radius: var(--radius); flex: none; }
.brand-title { font-weight: var(--weight-bold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: var(--text-sm); color: var(--text-tertiary); }

main.wrap {
  display: grid; gap: var(--space-4);
  padding-top: var(--space-5); padding-bottom: var(--space-7);
}

.card {
  background: var(--surface-raised);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: var(--space-5);
}
@media (prefers-color-scheme: dark) { .card { border: 1px solid var(--border); } }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  margin-bottom: var(--space-4);
}

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: var(--text-sm); font-weight: var(--weight-bold); line-height: 1.5;
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent; border-radius: var(--radius);
  background: none; color: inherit; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--action); color: var(--action-text); box-shadow: var(--shadow-1); }
.btn-primary:hover:not(:disabled) { background: var(--action-hover); }
.btn-primary:active:not(:disabled) { box-shadow: none; }
.btn-secondary { background: var(--surface-raised); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface); }
.btn-link { color: var(--link); padding-left: var(--space-2); padding-right: var(--space-2); }
.btn-link:hover:not(:disabled) { text-decoration: underline; }
.btn-danger { color: var(--danger-text); padding-left: var(--space-3); padding-right: var(--space-3); }
.btn-danger:hover:not(:disabled) { text-decoration: underline; }

/* status hero */
.hero { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-4); }
.hero-status { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-3); }
.pill {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-full);
  font-size: var(--text-sm); font-weight: var(--weight-bold);
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--ok-bg); color: var(--ok-text); }
.pill-warn { background: var(--warn-bg); color: var(--warn-text); }
.pill-bad { background: var(--bad-bg); color: var(--bad-text); }
.pill-idle { background: var(--idle-bg); color: var(--idle-text); }
.pill-info { background: var(--info-bg); color: var(--info-text); }
.pill .pause-icon { width: 8px; height: 8px; border-left: 3px solid currentColor; border-right: 3px solid currentColor; }
.pill-warn .dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.muted { color: var(--text-tertiary); font-size: var(--text-sm); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-4); }
.stat-value { font-size: var(--text-3xl); font-weight: var(--weight-bold); line-height: 1.25; font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--text-sm); color: var(--text-secondary); }
.stat-extra { font-size: var(--text-sm); color: var(--text-tertiary); margin-top: var(--space-2); overflow-wrap: anywhere; }

/* console */
.toggle { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-secondary); cursor: pointer; }
.console {
  height: 384px; overflow: auto;
  padding: var(--space-3);
  background: var(--console-bg); color: var(--console-text);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--text-xs); line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.console .l-warn { color: var(--console-warn); }
.console .l-err { color: var(--console-err); }
.console .l-cmd { color: var(--console-cmd); font-weight: var(--weight-bold); }
.console-input { display: flex; gap: var(--space-2); margin-top: var(--space-3); }
.console-input input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* forms */
input[type="text"], input[type="password"], input:not([type]) {
  font: inherit; font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface-raised); color: var(--text-primary);
}
input::placeholder { color: var(--text-tertiary); }
input:disabled { opacity: .4; }

/* backups */
.hint { margin: 0 0 var(--space-3); max-width: 34em; font-size: var(--text-sm); color: var(--text-secondary); }
.backups { list-style: none; margin: 0; padding: 0; }
.backups li { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-2) 0; border-top: 1px solid var(--border); }
.backups .b-date { flex: 1; font-variant-numeric: tabular-nums; }
.backups .b-size { font-size: var(--text-sm); color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.backups .empty { padding: var(--space-3) 0; font-size: var(--text-sm); color: var(--text-tertiary); }

.toast {
  position: fixed; left: 50%; bottom: var(--space-5); transform: translateX(-50%);
  max-width: calc(100% - var(--space-6));
  padding: var(--space-3) var(--space-5);
  background: var(--toast-bg); color: var(--toast-text);
  border-radius: var(--radius); box-shadow: var(--shadow-4);
  font-size: var(--text-sm);
}
.toast-error { background: var(--red-500); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: var(--space-4); }
.login-card { width: 100%; max-width: 384px; padding: var(--space-6); }
.login-card img { display: block; border-radius: var(--radius); margin-bottom: var(--space-4); }
.login-card h1 { font-size: var(--text-xl); }
.login-card .sub { margin: var(--space-1) 0 var(--space-5); font-size: var(--text-sm); color: var(--text-secondary); }
.field { display: grid; gap: var(--space-1); margin-bottom: var(--space-4); }
.field label { font-size: var(--text-sm); font-weight: var(--weight-bold); color: var(--text-secondary); }
.field input { font-size: var(--text-base); }
.login-card .btn-primary { width: 100%; margin-top: var(--space-2); padding: var(--space-3); font-size: var(--text-base); }
.error { margin-bottom: var(--space-4); padding: var(--space-3); border-radius: var(--radius); background: var(--bad-bg); color: var(--bad-text); font-size: var(--text-sm); }

@media (max-width: 768px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .card { padding: var(--space-4); }
  .login-card { padding: var(--space-5); }
  .stat-value { font-size: var(--text-2xl); }
  .console { height: 320px; }
  .hero .actions { width: 100%; }
  .console-input input { font-size: var(--text-base); } /* 16px keeps iOS from zooming on focus */
}
