/* ─────────────────────────────────────────────────────────────
   apple-developer — sidebar app shell.
   Mobile-first: the sidebar is an off-canvas drawer below 900px,
   driven by a checkbox so the app stays JavaScript-free.
   ───────────────────────────────────────────────────────────── */

:root {
  --bg:        #f6f6f4;
  --surface:   #ffffff;
  --surface-2: #f0efec;
  --fg:        #191817;
  --fg-soft:   #55534f;
  --muted:     #8b8983;
  --line:      #e5e4e0;
  --line-soft: #eeedea;

  --accent:    #2f6f4e;
  --accent-fg: #ffffff;
  --danger:    #a8342c;
  --warn:      #8a6d1f;

  --sidebar-w: 244px;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgb(24 22 20 / .05);
  --shadow:    0 1px 3px rgb(24 22 20 / .06), 0 6px 20px rgb(24 22 20 / .04);
  --shadow-lg: 0 10px 40px rgb(24 22 20 / .16);
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #131312;
    --surface:   #1c1c1a;
    --surface-2: #242422;
    --fg:        #edebe7;
    --fg-soft:   #bdbab4;
    --muted:     #918e88;
    --line:      #2f2e2b;
    --line-soft: #262523;

    --accent:    #7cbe98;
    --accent-fg: #0e2519;
    --danger:    #e78d84;
    --warn:      #d9b45f;

    --shadow-sm: none;
    --shadow:    0 1px 3px rgb(0 0 0 / .4);
    --shadow-lg: 0 10px 40px rgb(0 0 0 / .55);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { letter-spacing: -.011em; }
h1 { font-size: 1.35rem; line-height: 1.25; margin: 0 0 4px; }
h2 { font-size: 1rem; margin: 0 0 12px; }
h3 { font-size: .98rem; margin: 0 0 4px; }
p  { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ── shell ───────────────────────────────────────────────── */

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }

.shell { min-height: 100dvh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  z-index: 40;
  transform: translateX(-100%);
  transition: transform .22s ease;
}
.nav-toggle:checked ~ .shell .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }

.scrim {
  position: fixed;
  inset: 0;
  background: rgb(10 9 8 / .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
  z-index: 30;
}
.nav-toggle:checked ~ .shell .scrim { opacity: 1; pointer-events: auto; }

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 14px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--fg);
  font-weight: 640;
  font-size: .95rem;
  letter-spacing: -.015em;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); font-size: 1rem; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: var(--tap);
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--fg-soft);
  font-size: .92rem;
  font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--fg); text-decoration: none; }
.nav-item.active { background: var(--surface-2); color: var(--fg); font-weight: 600; }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { color: var(--muted); }

.sidebar-foot { border-top: 1px solid var(--line-soft); padding-top: 12px; margin-top: 12px; }
.me { display: flex; align-items: center; gap: 10px; padding: 2px 8px 12px; }
.avatar {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 650; font-size: .82rem;
}
.me-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.me-text b { font-size: .88rem; overflow: hidden; text-overflow: ellipsis; }

/* ── topbar (mobile only) ────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 600; font-size: .95rem; letter-spacing: -.01em; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap); height: var(--tap);
  margin: -6px;
  border-radius: var(--radius-sm);
  color: var(--fg-soft);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }

.content main { padding: 20px 16px 72px; }

@media (min-width: 900px) {
  .sidebar { transform: none; box-shadow: none; }
  /* permanent sidebar on desktop: nothing to close, nothing to open */
  .scrim, .topbar, .nav-close { display: none; }
  .content { margin-left: var(--sidebar-w); }
  /* scoped to .content so it never applies to the centred auth page */
  .content main { padding: 32px 32px 80px; max-width: 1080px; }
}

/* ── auth screen ─────────────────────────────────────────── */

body.plain { min-height: 100dvh; }

main.auth {
  /* Centres in the viewport but still grows and scrolls when the card is
     taller than the screen (login with an error, short landscape phones). */
  width: 100%;
  max-width: none;
  margin: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(1100px 520px at 50% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.auth-title {
  font-size: 1.15rem;
  text-align: center;
  margin: 0 0 22px;
}

/* ── surfaces ────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 14px;
}
@media (min-width: 700px) { .card { padding: 20px; } }

.card-head {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  align-items: baseline; justify-content: space-between;
  margin-bottom: 12px;
}
.card-head h2, .card-head h3 { margin: 0; }

.grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); } }

.page-sub { color: var(--muted); font-size: .9rem; margin: 0 0 20px; }
.section-title { margin: 26px 0 12px; }

/* ── rows ────────────────────────────────────────────────── */

.row { display: flex; flex-direction: column; gap: 12px; }
.row.gap { gap: 14px; }
.row.top { margin-top: 14px; }
.grow { flex: 1 1 260px; min-width: 0; }
.right { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; }
.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

@media (min-width: 640px) {
  .row { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
  .row.between { justify-content: space-between; align-items: flex-start; }
  .row.top { align-items: center; }
  .right { justify-content: flex-end; }
}

/* ── forms ───────────────────────────────────────────────── */

label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: .78rem; font-weight: 600; letter-spacing: .015em;
  color: var(--muted); text-transform: uppercase;
}
label.check {
  flex-direction: row; align-items: center; gap: 11px;
  min-height: var(--tap); padding: 2px 0;
  font-size: .93rem; font-weight: 400; letter-spacing: 0;
  text-transform: none; color: var(--fg); cursor: pointer;
}
label.plain { text-transform: none; font-size: .88rem; }

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  /* 16px stops iOS Safari zooming the viewport on focus */
  font-size: 16px;
}
input:hover, select:hover { border-color: var(--muted); }
input::placeholder { color: var(--muted); }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; flex: none; accent-color: var(--accent); }
input[type=file] { padding: 9px 12px; background: var(--surface-2); }
select { appearance: none; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack > button { margin-top: 4px; }

@media (min-width: 640px) {
  .row > label input:not([type=checkbox]), .row > label select { min-width: 190px; }
}

/* ── buttons ─────────────────────────────────────────────── */

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit; font-weight: 600; font-size: .92rem;
  cursor: pointer; white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(1.07); text-decoration: none; }
