/* ---- tokens -------------------------------------------------------------- */
:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #15171c;
  --muted: #5d6573;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --on-accent: #ffffff;
  --ok: #157f3c;
  --ok-soft: #e7f6ec;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --danger: #c0262d;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --border: #2a2f3a;
    --text: #e8eaee; --muted: #9aa3b2;
    --accent: #818cf8; --accent-hover: #a5b4fc; --accent-soft: #23264a; --on-accent: #0f1115;
    --ok: #4ade80; --ok-soft: #13291c; --warn: #fbbf24; --warn-soft: #2c2210;
    --danger: #f87171; --danger-soft: #2f1517;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115; --surface: #171a21; --surface-2: #1e222b; --border: #2a2f3a;
  --text: #e8eaee; --muted: #9aa3b2;
  --accent: #818cf8; --accent-hover: #a5b4fc; --accent-soft: #23264a; --on-accent: #0f1115;
  --ok: #4ade80; --ok-soft: #13291c; --warn: #fbbf24; --warn-soft: #2c2210;
  --danger: #f87171; --danger-soft: #2f1517;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
}

/* ---- base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.15rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- controls --------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-size: .9rem; font-weight: 560;
  padding: .45rem .85rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.solid-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: .3rem .6rem; font-size: .82rem; }

label { display: block; font-size: .85rem; font-weight: 560; margin-bottom: .3rem; }
input[type=text], input[type=password], select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: .55rem .7rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { margin-bottom: 1rem; }
.field .hint { font-size: .8rem; color: var(--muted); margin-top: .3rem; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: .55rem .75rem; font-size: .88rem; margin-bottom: 1rem; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.segmented button {
  font: inherit; font-size: .82rem; font-weight: 560; color: var(--muted);
  background: transparent; border: 0; border-radius: 7px; padding: .3rem .7rem; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.badge { display: inline-flex; align-items: center; gap: .3rem; font-size: .75rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---- sign-in page ----------------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.auth-card { width: 100%; max-width: 380px; padding: 2rem; }
.auth-card .brand { justify-content: center; margin-bottom: 1.5rem; }
.auth-card h1 { font-size: 1.3rem; text-align: center; margin-bottom: .35rem; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: .9rem; margin-bottom: 1.5rem; }
.auth-card .btn { width: 100%; padding: .65rem; }

/* ---- shell ---------------------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.08rem; letter-spacing: -.01em; color: var(--text); text-decoration: none; }
.brand img { width: 28px; height: 28px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: .7rem 1.25rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.tabs { display: flex; gap: .25rem; margin-left: .75rem; }
.tabs a {
  text-decoration: none; color: var(--muted); font-weight: 560; font-size: .92rem;
  padding: .4rem .75rem; border-radius: 8px;
}
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.spacer { flex: 1; }

.menu { position: relative; }
.menu-btn { display: inline-flex; align-items: center; gap: .5rem; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: .78rem; font-weight: 700; text-transform: uppercase; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 250px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: .5rem; z-index: 20;
}
.menu-panel .who { padding: .5rem .6rem .6rem; border-bottom: 1px solid var(--border); margin-bottom: .4rem; }
.menu-panel .row { padding: .5rem .6rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; font-size: .88rem; }
.menu-panel button.item {
  display: block; width: 100%; text-align: left; font: inherit; font-size: .9rem;
  background: none; border: 0; color: var(--text); padding: .5rem .6rem; border-radius: 7px; cursor: pointer;
}
.menu-panel button.item:hover { background: var(--surface-2); }

main { max-width: 1180px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.015em; }
.page-head p { color: var(--muted); margin-top: .2rem; }
.section { margin-top: 2.25rem; }
.section > h2 { margin-bottom: .85rem; }

/* ---- launcher tiles ------------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1rem; }
.tile {
  display: flex; flex-direction: column; gap: .8rem; padding: 1.15rem;
  text-decoration: none; color: inherit;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.tile-head { display: flex; align-items: center; gap: .8rem; }
.app-icon {
  width: 48px; height: 48px; border-radius: 12px; flex: none;
  display: grid; place-items: center; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 700; font-size: 1.1rem; color: #fff;
}
.app-icon img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.tile-name { font-weight: 650; font-size: 1.02rem; }
.tile-desc { color: var(--muted); font-size: .88rem; flex: 1; }
.tile-foot { display: flex; align-items: center; justify-content: space-between; font-size: .8rem; color: var(--muted); }
.tile-foot .open { color: var(--accent); font-weight: 600; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: .35rem; }

/* ---- storage ------------------------------------------------------------------- */
.storage { padding: 1.15rem 1.25rem; }
.storage-top { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.storage-big { font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; }
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; display: flex; }
.meter > span { display: block; height: 100%; }
.meter .m-other { background: color-mix(in srgb, var(--muted) 55%, transparent); }
.meter .m-apps { background: var(--accent); }
.meter.warn .m-other { background: var(--warn); }
.meter.danger .m-other { background: var(--danger); }
.legend { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-top: .7rem; font-size: .84rem; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: .4rem; vertical-align: 0; }

/* ---- manage list ---------------------------------------------------------------- */
.app-rows { display: flex; flex-direction: column; gap: .75rem; }
.app-row { padding: 1rem 1.15rem; display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center; }
.app-row .meta { min-width: 0; }
.app-row .title { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.app-row .title h3 { font-size: 1.02rem; }
.app-row .details { color: var(--muted); font-size: .84rem; margin-top: .2rem; display: flex; gap: .3rem 1rem; flex-wrap: wrap; }
.app-row .details a { color: inherit; }
.app-row .actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.app-row .error { grid-column: 2 / -1; color: var(--danger); font-size: .84rem; }
.progress { grid-column: 2 / -1; }
.progress .bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: .35rem; }
.progress .bar span { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.progress .bar.indeterminate span { width: 35%; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
@media (max-width: 720px) {
  .app-row { grid-template-columns: auto 1fr; }
  .app-row .actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---- users table ------------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: .3rem; }

/* ---- dialogs -------------------------------------------------------------------------- */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  width: min(460px, calc(100vw - 2rem));
}
dialog::backdrop { background: rgba(10, 12, 18, .45); backdrop-filter: blur(2px); }
dialog form, dialog .body { padding: 1.4rem 1.5rem 1.2rem; }
dialog h2 { margin-bottom: .4rem; }
dialog .lead { color: var(--muted); font-size: .92rem; margin-bottom: 1.1rem; }
dialog .buttons { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.secret { display: flex; gap: .5rem; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem; font-family: var(--mono); font-size: .95rem; word-break: break-all; }
.secret code { flex: 1; font-size: 1rem; }

/* ---- toast ------------------------------------------------------------------------------ */
.toasts { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 100; width: max-content; max-width: calc(100vw - 2rem); }
.toast { background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: .9rem; animation: pop .18s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 640px) {
  .tabs { order: 3; width: 100%; margin-left: 0; }
  main { padding-top: 1.25rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.mt { margin-top: .75rem; }
.legend .m-apps-dot { background: var(--accent); }
.legend .m-other-dot { background: color-mix(in srgb, var(--muted) 55%, transparent); }
.legend .m-free-dot { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
