/* relay — styles. Themed to match Flomation's house style: lilac canvas,
   deep-violet gradient CTAs, pastel purple/teal accents, Sora display type.
   Light/dark via prefers-color-scheme. No external assets — Sora is self-hosted,
   so it stays within the app's `default-src 'self'` CSP. */

@font-face {
  font-family: "Sora";
  src: url("fonts/sora-latin.woff2") format("woff2");
  font-weight: 400 800;   /* variable weight axis */
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --bg: #f6f4f8;
  --bg-grad:
    radial-gradient(1100px 620px at 100% -10%, #efe6f6 0%, rgba(239,230,246,0) 58%),
    radial-gradient(900px 520px at -10% 2%, #e6eef0 0%, rgba(230,238,240,0) 55%);
  --panel: #ffffff;
  --panel-2: #faf8fc;
  --panel-3: #eae3ef;
  --text: #342a38;
  --muted: #473d4b;
  --faint: #857b8c;
  --border: rgba(70,45,84,.12);
  --border-strong: rgba(70,45,84,.22);
  --accent: #6b3f80;
  --accent-strong: #460070;
  --accent-grad: linear-gradient(180deg, #5d3670, #460070);
  --accent-ink: #ffffff;
  --accent-soft: #efe7f6;
  --danger: #c23a63;
  --danger-soft: #fbe9f0;
  --ok: #2f6b64;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgba(70,45,84,.06), 0 10px 28px -12px rgba(70,45,84,.22);
  --shadow-sm: 0 1px 2px rgba(70,45,84,.08);
  --glow-cta: 0 6px 18px rgba(70,0,112,.22);
  --glow-cta-strong: 0 10px 26px rgba(70,0,112,.34);
  --radius: 16px;
  --radius-sm: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --display: "Sora", var(--sans);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15111b;
    --bg-grad:
      radial-gradient(1100px 620px at 100% -10%, #2a1d3c 0%, rgba(42,29,60,0) 55%),
      radial-gradient(900px 520px at -10% 2%, #16242a 0%, rgba(22,36,42,0) 55%);
    --panel: #1d1726;
    --panel-2: #241d2f;
    --panel-3: #2c2438;
    --text: #ece7f2;
    --muted: #b6abc4;
    --faint: #8a7e99;
    --border: rgba(199,173,215,.14);
    --border-strong: rgba(199,173,215,.24);
    --accent: #c0a3df;
    --accent-strong: #a77bc1;
    --accent-grad: linear-gradient(180deg, #7a4a92, #581782);
    --accent-ink: #ffffff;
    --accent-soft: #2a1f3b;
    --danger: #ff82a3;
    --danger-soft: #341a24;
    --ok: #7dbfba;
    --warn: #e7a93a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.5);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --glow-cta: 0 6px 20px rgba(40,0,70,.5);
    --glow-cta-strong: 0 10px 28px rgba(40,0,70,.6);
  }
}

/* Manual theme override from the header toggle. Persisted per device; wins over
   the OS setting. The dark values below mirror the media query block above —
   keep the two in sync. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15111b;
  --bg-grad:
    radial-gradient(1100px 620px at 100% -10%, #2a1d3c 0%, rgba(42,29,60,0) 55%),
    radial-gradient(900px 520px at -10% 2%, #16242a 0%, rgba(22,36,42,0) 55%);
  --panel: #1d1726;
  --panel-2: #241d2f;
  --panel-3: #2c2438;
  --text: #ece7f2;
  --muted: #b6abc4;
  --faint: #8a7e99;
  --border: rgba(199,173,215,.14);
  --border-strong: rgba(199,173,215,.24);
  --accent: #c0a3df;
  --accent-strong: #a77bc1;
  --accent-grad: linear-gradient(180deg, #7a4a92, #581782);
  --accent-ink: #ffffff;
  --accent-soft: #2a1f3b;
  --danger: #ff82a3;
  --danger-soft: #341a24;
  --ok: #7dbfba;
  --warn: #e7a93a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.5);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --glow-cta: 0 6px 20px rgba(40,0,70,.5);
  --glow-cta-strong: 0 10px 28px rgba(40,0,70,.6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Display type (Sora) for headings and the wordmark, à la Flomation. */
h1, h2, h3,
.login-title, .items-head h2, .diag-head h2 {
  font-family: var(--display);
  letter-spacing: -.02em;
  line-height: 1.15;
}

.container {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px 64px;
}

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

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 820px;
  margin: 0 auto;
  padding: 16px;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-logo { width: 26px; height: 26px; color: var(--accent); }
.brand-name { font-family: var(--display); font-weight: 700; font-size: 1.18rem; letter-spacing: -.01em; }

.header-right { display: flex; align-items: center; gap: 8px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
/* `display: flex` above would otherwise defeat the `hidden` attribute, leaking
   the signed-in controls onto the login screen. */
.header-actions[hidden] { display: none; }
#btn-theme { flex: none; }
.space-badge {
  font-family: var(--mono);
  font-size: .82rem;
  background: var(--panel-3);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 9px;
  border-radius: 999px;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 3px transparent; }
.conn-ok { background: var(--ok); }
.conn-warn { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.conn-idle { background: var(--faint); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-weight: 600;
  line-height: 1;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .05s ease, color .12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .icon { width: 17px; height: 17px; }

.btn-primary { background: var(--accent-grad); border-color: transparent; color: var(--accent-ink); box-shadow: var(--glow-cta); }
.btn-primary:hover { filter: brightness(1.05); box-shadow: var(--glow-cta-strong); }
.btn-primary:active { filter: brightness(.97); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-block { width: 100%; justify-content: center; padding: 12px; font-size: 1.02rem; }
.btn-sm { padding: 6px 10px; font-size: .85rem; border-radius: 8px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-icon { padding: 8px; }
.btn-danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.btn.is-ok { color: var(--ok); border-color: var(--ok); }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  color: var(--accent-ink); animation: spin .7s linear infinite;
  top: calc(50% - 8px); left: calc(50% - 8px);
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon { width: 18px; height: 18px; display: inline-block; vertical-align: middle; flex: none; }

.linklike {
  background: none; border: 0; padding: 0;
  color: var(--accent); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.linklike:hover { filter: brightness(1.08); }

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

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

/* ---------- Login ---------- */
.login-card { max-width: 440px; margin: 6vh auto 0; }
.login-title { margin: 0 0 4px; font-size: 1.6rem; font-weight: 700; }
.login-sub { margin: 0 0 18px; color: var(--muted); font-size: .95rem; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--panel-3);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 18px;
}
.tab {
  flex: 1;
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; padding: 9px; border-radius: 7px; cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.tab.is-active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }

.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.field .muted { color: var(--faint); font-weight: 400; }

input[type="text"], input[type="password"], input[type="number"], textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--panel);
}

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input { padding-right: 62px; }
.reveal {
  position: absolute; right: 6px;
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; padding: 6px 8px; border-radius: 6px;
}
.reveal:hover { color: var(--text); background: var(--panel-3); }

.hint { margin: 6px 0 0; font-size: .82rem; color: var(--faint); }
.hint code, code {
  font-family: var(--mono); font-size: .85em;
  background: var(--panel-3); padding: 1px 5px; border-radius: 5px;
}

.form-error {
  margin: 0 0 14px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: .9rem;
}

.login-foot { margin: 16px 0 0; text-align: center; font-size: .9rem; }

/* Protection mode selector */
.field-label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.seg {
  display: flex; gap: 4px;
  background: var(--panel-3); padding: 4px; border-radius: 10px;
}
.seg-opt {
  flex: 1; position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px; border-radius: 7px; cursor: pointer;
  font-weight: 600; font-size: .9rem; color: var(--muted);
  transition: background .12s ease, color .12s ease;
}
.seg-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg-opt:has(input:checked) { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm); }
.seg-opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Key reveal / copy rows */
.key-reveal { margin-top: 6vh; }
.key-warn { color: var(--danger); }
.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row input {
  flex: 1; min-width: 0;
  font-family: var(--mono); font-size: .85rem;
}
.copy-row .btn { flex: none; }
@media (max-width: 560px) {
  .copy-row { flex-direction: column; }
  .copy-row .btn { justify-content: center; }
}

/* ---------- Compose ---------- */
.compose { margin-top: 8px; }

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 26px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-icon { width: 34px; height: 34px; color: var(--accent); margin-bottom: 6px; }
.dropzone-main { margin: 0; font-weight: 600; }
.dropzone-sub { margin: 4px 0 0; color: var(--faint); font-size: .85rem; }
.file-btn { cursor: pointer; }

.text-send { margin-top: 16px; }
textarea { resize: vertical; min-height: 72px; }
.compose-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 10px;
}
.text-meta { font-size: .82rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.text-meta.over { color: var(--danger); font-weight: 600; }

.settings { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.settings > summary {
  cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--muted);
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
}
.settings > summary::-webkit-details-marker { display: none; }
.settings > summary::before { content: "▸"; color: var(--faint); transition: transform .12s ease; display: inline-block; }
.settings[open] > summary::before { transform: rotate(90deg); }
.settings-body { padding-top: 12px; }
.field.inline { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.field.inline > label { margin: 0; }
.field.inline input[type="number"] { width: 120px; }
.field.checkbox > label { display: inline-flex; align-items: center; gap: 9px; font-weight: 500; }
.field.checkbox input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Uploads ---------- */
.uploads { margin-top: 8px; display: grid; gap: 10px; }
.uploads:empty { margin-top: 0; }
.upload {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  transition: opacity .35s ease, border-color .2s ease;
}
.upload.is-error { border-color: var(--danger); }
.upload.is-done { border-color: var(--ok); }
.upload.fade { opacity: 0; }
.up-head { display: flex; align-items: center; gap: 9px; }
.up-ic { color: var(--accent); flex: none; }
.up-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.up-size { color: var(--faint); font-size: .82rem; font-variant-numeric: tabular-nums; }
.up-head .btn { margin-left: auto; }
.bar {
  height: 7px; background: var(--panel-3); border-radius: 999px;
  overflow: hidden; margin: 10px 0 6px;
}
.bar-fill { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .18s ease; }
.is-done .bar-fill { background: var(--ok); }
.is-error .bar-fill { background: var(--danger); }
.up-foot { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.is-error .up-status { color: var(--danger); }

/* ---------- Items ---------- */
.items-section { margin-top: 24px; }
.items-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.items-head h2 { margin: 0; font-size: 1.1rem; }
.items-count { color: var(--faint); font-size: .85rem; }

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.empty {
  text-align: center; color: var(--faint);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 32px 16px; margin: 0;
}

.item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
}
.item-head { display: flex; align-items: flex-start; gap: 11px; }
.item-kind {
  flex: none; width: 34px; height: 34px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.item-kind .icon { width: 18px; height: 18px; }
.kind-text { background: var(--accent-soft); color: var(--accent); }
.kind-file { background: var(--panel-3); color: var(--muted); }
.item-title-wrap { min-width: 0; flex: 1; }
.item-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { display: block; font-size: .8rem; color: var(--faint); font-variant-numeric: tabular-nums; margin-top: 2px; }

.item-body { margin: 10px 0 0; }
.item-body:empty { margin: 0; }
.text-preview {
  font-size: .9rem; color: var(--muted);
  white-space: pre-wrap; word-break: break-word;
  max-height: 4.5em; overflow: hidden; position: relative;
}
.text-full {
  font-family: var(--mono); font-size: .85rem; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; margin: 0;
  max-height: 340px; overflow: auto;
}
.item-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Undecryptable item (wrong key) */
.item.is-locked { border-color: var(--border-strong); opacity: .9; }
.item-locked-note {
  font-size: .88rem; color: var(--danger);
  display: inline-flex; align-items: center; gap: 6px;
}
.text-encrypted { font-size: .88rem; color: var(--faint); font-style: italic; }

/* ---------- Diagnostics dialog ---------- */
dialog.diag {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}
dialog.diag::backdrop { background: rgba(10,16,24,.55); backdrop-filter: blur(2px); }
.diag-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel);
}
.diag-head h2 { margin: 0; font-size: 1.08rem; display: inline-flex; align-items: center; gap: 8px; }
.diag-head h2 .icon { color: var(--accent); }
.diag-body { padding: 18px; overflow: auto; max-height: calc(100vh - 140px); }
.diag-intro { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }
.diag-actions { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.diag-progress { color: var(--faint); font-size: .85rem; }

.diag-output { display: grid; gap: 16px; margin-top: 8px; }
.diag-sec { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--panel-2); }
.diag-sec h3 { margin: 0 0 8px; font-size: .95rem; }
.diag-row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-top: 1px solid var(--border); font-size: .88rem; }
.diag-row:first-of-type { border-top: 0; }
.diag-k { color: var(--muted); }
.diag-v { text-align: right; word-break: break-word; }
.diag-v.mono { font-family: var(--mono); font-size: .82rem; }
.diag-headers { margin-top: 8px; }
.diag-headers summary { cursor: pointer; color: var(--accent); font-size: .85rem; font-weight: 600; }
.diag-summary { background: var(--accent-soft); border-color: var(--accent); }
.diag-summary p { margin: 0 0 7px; font-size: .9rem; }
.diag-apply { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.diag-fail { color: var(--danger); font-weight: 600; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: grid; gap: 8px; z-index: 50; width: max-content; max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: .9rem; font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); transition: opacity .25s ease, transform .25s ease;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--danger); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .app-header { flex-wrap: wrap; }
  .header-actions { width: 100%; }
  .header-actions .btn span { display: none; }  /* icon-only header buttons on small screens */
  .space-badge { max-width: none; flex: 1; }
  .card { padding: 18px; }
  .login-card { margin-top: 3vh; }
  .compose-actions { flex-direction: column-reverse; align-items: stretch; }
  .compose-actions .btn { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
