/* APEX Instant Sharing - single stylesheet, light and dark. */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #dfe2ea;
  --text: #171a21;
  --muted: #6a7180;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --danger: #c1362f;
  --ok: #1f7a4d;
  --warn: #9a6212;
  --shadow: 0 1px 2px rgba(16, 20, 32, .06), 0 8px 24px rgba(16, 20, 32, .06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141a;
    --surface: #1a1d25;
    --surface-2: #21242e;
    --border: #2e323d;
    --text: #e8eaf0;
    --muted: #9aa1b1;
    --accent: #7f96ff;
    --accent-text: #0d1017;
    --danger: #ff8b81;
    --ok: #63d3a0;
    --warn: #e7b35c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

/* Author display rules (.stack, .panel...) would otherwise beat the UA rule
   for the hidden attribute, which this app uses to switch views. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3.small { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-top: 1rem; }
p { margin: 0 0 .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); font-size: .9rem; }
.error:empty { display: none; }

/* ------------------------------------------------------------- controls -- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; justify-content: center;
  padding: .55rem .9rem; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.tiny { padding: .3rem .55rem; font-size: .82rem; }

.linkish { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; padding: .5rem 0; }

input, select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .chip:focus-visible, .dropzone:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: .1rem; }
label input, label select { margin-top: .3rem; font-weight: 400; }
.stack { display: grid; gap: .8rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.code-input { font-size: 1.4rem; letter-spacing: .35em; text-align: center; font-family: ui-monospace, monospace; }
.search { max-width: 340px; }

/* --------------------------------------------------------------- auth ---- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.6rem; box-shadow: var(--shadow);
}
.auth-card.wide { max-width: 560px; }

/* Sign-in: the suite's standard layout (as in FacturAres), a brand panel beside
   the form. The panel keeps the brand colours in both themes; the form side
   follows the theme. */
.auth-shell { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); background: var(--bg); }
.auth-aside {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between;
  padding: 48px 52px; color: #dbe3ff;
  background: linear-gradient(150deg, #0d1230 0%, #22379e 55%, #3b5bdb 100%);
}
.auth-aside::after {
  content: ''; position: absolute; right: -120px; bottom: -120px; width: 380px; height: 380px;
  border-radius: 50%; background: rgba(255, 255, 255, .07);
}
.auth-aside > * { position: relative; z-index: 1; }
.auth-logo { height: 52px; width: auto; align-self: flex-start; }
.auth-aside h2 { color: #fff; font-size: 29px; line-height: 1.2; margin: 0 0 16px; letter-spacing: -.02em; font-weight: 700; }
.auth-aside p { margin: 0 0 24px; color: #c4d0ff; font-size: 16px; line-height: 1.5; max-width: 30rem; }
.auth-points { list-style: none; padding: 0; margin: 0; display: grid; gap: 13px; }
.auth-points li { display: flex; gap: 11px; align-items: flex-start; color: #e8edff; font-size: 15px; line-height: 1.45; }
.auth-points svg { flex: none; margin-top: 1px; color: #ffc247; }
.auth-foot { font-size: 12.5px; color: #a3b3f0; }
.auth-main { display: flex; flex-direction: column; padding: 24px 32px 40px; }
.auth-panel { width: 100%; max-width: 420px; margin: auto; padding-top: 24px; }
.auth-panel.wide { max-width: 560px; }
.auth-panel > h1 { font-size: 25px; font-weight: 650; letter-spacing: -.015em; margin: 0 0 6px; }
.auth-intro { margin: 0 0 18px; color: var(--muted); }
.auth-panel .auth-card { max-width: none; }
.auth-panel .linkish { margin-top: .8rem; }
@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-aside { padding: 24px 24px 28px; }
  .auth-logo { height: 44px; }
  .auth-aside h2 { font-size: 21px; margin-top: 16px; }
  .auth-aside p { margin-bottom: 0; }
  .auth-points, .auth-foot { display: none; }
  .auth-main { padding: 16px 16px 32px; }
}
.brand { display: flex; gap: .8rem; align-items: center; margin-bottom: 1.2rem; }
.brand.small { gap: .5rem; margin: 0; }
.brand h1 { margin: 0; font-size: 1.2rem; }
.brand p { margin: 0; font-size: .88rem; }
.brand-mark { display: block; width: 38px; height: 38px; flex: none; }
.brand.small .brand-mark { width: 30px; height: 30px; }
.tabs { display: flex; gap: .25rem; background: var(--surface-2); padding: .25rem; border-radius: 10px; margin-bottom: 1.1rem; }
.tab { flex: 1; padding: .45rem; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.backup-details { margin: 1rem 0; border-top: 1px solid var(--border); padding-top: .8rem; }
.backup-details summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.backup-details .stack { margin-top: .8rem; }
.enrol { padding-left: 1.2rem; display: grid; gap: 1.2rem; }
.qr-wrap { background: #fff; padding: .6rem; border-radius: 10px; width: max-content; margin: .7rem 0; border: 1px solid var(--border); }
.secret { user-select: all; background: var(--surface-2); padding: .2rem .4rem; border-radius: 6px; letter-spacing: .1em; }
.inline-form { grid-template-columns: 1fr auto; display: grid; align-items: start; }
.codes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; list-style: none; padding: 0; margin: 1rem 0; }
.codes li { font-family: ui-monospace, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .5rem; text-align: center; letter-spacing: .06em; }

/* -------------------------------------------------------------- shell ---- */
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .7rem 1.1rem; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.nav { display: flex; gap: .2rem; flex: 1; flex-wrap: wrap; }
.navlink { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 500; padding: .45rem .7rem; border-radius: 8px; cursor: pointer; }
.navlink:hover { background: var(--surface-2); color: var(--text); }
.navlink.is-active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.userchip { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.badge { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); padding: .15rem .4rem; border-radius: 5px; font-weight: 700; }
.content { max-width: 1100px; margin: 0 auto; padding: 1.4rem 1.1rem 4rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.scopes { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: .35rem .8rem; font: inherit; font-size: .88rem; cursor: pointer; }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
details.card summary { cursor: pointer; margin-bottom: .6rem; }

/* -------------------------------------------------------------- files ---- */
.cards { display: grid; gap: .7rem; }
.filecard {
  display: grid; grid-template-columns: 42px 1fr auto; gap: .9rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem;
}
.filecard.is-deleted { opacity: .6; }
.fileicon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 10px; background: var(--surface-2); font-size: 1.2rem; }
.filename { font-weight: 600; word-break: break-word; }
.filemeta { color: var(--muted); font-size: .85rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.tag { font-size: .72rem; padding: .1rem .45rem; border-radius: 5px; border: 1px solid var(--border); background: var(--surface-2); text-transform: uppercase; letter-spacing: .04em; }
.tag.everyone { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
.tag.shared { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.tag.expiring { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, var(--border)); }
.tag.deleted { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.tag.public { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); background: color-mix(in srgb, var(--warn) 10%, var(--surface-2)); }
.fileactions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius); }

/* ------------------------------------------------------------- upload ---- */
.upload-form { display: grid; gap: 1.1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2.2rem 1rem; text-align: center; cursor: pointer; background: var(--surface-2); }
.dropzone.is-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface-2)); }
.dropzone p { margin: .2rem; }
.queue { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.queue li { display: flex; justify-content: space-between; gap: .6rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .7rem; font-size: .9rem; }
.share-picker { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.share-picker legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }
.radio { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.radio input { width: auto; margin: 0; }
.people { display: grid; gap: .25rem; max-height: 190px; overflow: auto; margin: .5rem 0; }
.person { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .4rem .6rem; border-radius: 8px; background: var(--surface-2); font-size: .9rem; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chips .chip { background: color-mix(in srgb, var(--accent) 12%, transparent); border-color: transparent; color: var(--accent); }
progress { width: 200px; height: 8px; }

/* -------------------------------------------------------------- tables --- */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tablewrap.short { max-height: 220px; overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .6rem .8rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.table td { padding: .55rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table td.details { max-width: 320px; color: var(--muted); font-family: ui-monospace, monospace; font-size: .78rem; word-break: break-word; }
.outcome { font-weight: 600; }
.outcome.success { color: var(--ok); }
.outcome.failure, .outcome.denied { color: var(--danger); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.filters input, .filters select { width: auto; min-width: 140px; }
.integrity { font-size: .9rem; }
.integrity.ok { color: var(--ok); }
.integrity.bad { color: var(--danger); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; }
.stat b { display: block; font-size: 1.35rem; }
.stat span { color: var(--muted); font-size: .82rem; }
.pager { display: grid; place-items: center; padding: 1rem; }

/* -------------------------------------------------------------- dialog --- */
.dialog { border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); max-width: 560px; width: calc(100% - 2rem); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 12, 18, .55); backdrop-filter: blur(2px); }
.dialog-inner { padding: 1.3rem; display: grid; gap: .6rem; }
.switch { display: flex; align-items: center; gap: .5rem; font-weight: 500; background: var(--surface-2); padding: .6rem .8rem; border-radius: 9px; }
.switch input { width: auto; }
/* Public link: visually set apart, because it is the only share that works
   without an account. */
.linkbox { border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border)); border-radius: 10px; padding: .7rem; display: grid; gap: .6rem; }
.linkbox .switch { background: color-mix(in srgb, var(--warn) 9%, var(--surface-2)); }
#publiclink-detail { display: grid; gap: .6rem; }
#publiclink-url { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }
.btn.is-disabled, a.btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

/* Admin policy switches */
.policyrow { display: grid; gap: .25rem; padding-bottom: .6rem; border-bottom: 1px solid var(--border); }
.policyrow:last-child { border-bottom: 0; padding-bottom: 0; }
.policyrow p { margin: 0; }

.sharelist { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.sharelist li { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .4rem .6rem; background: var(--surface-2); border-radius: 8px; font-size: .9rem; }

/* -------------------------------------------------------------- toasts --- */
.toasts { position: fixed; top: 1rem; right: 1rem; z-index: 50; display: grid; gap: .5rem; max-width: min(380px, calc(100vw - 2rem)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; padding: .7rem .9rem; box-shadow: var(--shadow); font-size: .9rem; animation: slide .18s ease-out; }
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--ok); }
@keyframes slide { from { opacity: 0; transform: translateY(-6px); } }

@media (max-width: 700px) {
  .filecard { grid-template-columns: 1fr; }
  .fileactions { justify-content: flex-start; }
  .topbar { gap: .5rem; }
  .search { max-width: 100%; }
}

/* ---------------------------------------------------- demo storage meter -- */
.storage-meter { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.storage-text { font-size: .9rem; margin-bottom: .45rem; }
.storage-bar { height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.storage-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.storage-meter.is-full .storage-bar span { background: var(--danger); }

/* ------------------------------------------------- demo sign-in notice ---- */
.demo-note { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; padding: 12px 14px; border: 1px solid var(--warn); border-radius: 10px; background: color-mix(in srgb, var(--warn) 12%, var(--surface)); font-size: 13.5px; line-height: 1.45; }
.demo-badge { flex: none; padding: 4px 10px; border-radius: 6px; background: var(--warn); color: var(--surface); font-weight: 800; font-size: 13px; letter-spacing: .12em; }
.demo-note a { color: var(--accent); font-weight: 600; }
