:root {
    --bg: #eef1f5;
    --surface: #ffffff;
    --ink: #172035;
    --muted: #586277;
    --line: #d4dae4;
    --accent: #23305c;
    --accent-ink: #ffffff;
    --focus: #4f63d9;
    --danger: #a3261f;
    --danger-bg: #fbeceb;
    --ok: #1f6b3a;
    --ok-bg: #e8f4ec;
    --gdrive: #1a7f45;
    --onedrive: #0f63b0;
    --icloud: #6a7280;
    --radius: 10px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #10141c;
        --surface: #181e29;
        --ink: #e5e9f0;
        --muted: #9aa3b4;
        --line: #2b3342;
        --accent: #a9b5f5;
        --accent-ink: #10141c;
        --focus: #a9b5f5;
        --danger: #f2a39c;
        --danger-bg: #3a1d1c;
        --ok: #8fd6a6;
        --ok-bg: #16301f;
        --gdrive: #58c586;
        --onedrive: #6aaef0;
        --icloud: #a3aab6;
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.5 var(--font);
    padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

h1 { font-size: 1.5rem; line-height: 1.25; margin: 1.5rem 0 .75rem; letter-spacing: -.01em; }
h2 { font-size: 1.125rem; line-height: 1.3; margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Provider colour tokens: every row, pill and card picks up its drive's colour from one class. */
.p-gdrive { --pc: var(--gdrive); }
.p-onedrive { --pc: var(--onedrive); }
.p-icloud { --pc: var(--icloud); }

/* Top bar */
.topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: .75rem max(1rem, env(safe-area-inset-left));
    padding-top: max(.75rem, env(safe-area-inset-top));
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .5rem; color: var(--ink); text-decoration: none; font-weight: 650; font-size: 1.125rem; }
.mainnav { display: flex; gap: .25rem; margin-left: auto; }
.mainnav a {
    color: var(--muted); text-decoration: none; padding: .375rem .75rem; border-radius: 999px; font-weight: 550;
}
.mainnav a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.signout { margin: 0; }
.linkish { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: .375rem; }
.linkish:hover { color: var(--ink); }

.page { max-width: 58rem; margin: 0 auto; padding: 1rem max(1rem, env(safe-area-inset-left)) 4rem; }
.page--narrow { max-width: 26rem; padding-top: 12vh; }

/* Notices */
.notice { padding: .75rem 1rem; border-radius: var(--radius); margin: 1rem 0; }
.notice--error { background: var(--danger-bg); color: var(--danger); }
.notice--success { background: var(--ok-bg); color: var(--ok); }

/* Buttons and inputs */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 2.75rem; padding: 0 1.125rem; border-radius: var(--radius);
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { filter: brightness(1.12); }
.btn--quiet { border-color: transparent; color: var(--muted); }
.is-disabled { opacity: .5; cursor: not-allowed; }

input[type="email"], input[type="password"], input[type="text"], input[type="search"], select {
    width: 100%; min-height: 2.75rem; padding: .5rem .75rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--surface); color: var(--ink); font: inherit;
}

/* Sign-in */
.authcard { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 2rem 1.5rem; }
.authcard h1 { margin-top: 1rem; }
.stack { display: grid; gap: 1rem; margin-top: 1.25rem; }
.stack label { display: grid; gap: .375rem; font-weight: 600; font-size: .9375rem; }
.codeinput { font-size: 1.5rem; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }

