:root {
  --navy: #0a1a2e;
  --navy-2: #13294a;
  --red: #be1828;
  --blue: #1b5fa8;
  --blue-soft: #e8f0fa;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #dde2ea;
  --ink: #111827;
  --muted: #4b5563;
  --ok: #146c43;
  --ok-soft: #e3f4ea;
  --warn: #8a5300;
  --warn-soft: #fdf1dc;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(10, 26, 46, .06), 0 4px 14px rgba(10, 26, 46, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Arial, sans-serif; }
[hidden] { display: none !important; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
a { color: var(--blue); }
small { color: var(--muted); font-weight: 400; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.fine { font-size: 13px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-family: inherit; font-weight: 600; font-size: 14px; line-height: 1; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: #b8c1cf; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: #a3121f; }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }
.btn:focus-visible, .nav:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .drop:focus-visible, .row:focus-visible { outline: 3px solid #7fb0e8; outline-offset: 2px; }
.link { color: #fff; font-size: 14px; }

/* ---- sign in ---- */
.signin, body.center { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 20% -10%, #1d3a64 0%, var(--navy) 55%); }
.signin-card, .card.narrow { width: 100%; max-width: 420px; background: #fff; border-radius: 16px; padding: 36px 32px; text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.signin-card h1, .card.narrow h1 { font-size: 26px; margin: 14px 0 8px; }
.signin-card h1 span, .brand span { color: var(--red); }
.signin-card p { color: var(--muted); margin: 0 0 22px; }
.btn.ms { width: 100%; min-height: 46px; font-size: 15px; background: #fff; border-color: #8c8c8c; }
.btn.ms:hover { background: #f3f3f3; }
.signin-card .fine { margin: 18px 0 0; }
.card.narrow p { color: var(--muted); }
.card.narrow .btn { margin-top: 8px; }

/* ---- layout ---- */
.app { display: grid; grid-template-columns: 236px 1fr; grid-template-rows: 60px 1fr; height: 100vh; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 20px; padding: 0 20px; background: var(--navy); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 17px; white-space: nowrap; }
.brand span { color: #ff6b77; }
.org { flex: 1; display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.org span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org select { background: var(--navy-2); color: #fff; border: 1px solid #39537a; border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 14px; max-width: 260px; }
.user { display: flex; align-items: center; gap: 16px; font-size: 14px; color: #d6deea; white-space: nowrap; }

.side { padding: 18px 14px; border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.send-btn { margin-bottom: 14px; min-height: 44px; }
.nav { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav:hover { background: var(--bg); }
.nav.on { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.count { background: var(--red); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 1px 8px; min-width: 22px; text-align: center; }
.numbers { margin-top: auto; padding: 14px 12px 4px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.numbers b { display: block; color: var(--ink); font-size: 14px; }

.main { overflow: hidden; min-width: 0; }

/* ---- folder ---- */
.folder { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; height: 100%; }
.list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #fff; min-height: 0; }
.list-head { padding: 18px 18px 12px; border-bottom: 1px solid var(--line); display: grid; gap: 12px; }
.list-head input { width: 100%; }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.row { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 12px 18px; border-bottom: 1px solid #edf0f4; cursor: pointer; }
.row:hover { background: #f8fafc; }
.row.on { background: var(--blue-soft); }
.row .doc { width: 40px; height: 48px; border: 1px solid var(--line); border-radius: 4px; background: #fff linear-gradient(#e5e9ef, #e5e9ef) 7px 10px / 22px 2px no-repeat; position: relative; }
.row .doc::after { content: ""; position: absolute; left: 7px; right: 7px; top: 16px; height: 18px; background: repeating-linear-gradient(#e5e9ef 0 2px, transparent 2px 6px); }
.row .who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .who { font-weight: 700; }
.row.unread .doc { border-color: var(--red); box-shadow: inset 3px 0 0 var(--red); }
.row .meta { font-size: 13px; color: var(--muted); }
.row .when { font-size: 13px; color: var(--muted); text-align: right; white-space: nowrap; }
.chip { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 1px 9px; margin-top: 4px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.empty { padding: 28px 18px; color: var(--muted); text-align: center; }

.preview-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.preview-empty { margin: auto; text-align: center; color: var(--muted); opacity: .9; }
.preview-empty img { opacity: .35; }
.pv-head { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-start; justify-content: space-between; padding: 16px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.pv-head h2 { margin: 0 0 4px; font-size: 18px; }
.pv-facts { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 13px; color: var(--muted); }
.pv-facts b { color: var(--ink); font-weight: 600; }
.pv-note { margin: 6px 0 0; }
.pv-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pv-back { display: none; }
.pv-alert { margin: 0; padding: 10px 20px; background: var(--bad-soft); color: var(--bad); border-bottom: 1px solid #f1c7c3; }
.pv-doc { flex: 1; border: 0; width: 100%; background: #525659; }
.pv-msg { margin: auto; padding: 24px; text-align: center; color: var(--muted); max-width: 420px; }

/* ---- forms ---- */
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #b8c1cf; border-radius: 8px; padding: 9px 12px; min-height: 42px; }
textarea { resize: vertical; }
label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 600; }
label.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--red); }

.send, .activity { height: 100%; overflow-y: auto; padding: 28px 24px 48px; }
.send .card { max-width: 720px; margin: 0 auto; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.drop { border: 2px dashed #b8c1cf; border-radius: 12px; padding: 26px 16px; text-align: center; color: var(--muted); cursor: pointer; background: #fafbfd; }
.drop p { margin: 6px 0 0; }
.drop b { color: var(--ink); }
.drop.over { border-color: var(--blue); background: var(--blue-soft); }
.files { list-style: none; margin: -6px 0 0; padding: 0; display: grid; gap: 8px; }
.files li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.files li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files li small { white-space: nowrap; }
.files button { border: 0; background: none; color: var(--bad); font-family: inherit; font-weight: 600; font-size: 13px; cursor: pointer; padding: 4px 6px; }
#coverFields { display: grid; gap: 16px; }
.error { margin: 0; padding: 10px 14px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); font-weight: 500; }
.actions { display: flex; gap: 10px; }

/* ---- activity ---- */
.activity h1 { margin-bottom: 4px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid #edf0f4; vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: #fafbfd; }
td.nowrap { white-space: nowrap; }

.link-btn { margin-left: auto; border-color: transparent; }
.modal { position: fixed; inset: 0; background: rgba(10, 26, 46, .6); display: grid; place-items: center; padding: 24px; z-index: 20; }
.modal-box { width: min(980px, 100%); height: min(92vh, 1100px); background: #fff; border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }
.modal-head { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head .fine { margin: 2px 0 0; }
.modal-doc { flex: 1; border: 0; width: 100%; background: #525659; }
@media (max-width: 900px) { .modal { padding: 0; } .modal-box { height: 100vh; border-radius: 0; } }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); font-weight: 500; z-index: 10; max-width: calc(100% - 32px); }

/* ---- small screens ---- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: auto; min-height: 100vh; }
  .top { flex-wrap: wrap; gap: 6px 16px; padding: 10px 16px; }
  .org { order: 3; flex-basis: 100%; }
  .user { margin-left: auto; }
  .user span { display: none; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .send-btn { margin: 0 6px 0 0; min-height: 40px; }
  .numbers { display: none; }
  .main { overflow: visible; }
  .folder { display: block; height: auto; }
  .list-pane { border-right: 0; }
  .preview-pane { display: none; }
  .folder.viewing .list-pane { display: none; }
  .folder.viewing .preview-pane { display: flex; height: calc(100vh - 120px); }
  .pv-back { display: inline-flex; }
  .send, .activity { padding: 20px 16px 40px; height: auto; }
  .send .card { padding: 20px 16px; }
  .grid2 { grid-template-columns: 1fr; }
}