button:active, .button:active { transform: translateY(1px); }

.btn-secondary, button.secondary {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--line);
}
.btn-secondary:hover, button.secondary:hover { background: var(--surface-2); filter: none; }

.btn-ghost {
  background: none; border: none; color: var(--fg-soft);
  justify-content: flex-start; width: 100%;
  padding: 0 10px; font-weight: 500; font-size: .92rem;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); filter: none; }
.full { width: 100%; }

button.link {
  background: none; border: none; color: var(--accent);
  padding: 10px 2px; font-weight: 500; min-height: var(--tap);
}
button.link.danger { color: var(--danger); }

.button.big { width: 100%; min-height: 52px; font-size: 1rem; border-radius: var(--radius); }
@media (min-width: 560px) { .auth-card .button.big { width: 100%; } }

form.inline button, form.inline input, form.inline select { width: auto; }

/* ── tables → stacked cards on phones ────────────────────── */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700; background: var(--surface-2);
}
tr:last-child td { border-bottom: none; }

@media (max-width: 719px) {
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  table { border: none; background: none; box-shadow: none; border-radius: 0; }
  tr {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    padding: 4px 14px; margin-bottom: 12px;
  }
  td {
    border-bottom: 1px solid var(--line-soft);
    padding: 11px 0;
    display: flex; flex-wrap: wrap; gap: 4px 14px;
    justify-content: space-between; align-items: baseline;
  }
  tr td:last-child { border-bottom: none; }
  td::before {
    content: attr(data-label);
    color: var(--muted); font-size: .68rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .07em; flex: none;
  }
  td:not([data-label])::before { display: none; }
  td.right { justify-content: flex-start; }
}

/* ── messages ────────────────────────────────────────────── */

.flash {
  padding: 12px 14px; border-radius: var(--radius-sm);
  margin: 0 0 14px; border: 1px solid transparent; font-size: .9rem;
}
.flash.error  { background: color-mix(in srgb, var(--danger) 9%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.flash.notice { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.flash ul { margin: 8px 0 0; padding-left: 20px; }
.flash code, code {
  background: var(--surface-2); padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em;
}

/* ── bits ────────────────────────────────────────────────── */

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .7rem; font-weight: 650; letter-spacing: .02em;
  border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap; vertical-align: middle;
}
.pill.ok      { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 42%, transparent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.pill.warn    { color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 42%, transparent);   background: color-mix(in srgb, var(--warn) 10%, transparent); }
.pill.pending { color: var(--muted);  border-style: dashed; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 14px; text-align: center;
}
.stat b { display: block; font-size: 1.5rem; line-height: 1.1; letter-spacing: -.025em; }
.stat span { color: var(--muted); font-size: .74rem; }
@media (min-width: 560px) {
  .stat { text-align: left; padding: 16px 20px; }
  .stat b { font-size: 1.8rem; }
}

.empty { text-align: center; padding: 32px 18px; color: var(--muted); }
.empty h3 { color: var(--fg); }

.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 9px; }
.steps b { color: var(--fg); font-weight: 650; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono  { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; word-break: break-all; }

hr { border: none; border-top: 1px solid var(--line-soft); margin: 20px 0; }

h1, h2, h3, td, .card p, .mono { overflow-wrap: anywhere; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  button:active, .button:active { transform: none; }
}

/* downloader tiles: buttons align across a row */
.app-card { display: flex; flex-direction: column; justify-content: space-between; gap: 14px; margin-bottom: 0; }

/* collapsible "already have a .p12" panel */
details.card > summary {
  cursor: pointer; list-style: none; min-height: var(--tap);
  display: flex; align-items: center; gap: 8px;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: '›'; color: var(--muted); font-size: 1.1rem; transition: transform .15s ease; }
details.card[open] > summary::before { transform: rotate(90deg); }

/* duplicate-import resolver */
.resolve { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.resolve h2 { color: var(--warn); }
input[type=radio] { width: 18px; height: 18px; min-height: 0; flex: none; accent-color: var(--accent); }

/* stacked action buttons inside a card (downloader tiles) */
.app-card .stack { gap: 8px; }

/* nested disclosure inside an app card */
details.sub > summary {
  cursor: pointer; list-style: none; min-height: var(--tap);
  display: flex; align-items: center; gap: 8px;
  font-size: .9rem; font-weight: 600; color: var(--fg-soft);
}
details.sub > summary::-webkit-details-marker { display: none; }
details.sub > summary::before { content: '›'; color: var(--muted); font-size: 1.05rem; transition: transform .15s ease; }
details.sub[open] > summary::before { transform: rotate(90deg); }
