:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #161a2b;
  --muted: #667085;
  --line: #e3e7f0;
  --accent: #3b6fe0;
  --accent-text: #ffffff;
  --bad: #d9455f;
  --warn: #b86a12;
  --ok: #238a55;
  --chip: #eaeef8;
  --shadow: 0 1px 2px rgba(19, 26, 74, 0.08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1128;
    --surface: #151a3a;
    --text: #e8ebf7;
    --muted: #9aa3c4;
    --line: #262d57;
    --accent: #6c93f0;
    --accent-text: #0d1128;
    --bad: #ff7a90;
    --warn: #f0a14d;
    --ok: #55d391;
    --chip: #1d2450;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; max-width: 100%; overflow-x: hidden; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.shell { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; background: var(--bg); }
.top { display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line); background: var(--surface); }
.top h1 { margin: 0; font-size: 18px; }
#view { flex: 1; min-width: 0; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 24px; }

.bottom { display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid var(--line); background: var(--surface); padding-bottom: env(safe-area-inset-bottom); }
.bottom button { background: none; border: 0; padding: 8px 2px 6px; min-height: 56px; color: var(--muted); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.bottom button .ico { font-size: 20px; line-height: 1; }
.bottom button.active { color: var(--accent); font-weight: 600; }
.bottom button.compose .ico { background: var(--accent); color: var(--accent-text); border-radius: 50%; width: 38px; height: 38px; display: grid; place-items: center; font-size: 18px; margin-top: -10px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); }

.icon-btn { background: none; border: 0; font-size: 20px; padding: 8px; min-width: 44px; min-height: 44px; cursor: pointer; border-radius: 10px; }
.icon-btn:active { background: var(--chip); }

/* Fara derulare laterala nicaieri: coloanele de grid sunt limitate (minmax(0,1fr)), chip-urile trec pe rand nou. */
.filters { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-bottom: 10px; }
.chips, .chips.scroll { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.chip { flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; border: 1px solid var(--line); background: var(--chip); border-radius: 999px; padding: 6px 12px; min-height: 36px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
input[type="search"], .filters select, .field input, .field select, .field textarea, .login input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 11px 12px; min-height: 46px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.item { min-width: 0; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); cursor: pointer; }
.item:active { background: var(--chip); }
.item .row1 { display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.item .who { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item time { font-size: 12px; color: var(--muted); flex: none; }
.item .subj { font-weight: 600; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .snip { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.item.unread .who, .item.unread .subj { color: var(--text); }
.item.unread { border-left: 4px solid var(--accent); }
.badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.badge { font-size: 11px; border-radius: 6px; padding: 2px 7px; background: var(--chip); color: var(--muted); }
.badge.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }
.more { width: 100%; margin-top: 10px; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 14px; min-height: 44px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; }

.page { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.page .bar { display: flex; align-items: center; gap: 4px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; border-bottom: 1px solid var(--line); background: var(--surface); }
.page .bar .title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page .pbody { flex: 1; min-width: 0; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px 24px; overflow-wrap: anywhere; }
.page .actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.page .actions .btn { flex: 1 1 auto; }

.msg h2 { margin: 0 0 8px; font-size: 20px; line-height: 1.25; word-break: break-word; }
.meta { font-size: 14px; color: var(--muted); display: grid; gap: 2px; margin-bottom: 10px; word-break: break-word; }
.body { white-space: pre-wrap; word-break: break-word; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 15px; }
.section { margin-top: 18px; }
.section h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.note { font-size: 13px; color: var(--muted); margin: 8px 0; }

.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.field textarea { min-height: 220px; resize: vertical; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 8px; box-shadow: var(--shadow); }
.card .k { color: var(--muted); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; text-align: center; }
.grid2 .n { font-size: 20px; font-weight: 700; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.row > :first-child { min-width: 0; overflow-wrap: anywhere; }
.row > :last-child { flex: none; }
.row:last-child { border-bottom: 0; }

#toasts { position: fixed; left: 0; right: 0; bottom: calc(70px + env(safe-area-inset-bottom)); display: grid; gap: 8px; justify-items: center; pointer-events: none; z-index: 50; padding: 0 12px; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 14px; display: flex; gap: 12px; align-items: center; max-width: min(520px, 100%); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); overflow-wrap: anywhere; }
.toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 6px; min-height: 36px; }

.login { max-width: 380px; margin: 0 auto; padding: calc(48px + env(safe-area-inset-top)) 20px 24px; display: grid; gap: 14px; }
.login h1 { margin: 0 0 4px; font-size: 24px; }
.login .err { color: var(--bad); font-size: 14px; min-height: 20px; }
