:root {
  --page: #ffffff;
  --side: #fbfbfb;
  --card: #ffffff;
  --hover: #f4f5f7;
  --ink: #1c1d1f;
  --text: #3a3d42;
  --muted: #6f737a;
  --faint: #a0a4ab;
  --line: #ebecef;
  --line-2: #dfe1e5;
  --blue: #266df0;
  --blue-soft: #edf3ff;
  --red: #d93036;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 2px 8px rgba(16, 24, 40, 0.04);
  --shadow-pop: 0 12px 32px rgba(16, 24, 40, 0.12), 0 2px 6px rgba(16, 24, 40, 0.06);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #111214; --side: #151618; --card: #17181b; --hover: #222428;
    --ink: #f1f2f4; --text: #c9ccd1; --muted: #8d9199; --faint: #686c73; --line: #26282c; --line-2: #31343a;
    --blue: #5b8ff6; --blue-soft: #1a2541; --red: #f06a6f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3); --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.5);
  }
}
* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body { margin: 0; background: var(--page); color: var(--text); font: 14px/1.5 var(--font); }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
img { max-width: 100%; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 18px 28px; }
.brand img { display: block; height: 28px; width: auto; }
.text-link, .text-btn { color: var(--muted); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: none; }
.text-btn:hover, .text-link:hover { color: var(--ink); }
.gate-grid { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 420px); gap: 20px; max-width: 920px; margin: 12px auto 48px; padding: 0 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
h1, h2 { color: var(--ink); margin: 0 0 8px; font-weight: 650; letter-spacing: -0.02em; }
h1 { font-size: 32px; }
h2 { font-size: 20px; }
.lead { margin: 0 0 20px; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
label span { font-size: 13px; color: var(--muted); }
input, textarea { width: 100%; border: 1px solid var(--line-2); background: var(--page); border-radius: 10px; padding: 10px 12px; }
textarea { min-height: 180px; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 10px; background: var(--ink); color: var(--page); padding: 10px 16px; font-weight: 600; cursor: pointer; }
.btn:disabled { opacity: 0.6; cursor: default; }
.err { color: var(--red); min-height: 1.2em; margin: 8px 0 0; }
dl { margin: 0; display: grid; gap: 10px; }
dl div { display: grid; grid-template-columns: 140px 1fr; gap: 8px; }
dt { color: var(--muted); }
dd { margin: 0; color: var(--ink); }

#app { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(280px, 380px) minmax(0, 1fr); }
.side { background: var(--side); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 12px; min-height: 100vh; }
.side .brand img { height: 24px; margin: 4px 8px 8px; }
.side .btn { width: 100%; }
#folders { display: flex; flex-direction: column; gap: 2px; }
#folders button { display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left; border: 0; background: transparent; border-radius: 8px; padding: 7px 10px; color: var(--text); cursor: pointer; }
#folders button[aria-current="true"] { background: var(--page); color: var(--ink); box-shadow: 0 0 0 1px var(--line), var(--shadow); }
#folders .count { color: var(--blue); font-weight: 650; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 8px; color: var(--muted); font-size: 13px; }
.list-pane, .read-pane { min-width: 0; min-height: 100vh; }
.list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.pane-head h2 { margin: 0; font-size: 16px; flex: 1; }
.icon-btn { display: none; border: 1px solid var(--line); background: var(--page); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; }
#list { overflow: auto; }
.row { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 12px 16px; cursor: pointer; }
.row:hover, .row[aria-current="true"] { background: var(--hover); }
.row.unseen .subj, .row.unseen .from { font-weight: 700; color: var(--ink); }
.row .from { color: var(--ink); }
.row .subj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { display: flex; justify-content: space-between; gap: 8px; color: var(--faint); font-size: 12px; margin-top: 2px; }
.empty, .muted { color: var(--muted); padding: 28px 16px; }
.read-pane { display: flex; flex-direction: column; }
.letter { display: flex; flex-direction: column; min-height: 100vh; }
.letter-head { padding: 20px 24px 8px; }
.letter-head h2 { font-size: 22px; }
.parties { color: var(--muted); font-size: 13px; display: grid; gap: 2px; margin-top: 8px; }
.letter-actions { display: flex; gap: 14px; padding: 8px 24px 12px; }
.files { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 24px 12px; }
.files a { border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; color: var(--ink); text-decoration: none; }
.body { padding: 8px 24px 32px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.body iframe { width: 100%; min-height: 60vh; border: 0; background: white; }
dialog { width: min(640px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text); box-shadow: var(--shadow-pop); padding: 8px 18px 18px; }
dialog::backdrop { background: rgba(16, 24, 40, 0.35); }
dialog label.grow { flex: 1; }
#compose-form { display: flex; flex-direction: column; min-height: 70vh; }
.actions { display: flex; justify-content: flex-end; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--page); border-radius: 999px; padding: 8px 14px; }

@media (max-width: 860px) {
  .gate-grid { grid-template-columns: 1fr; }
  dl div { grid-template-columns: 1fr; gap: 0; }
  #app { grid-template-columns: 1fr; }
  .side { display: none; position: fixed; inset: 0 auto 0 0; width: min(280px, 86vw); z-index: 5; min-height: 100%; box-shadow: var(--shadow-pop); }
  #app.show-folders .side { display: flex; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .list-pane, .read-pane { min-height: auto; }
  #app.show-letter .list-pane { display: none; }
  #app:not(.show-letter) .read-pane { display: none; }
  .letter { min-height: 100vh; }
}
