/* MediaDrop — quiet, cool-neutral UI. The one bold element is the upload
   block map: each cell is a real part of the file going to storage. */

:root {
  --paper: #F4F6F9;
  --surface: #FFFFFF;
  --ink: #18212F;
  --muted: #5B6577;
  --rule: #D7DDE5;
  --signal: #0B6E99;
  --signal-hover: #095A7D;
  --signal-ink: #FFFFFF;
  --amber: #D9922E;
  --danger: #B3261E;
  --ok: #2E7D4F;
  --warn-bg: #FBF1E2;
  --ok-bg: #E7F3EC;
  --err-bg: #FBE9E7;

  --map-empty: #E3E7ED;
  --map-done: var(--signal);
  --map-active: var(--amber);

  --radius-s: 4px;
  --radius-m: 8px;
  --font: 'Public Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #12171F;
    --surface: #1A212C;
    --ink: #E6EAF0;
    --muted: #98A2B3;
    --rule: #2E3846;
    --signal: #3FA3CF;
    --signal-hover: #62B6DB;
    --signal-ink: #0B1118;
    --amber: #E8A94D;
    --danger: #EF6B62;
    --ok: #5CB883;
    --warn-bg: #3A2E1C;
    --ok-bg: #1C3326;
    --err-bg: #3B1F1D;
    --map-empty: #2A3340;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.55 var(--font);
  font-variant-numeric: tabular-nums;
}

a { color: var(--signal); text-underline-offset: 2px; }
a:hover { color: var(--signal-hover); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

h1, h2 { margin: 0; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; margin-bottom: 0.9rem; }
p { margin: 0 0 1rem; }

.muted { color: var(--muted); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---- Top bar ---------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; gap: 2rem;
  padding: 0 1.5rem; min-height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--rule);
}
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font-weight: 700; font-size: 1.05rem; color: var(--ink); text-decoration: none;
}
.brand-mark {
  width: 18px; height: 18px; border-radius: 3px;
  background: linear-gradient(to right, var(--signal) 0 33%, var(--amber) 33% 66%, var(--ink) 66%);
}
.topbar nav { display: flex; gap: 1.25rem; }
.topbar nav a { color: var(--muted); text-decoration: none; font-weight: 500; padding: 1rem 0; border-bottom: 2px solid transparent; }
.topbar nav a:hover { color: var(--ink); }
.topbar nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--signal); }
.whoami { margin-left: auto; display: flex; align-items: center; gap: 0.9rem; color: var(--muted); font-size: 0.9rem; }

/* ---- Layout ----------------------------------------------------------- */

.page { max-width: 1120px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.crumb { margin-bottom: 0.4rem; font-size: 0.9rem; }

.panel {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m);
  padding: 1.25rem 1.4rem; margin-bottom: 1.5rem;
}
.file-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.5rem; align-items: start; }
.file-grid .panel { margin-bottom: 0; }
.file-title { overflow-wrap: anywhere; }

/* ---- Buttons ---------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: 600 0.9rem/1 var(--font); padding: 0.6rem 1rem;
  border: 1px solid var(--rule); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink); text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); color: var(--ink); }
.btn-primary { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.btn-primary:hover { background: var(--signal-hover); border-color: var(--signal-hover); color: var(--signal-ink); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-small { padding: 0.4rem 0.7rem; font-size: 0.82rem; }
.btn-large { padding: 0.85rem 1.6rem; font-size: 1rem; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--signal); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ---- Forms ------------------------------------------------------------ */

.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.field small, .check small { color: var(--muted); font-size: 0.82rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
input[type="text"], input[type="number"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius-s); padding: 0.55rem 0.7rem; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--signal); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 25%, transparent); }
.check { display: flex; gap: 0.6rem; align-items: flex-start; margin-bottom: 0.8rem; }
.check input { margin-top: 0.3rem; }
.check span { display: flex; flex-direction: column; }
.share-form .btn-primary { margin-top: 0.4rem; }
.inline-form { display: flex; gap: 0.4rem; align-items: center; }
.inline-form select { width: auto; padding: 0.35rem 0.5rem; font-size: 0.85rem; }
.inline-form input[type="text"] { width: auto; min-width: 0; flex: 1 1 14rem; max-width: 22rem; }
.settings-form { max-width: 560px; }