/* The finder: the one loud element on the page */
.finder { position: sticky; top: 3.75rem; z-index: 5; background: var(--bg); padding: .75rem 0 .5rem; }
.finder__box {
    display: flex; gap: .5rem; padding: .375rem;
    background: var(--surface); border: 2px solid var(--ink); border-radius: 14px;
}
.finder__box:focus-within { border-color: var(--focus); }
.finder__box input { border: 0; font-size: 1.25rem; min-height: 3rem; padding: 0 .5rem; background: transparent; }
.finder__box input:focus-visible { outline: none; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; align-items: center; }
.filters select { width: auto; max-width: 100%; min-height: 2.25rem; padding: .25rem .5rem; font-size: .9375rem; }
.chips { display: flex; gap: .375rem; border: 0; margin: 0; padding: 0; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
    display: inline-block; white-space: nowrap; padding: .3rem .75rem; border-radius: 999px;
    border: 1px solid var(--line); background: var(--surface); font-size: .875rem; cursor: pointer;
}
.chip input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.listhead { font-size: 1rem; font-weight: 600; color: var(--muted); margin: 1rem 0 .5rem; }

/* Results */
.results { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.result {
    display: grid; gap: .25rem; padding: .875rem 1rem .875rem 1.125rem;
    border-bottom: 1px solid var(--line); border-left: 4px solid var(--pc);
}
.result:last-child { border-bottom: 0; }
.result__name { font-weight: 600; font-size: 1.0625rem; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
a.result__name:hover { text-decoration: underline; }
.result__meta, .dupgroup__meta { display: flex; flex-wrap: wrap; gap: .25rem 1rem; color: var(--muted); font-size: .875rem; }

/* Location trail */
.trail { display: flex; flex-wrap: wrap; align-items: center; gap: .125rem .375rem; font-size: .9375rem; color: var(--ink); min-width: 0; }
.trail__sep { color: var(--muted); }
.trail__folder { overflow-wrap: anywhere; }
.pill {
    display: inline-block; padding: .05rem .5rem; border-radius: 6px; font-size: .8125rem; font-weight: 650;
    color: var(--pc); background: color-mix(in srgb, var(--pc) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--pc) 35%, transparent);
}

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: .75rem; }
.tabs a { padding: .5rem .75rem; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }

/* Duplicates */
.summary { font-size: 1.0625rem; }
.dupgroup { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 1rem 0; overflow: hidden; }
.dupgroup header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem 1rem; padding: .875rem 1rem; border-bottom: 1px solid var(--line); }
.dupgroup h2 { overflow-wrap: anywhere; }
.dupgroup ul { list-style: none; margin: 0; padding: 0; }
.dupgroup li { display: grid; gap: .25rem; padding: .75rem 1rem .75rem 1.125rem; border-left: 4px solid var(--pc); }
.dupgroup li + li { border-top: 1px solid var(--line); }
.badge { font-weight: 650; color: var(--ok); }

/* Drives */
.drivelist { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }
.drivecard { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--pc); border-radius: var(--radius); padding: 1rem; display: grid; gap: .75rem; align-content: start; }
.drivecard header { display: grid; gap: .375rem; justify-items: start; }
.drivecard h2 { font-size: 1rem; overflow-wrap: anywhere; }
.drivecard dl { display: flex; gap: 1.5rem; margin: 0; }
.drivecard dt { font-size: .8125rem; color: var(--muted); }
.drivecard dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.drivecard .notice { margin: 0; font-size: .9375rem; }
.drivecard .muted { margin: 0; font-size: .9375rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.actions form { margin: 0; }
.sectionhead { margin: 2rem 0 .75rem; }
.connect { display: grid; gap: .75rem; justify-items: start; }
.connect__btn { border-left: 4px solid var(--pc, var(--line)); }

.empty { padding: 2rem 0; }
.errordetail { white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); padding: 1rem; border-radius: var(--radius); }

@media (max-width: 40rem) {
    .topbar { flex-wrap: wrap; row-gap: .5rem; }
    .mainnav { order: 3; width: 100%; margin-left: 0; }
    .mainnav a { flex: 1; text-align: center; }
    .signout { margin-left: auto; }
    .finder { top: 6.5rem; }
    .finder__box input { font-size: 1.125rem; }
    .filters select { width: 100%; }
    .chips { flex: 1 1 100%; }
    h1 { font-size: 1.3rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto !important; transition: none !important; }
}
