:root {
  color-scheme: light dark;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #eef2ee;
  --text: #17201a;
  --muted: #657169;
  --border: #d9dfda;
  --accent: #176f5d;
  --accent-2: #f1b84b;
  --danger: #b42335;
  --warn: #a65f00;
  --ok: #16835d;
  --shadow: 0 14px 40px rgba(19, 30, 26, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #151d1a;
    --surface-2: #1c2622;
    --text: #eef5ef;
    --muted: #a6b1aa;
    --border: #2c3934;
    --shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input { font: inherit; }
button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 700;
}
button.ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
button.danger { color: var(--danger); }

.hidden { display: none !important; }
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 900;
  margin-bottom: 18px;
}
h1, h2, p { margin: 0; }
.login-panel h1 { font-size: 28px; }
.login-panel p { color: var(--muted); margin: 6px 0 24px; }
label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 14px;
}
input {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}
.form-error { display: block; min-height: 20px; color: var(--danger); margin-top: 12px; }

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.eyebrow {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  font-weight: 800;
}
.topbar h1 { font-size: 32px; }
.top-actions, .inline-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 18px;
}
.tabs button {
  background: transparent;
  color: var(--muted);
}
.tabs button.active {
  background: var(--accent);
  color: white;
}
.tab-page { display: none; }
.tab-page.active { display: grid; gap: 18px; }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.metric, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric { padding: 18px; }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; font-size: 26px; margin-top: 8px; }
.panel { padding: 18px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.panel h2 { font-size: 20px; }
.alert-list { display: grid; gap: 10px; }
.alert {
  border: 1px solid var(--border);
  border-left: 4px solid var(--warn);
  background: var(--surface);
  border-radius: 8px;
  padding: 14px;
}
.alert.critical { border-left-color: var(--danger); }
.alert.ok { border-left-color: var(--ok); }
.bar-row { margin: 14px 0; }
.bar-head { display: flex; justify-content: space-between; color: var(--muted); margin-bottom: 8px; gap: 12px; }
.bar {
  height: 12px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.table-wrap { overflow-x: auto; }
.mobile-list { display: none; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
th, td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { color: var(--muted); font-size: 13px; }
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ok) 12%, transparent);
  color: var(--ok);
  font-weight: 800;
  white-space: nowrap;
}
.status-pill.bad {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}
.backup-app {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 14px;
}
.backup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.backup-file {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.backup-file small { color: var(--muted); display: block; margin-top: 4px; }
.file-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.file-actions button, .file-actions a {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
}
.file-actions .delete, .file-actions .restore { color: var(--danger); }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.settings-grid .panel-head, .settings-grid button { grid-column: 1 / -1; }
.settings-grid label {
  margin: 0;
}
pre {
  overflow: auto;
  margin: 0;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 8px;
  color: var(--muted);
}

@media (max-width: 760px) {
  body {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
  }
  button {
    min-height: 44px;
    padding: 0 13px;
    font-size: 15px;
  }
  input {
    min-height: 46px;
    width: 100%;
    font-size: 16px;
  }
  label {
    font-size: 13px;
    gap: 7px;
  }
  .login-view {
    align-items: start;
    padding: 18px;
    padding-top: max(28px, env(safe-area-inset-top));
  }
  .login-panel {
    padding: 22px;
    margin-top: 18px;
  }
  .shell {
    width: 100%;
    padding: 14px;
    padding-top: max(14px, env(safe-area-inset-top));
    padding-bottom: calc(94px + env(safe-area-inset-bottom));
  }
  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 12px;
    margin-bottom: 14px;
  }
  .topbar h1 {
    font-size: 25px;
    line-height: 1.12;
  }
  .top-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }
  .top-actions button {
    min-height: 40px;
    padding: 0 8px;
    font-size: 13px;
    white-space: nowrap;
  }
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .metric {
    min-height: 112px;
    padding: 14px;
  }
  .metric strong {
    font-size: 23px;
    line-height: 1.12;
  }
  .metric span {
    font-size: 12px;
    line-height: 1.35;
  }
  .panel {
    padding: 14px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(19, 30, 26, 0.08);
  }
  .panel-head {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    align-items: start;
    margin-bottom: 13px;
  }
  .panel-head h2 {
    font-size: 19px;
    line-height: 1.2;
  }
  .panel-head > span {
    color: var(--muted);
    font-size: 13px;
  }
  .inline-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
  }
  .inline-actions button,
  #pruneButton {
    width: 100%;
  }
  .alert {
    padding: 12px;
    font-size: 14px;
  }
  .alert p {
    margin-top: 4px;
    line-height: 1.35;
  }
  .bar-row {
    margin: 12px 0;
  }
  .bar-head {
    align-items: flex-start;
    gap: 8px;
    font-size: 14px;
    line-height: 1.25;
  }
  .bar-head span {
    white-space: nowrap;
  }
  .bar {
    height: 10px;
  }
  .app-storage-card {
    padding: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  .app-storage-card > .bar-row {
    margin: 10px 0 0;
  }
  .table-wrap {
    display: none;
  }
  .mobile-list {
    display: grid;
    gap: 10px;
  }
  .mobile-card {
    padding: 13px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  .mobile-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
  }
  .mobile-card-head strong {
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 16px;
  }
  .mobile-facts {
    display: grid;
    gap: 8px;
    margin: 0;
  }
  .mobile-facts div {
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
  }
  .mobile-facts dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }
  .mobile-facts dd {
    margin: 0;
    min-width: 0;
    color: var(--text);
    font-size: 13px;
    line-height: 1.35;
    overflow-wrap: anywhere;
  }
  .status-pill {
    min-height: 26px;
    padding: 0 9px;
    font-size: 12px;
  }
  .backup-head {
    align-items: flex-start;
  }
  .backup-head h3 {
    margin: 0;
    font-size: 17px;
    overflow-wrap: anywhere;
  }
  .backup-head span {
    color: var(--muted);
    white-space: nowrap;
  }
  .backup-file {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 0;
  }
  .backup-file strong {
    display: block;
    font-size: 14px;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }
  .backup-file small {
    font-size: 12px;
    line-height: 1.35;
  }
  .file-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    justify-content: stretch;
  }
  .file-actions button,
  .file-actions a {
    justify-content: center;
    min-height: 38px;
    padding: 0 8px;
    font-size: 13px;
    text-align: center;
  }
  .settings-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .settings-grid label {
    display: grid;
    grid-template-columns: 1fr;
    margin: 0;
  }
  .settings-grid label:has(input[type="checkbox"]) {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 46px;
    padding: 0 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  input[type="checkbox"] {
    width: 22px;
    height: 22px;
    min-height: 22px;
    justify-self: end;
    accent-color: var(--accent);
  }
  .settings-grid button {
    width: 100%;
  }
  pre {
    max-height: 260px;
    padding: 12px;
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
  .tabs {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    top: auto;
    margin: 0;
    box-shadow: var(--shadow);
    gap: 4px;
    padding: 6px;
    border-radius: 8px;
  }
  .tabs button {
    min-height: 48px;
    padding: 0 4px;
    font-size: 13px;
    border-radius: 7px;
  }
}

@media (max-width: 380px) {
  .shell {
    padding-left: 10px;
    padding-right: 10px;
  }
  .top-actions,
  .file-actions {
    grid-template-columns: 1fr;
  }
  .metric-grid {
    grid-template-columns: 1fr;
  }
  .mobile-facts div {
    grid-template-columns: 68px minmax(0, 1fr);
  }
}