/* ---- Tables ----------------------------------------------------------- */

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); }
.list th {
  text-align: left; font-size: 0.82rem; font-weight: 600; color: var(--muted);
  padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.list td { padding: 0.75rem 0.8rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.list .num { text-align: right; }
.list .name { min-width: 260px; }
.filename { font-weight: 600; overflow-wrap: anywhere; }
.desc { display: block; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.desc.warn { color: var(--danger); }
.page > .table-wrap { border: 1px solid var(--rule); border-radius: var(--radius-m); }

.tag {
  display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 0.1rem 0.45rem;
  border-radius: var(--radius-s); background: var(--paper); color: var(--muted); margin: 0 0.4rem;
}
.tag-warn { background: var(--warn-bg); color: var(--ink); }

.state { font-weight: 600; font-size: 0.85rem; }
.state::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.4rem; background: currentColor; }
.state-active { color: var(--ok); }
.state-expired, .state-used { color: var(--amber); }
.state-revoked { color: var(--muted); }

/* ---- Shares ----------------------------------------------------------- */

.shares { margin-top: 2rem; }
.batch { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); margin-bottom: 1.25rem; overflow: hidden; }
.batch-head { display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 0.9rem; font-size: 0.88rem; color: var(--muted); border-bottom: 1px solid var(--rule); }
.batch-msg { margin: 0; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--rule); white-space: pre-wrap; font-size: 0.92rem; }
.recipients tr:last-child td { border-bottom: 0; }
.row-actions { text-align: right; width: 1%; }
.log-row td { padding-top: 0; }
.log-row summary { cursor: pointer; color: var(--signal); font-size: 0.85rem; }
table.log { width: 100%; border-collapse: collapse; margin-top: 0.5rem; font-size: 0.82rem; }
.log th, .log td { text-align: left; padding: 0.35rem 0.5rem; border-top: 1px solid var(--rule); }
.log th { color: var(--muted); font-weight: 600; }
.log .ua { color: var(--muted); max-width: 380px; overflow-wrap: anywhere; }

details.menu { position: relative; display: inline-block; }
details.menu > summary { list-style: none; }
details.menu > summary::-webkit-details-marker { display: none; }
.menu-body {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; min-width: 240px;
  display: flex; flex-direction: column; gap: 0.5rem; align-items: stretch;
  padding: 0.75rem; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m);
  box-shadow: 0 8px 24px rgba(24, 33, 47, 0.14);
}
.menu-body form { margin: 0; }
.menu-body form > .btn, .menu-body > .btn { width: 100%; }

/* ---- Messages --------------------------------------------------------- */

.flash { padding: 0.75rem 1rem; border-radius: var(--radius-s); margin-bottom: 1.5rem; }
.flash-ok { background: var(--ok-bg); }
.flash-error { background: var(--err-bg); }
.error { color: var(--danger); font-weight: 500; }
.notice, .empty { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 1.5rem; }
.notice h1 { margin-bottom: 0.75rem; font-size: 1.3rem; }
.empty { max-width: 560px; }
.empty h2 { font-size: 1.2rem; }
.empty p { color: var(--muted); }

/* ---- Upload ----------------------------------------------------------- */

.uploader { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 1.5rem; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: 0.4rem; min-height: 220px; padding: 2rem; margin-bottom: 1.25rem; cursor: pointer;
  border: 2px dashed var(--rule); border-radius: var(--radius-m); background: var(--paper);
}
.dropzone:hover, .dropzone.is-over { border-color: var(--signal); }
.dropzone:focus-within { outline: 2px solid var(--signal); outline-offset: 2px; }
.dz-title { font-size: 1.15rem; font-weight: 700; }
.dz-sub { color: var(--muted); max-width: 46ch; }
.uploader .field { max-width: 640px; }

.progress-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.progress-head .filename { font-size: 1.1rem; }
.blockmap { display: block; width: 100%; margin-bottom: 1.5rem; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin: 0 0 1rem; }
.stats div { border-top: 2px solid var(--ink); padding-top: 0.5rem; }
.stats dt { font-size: 0.82rem; color: var(--muted); }
.stats dd { margin: 0.1rem 0 0; font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
.status { color: var(--muted); min-height: 1.5em; }

/* ---- Recipient / sign-in pages ---------------------------------------- */

body.plain { min-height: 100vh; display: flex; }
.solo { margin: auto; width: 100%; max-width: 560px; padding: 3rem 1.5rem; }
.solo-brand { margin-bottom: 1.5rem; }
.card-solo { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 2rem; }
.card-solo h1 { margin-bottom: 0.4rem; }
.card-solo > .muted:first-child { margin-bottom: 0.4rem; }
.filemeta { color: var(--muted); font-size: 1.05rem; margin-bottom: 1.25rem; }
.note { margin: 0 0 1.5rem; padding: 0.8rem 1rem; border-left: 3px solid var(--signal); background: var(--paper); white-space: pre-wrap; }
.fineprint { margin: 1.5rem 0 0; font-size: 0.85rem; color: var(--muted); }

/* ---- Settings --------------------------------------------------------- */

.page-tabs { display: flex; gap: 1.5rem; border-bottom: 1px solid var(--rule); margin: -0.5rem 0 1.5rem; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.page-tab { color: var(--muted); text-decoration: none; font-weight: 500; padding: 0.6rem 0; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.page-tab:hover { color: var(--ink); }
.page-tab[aria-current="page"] { color: var(--ink); border-bottom-color: var(--signal); }

.manage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; }
.manage-card {
  display: flex; flex-direction: column; gap: 0.3rem; padding: 1.25rem;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m);
  color: var(--ink); text-decoration: none;
}
.manage-card:hover { border-color: var(--signal); color: var(--ink); }
.manage-card svg { width: 26px; height: 26px; color: var(--signal); margin-bottom: 0.4rem; }
.manage-card-title { font-weight: 700; }
.manage-card-sub { color: var(--muted); font-size: 0.88rem; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.25rem; margin: 0 0 1rem; }
.kv dt { font-weight: 600; }
.kv dd { margin: 0; color: var(--muted); }
.role { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 0.1rem 0.5rem; border-radius: var(--radius-s); background: var(--paper); }
.role-manager { background: var(--warn-bg); }
.role-admin { background: var(--signal); color: var(--signal-ink); }
.role-disabled { color: var(--muted); text-decoration: line-through; }

.fieldset { border: 0; padding: 0; margin: 0 0 1.5rem; }
.fieldset legend { font-weight: 700; margin-bottom: 0.6rem; }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }

