/* folkisen mail — interface styles */

:root {
  --brand: #2471a3;
  --brand-strong: #1d5c88;
  --brand-subtle: #e7f1f8;
  --sidebar-header: #6cb6e8;

  --bg: #f4f6f8;
  --card: #ffffff;
  --card-alt: #f8f9fa;
  --border: #dee2e6;
  --border-soft: #e9ecef;
  --text: #212529;
  --muted: #6c757d;
  --danger: #dc3545;
  --danger-subtle: #fdf0f1;
  --ok: #198754;
  --sidebar-bg: #212529;
  --sidebar-text: rgba(255,255,255,.82);
  --sidebar-hover: rgba(255,255,255,.08);
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
}

html[data-theme="dark"] {
  --brand: #4f9bd1;
  --brand-strong: #3d8fc4;
  --brand-subtle: #1c3348;
  --bg: #15171a;
  --card: #1e2126;
  --card-alt: #23272d;
  --border: #363c44;
  --border-soft: #2c3138;
  --text: #dee2e6;
  --muted: #9aa3ad;
  --danger: #e5606f;
  --danger-subtle: #342025;
  --ok: #3fa877;
  --sidebar-bg: #16181c;
  --sidebar-text: rgba(255,255,255,.82);
  --shadow: 0 1px 2px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

a { color: var(--brand); }

/* ---------- layout ---------- */

.app { display: flex; min-height: 100dvh; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
}

.foot {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  padding: .65rem 1.25rem;
  border-top: 1px solid var(--border-soft);
  color: var(--muted);
  font-size: 12.5px;
}
.foot a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--muted); }
.foot a:hover { color: var(--brand); }

/* ---------- sidebar ---------- */

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.06);
}

.brand {
  background: var(--brand);
}

.brand-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .8rem .9rem;
  text-decoration: none;
  color: #fff;
}

.brand-logo {
  width: 33px;
  height: 33px;
  border-radius: 0;
  background: rgba(255,255,255,.14);
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}

.brand-text { font-weight: 300; font-size: 1.05rem; letter-spacing: .01em; }

.mailbox-panel {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .9rem .9rem;
  border-bottom: 1px solid rgba(255,255,255,.09);
}

.mailbox-panel .avatar {
  width: 34px; height: 34px;
  border-radius: 0;
  background: #fff;
  color: #1c2b36;
  display: grid; place-items: center;
  flex-shrink: 0;
  opacity: .9;
}

.mailbox-name {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mailbox-sub { font-size: 11.5px; color: var(--sidebar-header); }

.nav { padding: .55rem .55rem .9rem; overflow-y: auto; }

.nav-header {
  padding: .8rem .75rem .3rem;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--sidebar-header);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .5rem .75rem;
  margin: 1px 0;
  border-radius: 0;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
}

.nav-link svg {
  width: 17px; height: 17px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  opacity: .85;
}

.nav-link:hover { background: var(--sidebar-hover); }

.nav-link[aria-current="page"] {
  background: var(--brand);
  color: #fff;
}

.badge {
  margin-left: auto;
  background: #fff;
  color: #1c2b36;
  border-radius: 0;
  font-size: 11px;
  font-weight: 700;
  padding: 0 .45em;
  min-width: 1.4em;
  text-align: center;
  line-height: 1.5;
}

.sidebar-foot {
  margin-top: auto;
  padding: .7rem .95rem;
  border-top: 1px solid rgba(255,255,255,.09);
  font-size: 12px;
  color: rgba(255,255,255,.55);
  display: flex;
  justify-content: space-between;
  gap: .5rem;
}
.sidebar-foot a { color: rgba(255,255,255,.75); text-decoration: none; }
.sidebar-foot a:hover { color: #fff; }

.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 39;
}

/* ---------- topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: .45rem .9rem;
  min-height: 48px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--card-alt); }
.icon-btn svg {
  width: 19px; height: 19px;
  stroke: currentColor; stroke-width: 1.9; fill: none;
  stroke-linecap: round; stroke-linejoin: round;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: 14px;
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
}
.crumbs .sep { opacity: .5; font-size: 12px; }
.crumbs .here { color: var(--text); font-weight: 500; }
.crumbs a { color: inherit; text-decoration: none; }
.crumbs a:hover { color: var(--brand); }

#themeBtn { margin-left: auto; }

/* ---------- cards, headers ---------- */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.page-head h1 { margin: 0; font-size: 1.3rem; font-weight: 600; }
.page-head .sub { color: var(--muted); font-size: 13.5px; }

.actions { display: flex; gap: .45rem; flex-wrap: wrap; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card-body { padding: 1rem 1.1rem; }
.card-title { font-weight: 600; margin: 0 0 .65rem; font-size: 1rem; }

/* ---------- buttons & forms ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: 0;
  padding: .45rem .85rem;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--card-alt); }
.btn svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-subtle); border-color: var(--danger); }

.btn-sm { padding: .25rem .55rem; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

input[type="text"], input[type="password"], select, textarea {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: .45rem .6rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 0;
  border-color: var(--brand);
}
textarea { width: 100%; resize: vertical; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; }
.field label { font-weight: 500; font-size: 14px; }
.field .hint { color: var(--muted); font-size: 12.5px; }

.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-form input[type="text"] { min-width: 12ch; }

.mono {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px;
}

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th {
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: .45rem .6rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.table tr:last-child td { border-bottom: 0; }

.table tbody tr.rowlink { cursor: pointer; }
.table tbody tr.rowlink:hover { background: var(--card-alt); }

.table .num { font-variant-numeric: tabular-nums; text-align: right; }
.table th.num { text-align: right; }
.table .fit { width: 1%; white-space: nowrap; }
.muted { color: var(--muted); }

/* ---------- stat cards ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0;
  box-shadow: var(--shadow);
  padding: .8rem .95rem;
}
.stat .k { color: var(--muted); font-size: 12.5px; }
.stat .v { font-size: 1.45rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.3; }

/* ---------- mail reading ---------- */

.meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .25rem .9rem;
  font-size: 14px;
}
.meta-grid dt { color: var(--muted); margin: 0; }
.meta-grid dd { margin: 0; overflow-wrap: anywhere; }

.mail-frame {
  width: 100%;
  border: 1px solid var(--border-soft);
  border-radius: 0;
  background: #fff;
  min-height: 300px;
}

.pre-mail {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 400 13.5px/1.55 ui-monospace, "Cascadia Code", Consolas, monospace;
  background: var(--card-alt);
  border: 1px solid var(--border-soft);
  border-radius: 0;
  padding: .65rem .75rem;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--card-alt);
  padding: .25rem .6rem;
  font-size: 13px;
  margin: 0 .4rem .4rem 0;
}

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: min(360px, calc(100vw - 2rem));
}

.toast {
  background: var(--sidebar-bg);
  color: #fff;
  border-radius: 0;
  padding: .6rem .85rem;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  border-left: 3px solid var(--brand);
}
.toast.err { border-left-color: var(--danger); }

/* ---------- misc ---------- */

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2.2rem 1rem;
  font-size: 14px;
}
.empty .big { font-size: 15px; color: var(--text); font-weight: 500; margin-bottom: .3rem; }

.cred-box {
  background: var(--card-alt);
  border: 1px dashed var(--border);
  border-radius: 0;
  padding: .55rem .65rem;
  font-size: 12px;
  word-break: break-all;
  max-height: 110px;
  overflow-y: auto;
}

.spin { animation: spin 1s linear infinite; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }

:where(a, button, input, select, [tabindex]):focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 30px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 1rem .85rem 1.5rem; }
}