.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.sev { font-weight: 600; font-size: 0.8rem; }
.sev-bad { color: var(--danger); }
.sev-warn { color: var(--amber); }
.err-msg { overflow-wrap: anywhere; min-width: 280px; }
.err-msg summary { cursor: pointer; }
.err-msg pre { white-space: pre-wrap; font-size: 0.8rem; margin: 0.5rem 0 0; }

.search-form { margin-bottom: 1rem; }
.bulk-bar { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- Share modes ------------------------------------------------------ */

.mode-switch { display: flex; border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 3px; margin: 0 0 1.25rem; gap: 3px; }
.mode-switch label { flex: 1; position: relative; cursor: pointer; }
.mode-switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.mode-switch span { display: block; text-align: center; padding: 0.5rem 0.75rem; border-radius: var(--radius-s); font-weight: 600; font-size: 0.9rem; color: var(--muted); }
.mode-switch input:checked + span { background: var(--signal); color: var(--signal-ink); }
.mode-switch input:focus-visible + span { outline: 2px solid var(--signal); outline-offset: 2px; }

.new-link { border-color: var(--signal); }
.copy-row { display: flex; gap: 0.6rem; margin-bottom: 0.6rem; }
.copy-row input { flex: 1; min-width: 0; font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: 0.85rem; }

/* ---- Branding ---------------------------------------------------------- */

.brand-logo { width: 28px; height: 28px; object-fit: contain; border-radius: 4px; flex: none; }
.solo-brand .brand-logo { width: 40px; height: 40px; }
.logo-preview { display: flex; align-items: center; min-height: 84px; padding: 1rem; margin-bottom: 0.5rem; border: 1px dashed var(--rule); border-radius: var(--radius-m); background: var(--paper); }
.logo-preview-email { background: #FFFFFF; }   /* emails are read on white */
.email-head { display: flex; align-items: center; gap: 14px; color: #1A2230; font-size: 22px; letter-spacing: -0.01em; }
.email-head img { height: 48px; max-width: 240px; object-fit: contain; }
.logo-form { margin-top: 1rem; }
.logo-form input[type="file"] { font: inherit; font-size: 0.9rem; }

/* ---- Packs ------------------------------------------------------------- */

.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.9rem; }
.panel-head h2 { margin: 0; }
.solo-wide { max-width: 760px; }
.email-brand { display: flex; align-items: center; gap: 14px; font-weight: 700; font-size: 1.35rem; letter-spacing: -0.01em; }
.email-brand img { height: 48px; max-width: 240px; object-fit: contain; }
@media (prefers-color-scheme: dark) {
  .email-brand img { background: #FFFFFF; padding: 4px 6px; border-radius: var(--radius-s); }   /* email logos are made for white */
}
.pack-files { list-style: none; margin: 1.25rem 0 0; padding: 0; border-top: 1px solid var(--rule); }
.pack-files li { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.85rem 0; border-bottom: 1px solid var(--rule); }
.pack-file-info { display: flex; flex-direction: column; min-width: 0; }
.pack-file-info .filename { overflow-wrap: anywhere; font-weight: 600; }
.upload-queue { list-style: none; margin: 1rem 0 0; padding: 0; }
.upload-queue li { display: flex; justify-content: space-between; gap: 1rem; padding: 0.4rem 0; border-bottom: 1px solid var(--rule); font-size: 0.9rem; }
.upload-queue .q-done { color: var(--ok); }
.upload-queue .q-active { color: var(--amber); font-weight: 600; }

/* ---- Small screens ---------------------------------------------------- */

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 0.5rem 1.25rem; padding: 0.5rem 1rem; }
  .whoami { margin-left: 0; }
  .page { padding: 1.25rem 1rem 3rem; }
  .file-grid, .field-row { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats dd { font-size: 1.3rem; }
  .menu-body { right: auto; left: 0; }
  .kv { grid-template-columns: 1fr; }
  .pack-files li { flex-direction: column; align-items: stretch; }
  .kv dd { margin-bottom: 0.5rem; }
}

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