/* Velora Inbox – style. Kolory i proporcje wg makiety v2. */
:root {
  --bg: #EDF0F5;
  --surface: #FFFFFF;
  --text: #16203A;
  --muted: #6A7389;
  --line: #E1E5EE;
  --navy: #24357A;
  --navy-600: #1C2A63;
  --sel: #E6EAF8;
  --ok: #1F9E86;
  --danger: #C8423A;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 14px;
  --display: 'Bricolage Grotesque', 'Instrument Sans', system-ui, sans-serif;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --rail-w: 248px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Widoczny focus tylko z klawiatury */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; border-radius: 6px; }

/* ---------- Przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-600); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: #C9D0DE; }
.btn-onDark { background: #fff; color: var(--text); }
.btn-onDark:hover { background: var(--sel); }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  border: 0; background: transparent; color: var(--text); flex: none;
}
.icon-btn:hover { background: rgba(36, 53, 122, .07); }
.icon-btn svg { width: 20px; height: 20px; }
.link-btn { border: 0; background: none; padding: 4px 0; color: var(--muted); font-size: 12.5px; }
.link-btn:hover { color: var(--text); text-decoration: underline; }

/* ---------- Logowanie ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 32px 28px 24px;
}
.brand--center { justify-content: center; margin-bottom: 28px; }
.field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.login-card input {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px;
}
.login-card input:focus-visible { outline: 2px solid var(--navy); outline-offset: 0; }
.login-error { min-height: 20px; margin: 8px 0 12px; color: var(--danger); font-size: 13px; }
.login-note { margin: 14px 0 0; color: var(--muted); font-size: 12.5px; text-align: center; }

/* ---------- Marka ---------- */
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-mark--sm { width: 24px; height: 24px; }
.brand-name { font: 700 17px/1.1 var(--display); letter-spacing: -.01em; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- Układ ---------- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(360px, 1fr) minmax(420px, 1.25fr);
  height: 100vh; height: 100dvh;
  gap: 12px; padding: 12px;
}
.col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); min-height: 0; overflow: hidden; }

/* ---------- Lewa szyna ---------- */
.rail { display: flex; flex-direction: column; gap: 26px; padding: 14px 6px 6px 8px; min-height: 0; overflow-y: auto; }
.rail .brand { padding: 4px 6px; }
.rail-close { display: none; margin-left: auto; }
.rail-title { color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 0 10px 8px; }
.mbx-list { display: flex; flex-direction: column; gap: 2px; }
.mbx {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 40px; padding: 0 10px;
  border: 0; border-radius: 10px; background: transparent; text-align: left; font-weight: 500;
}
.mbx:hover { background: rgba(255,255,255,.6); }
.mbx[aria-checked="true"] { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); font-weight: 600; }
.mbx-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.mbx-dot--all { background: conic-gradient(var(--navy) 0 50%, #8F9BC7 0); }
.mbx-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mbx-count { font: 600 14px var(--display); color: var(--muted); font-variant-numeric: tabular-nums; }
.mbx[aria-checked="true"] .mbx-count { color: var(--text); }
.mbx-warn { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); flex: none; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px; cursor: pointer; font-weight: 500; }
.switch-row--inline { padding: 0; font-weight: 500; color: var(--muted); font-size: 13px; }
.switch {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none; cursor: pointer;
  width: 34px; height: 20px; border-radius: 20px; background: #C9D0DE; position: relative; transition: background .15s;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(22,32,58,.2);
}
.switch:checked { background: var(--navy); }
.switch:checked::after { transform: translateX(14px); }
.switch:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; border-radius: 20px; }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.sync-tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; font-size: 12.5px; }
.sync-line { display: flex; align-items: flex-start; gap: 8px; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-top: 5px; flex: none; }
.sync-dot--busy { background: var(--navy); animation: pulse 1.2s ease-in-out infinite; }
.sync-dot--err { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }
.sync-main { font-weight: 600; }
.sync-sub { color: var(--muted); margin-top: 2px; }
.sync-err { color: var(--danger); margin-top: 8px; }
.sync-err b { font-weight: 600; }
.sync-progress { height: 4px; background: var(--line); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.sync-progress > i { display: block; height: 100%; background: var(--navy); border-radius: 4px; transition: width .4s; }
.sync-refresh { margin-top: 10px; height: 32px; font-size: 13px; width: 100%; }
.rail-links { display: flex; justify-content: space-between; padding: 0 6px 4px; }

/* ---------- Nadawcy ---------- */
.senders { display: flex; flex-direction: column; }
.topbar { display: none; }
.summary { padding: 22px 22px 14px; }
.summary-title { margin: 0; font: 700 34px/1.05 var(--display); letter-spacing: -.02em; }
.summary-title .num { font-variant-numeric: tabular-nums; }
.summary-lede { margin: 8px 0 16px; color: var(--muted); font-size: 14px; max-width: 46ch; }
.stack { display: flex; height: 10px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--surface); }
.stack > i { display: block; height: 100%; min-width: 3px; transition: flex-grow .3s; }
.stack-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 10px; color: var(--muted); font-size: 12.5px; }
.stack-legend span { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; }
.stack-legend i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.stack-legend b { font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 18ch; }
.chips { display: none; }

.toolbar { display: flex; gap: 8px; padding: 0 22px 12px; border-bottom: 1px solid var(--line); }
.search { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--muted); }
.search:focus-within { border-color: var(--navy); }
.search svg { width: 16px; height: 16px; flex: none; }
.search input { flex: 1; min-width: 0; width: 100%; border: 0; background: none; height: 100%; color: var(--text); font-size: 14px; }
.search input:focus-visible { outline: none; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.sort select {
  height: 38px; padding: 0 30px 0 12px; border: 1px solid var(--line); border-radius: 10px; font-weight: 500;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236A7389' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 11px center;
  appearance: none; -webkit-appearance: none; cursor: pointer;
}

.sender-list { list-style: none; margin: 0; padding: 6px 10px 16px; overflow-y: auto; flex: 1; min-height: 0; }
.sender {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--r); cursor: pointer; user-select: none;
}
.sender:hover { background: #F5F7FB; }
.sender[aria-selected="true"] { background: var(--sel); }
.avatar {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  background: var(--bg); color: var(--muted); font: 600 14px var(--display); letter-spacing: .02em;
}
.sender[aria-selected="true"] .avatar { background: #fff; color: var(--navy); }
.sender-main { min-width: 0; }
.sender-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sender-addr { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini { display: flex; height: 4px; margin-top: 6px; border-radius: 3px; overflow: hidden; gap: 1px; max-width: 160px; }
.mini i { display: block; height: 100%; }
.sender-count { font: 700 18px var(--display); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.skeleton { height: 58px; margin: 4px 0; border-radius: var(--r); background: linear-gradient(90deg, #F3F5F9, #EBEEF4, #F3F5F9); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Maile ---------- */
.mails { display: flex; flex-direction: column; position: relative; }
.mails-placeholder { margin: auto; text-align: center; color: var(--muted); padding: 24px; max-width: 280px; }
.placeholder-mark svg { width: 44px; height: 44px; margin: 0 auto 14px; opacity: .25; }
.mails-inner { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.mails-head { display: flex; align-items: flex-start; gap: 14px; padding: 22px 22px 12px; }
.back-btn { display: none; }
.mails-who { flex: 1; min-width: 0; }
.mails-name { margin: 0; font: 700 24px/1.15 var(--display); letter-spacing: -.015em; overflow-wrap: anywhere; }
.mails-addr { color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
.mails-split { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.mails-split span { display: inline-flex; align-items: center; gap: 6px; }
.mails-split i { width: 8px; height: 8px; border-radius: 50%; }
.mails-split b { color: var(--text); font-weight: 600; }
.mark-all svg { width: 16px; height: 16px; }
.mails-opts { display: flex; align-items: center; gap: 14px; padding: 0 22px 12px; border-bottom: 1px solid var(--line); min-height: 33px; }
.mails-note { color: var(--muted); font-size: 12.5px; }

.mail-scroll { flex: 1; overflow-y: auto; min-height: 0; padding: 4px 10px 96px; }
.mail-group { padding: 16px 12px 6px; color: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.mail {
  display: grid; grid-template-columns: 22px 8px 1fr auto; align-items: start; gap: 12px;
  padding: 10px 12px; border-radius: var(--r); cursor: default; transition: background .12s, opacity .2s;
}
.mail:hover { background: #F5F7FB; }
.mail.is-selected { background: var(--sel); }
.mail.is-read { opacity: .55; }
.mail.is-read .mail-subject { font-weight: 500; }
.mail.is-leaving { opacity: 0; }
.cb {
  appearance: none; -webkit-appearance: none; margin: 1px 0 0; width: 18px; height: 18px; border-radius: 5px;
  border: 1.6px solid #B5BDCD; background: #fff; cursor: pointer; display: grid; place-items: center;
}
.cb:checked { background: var(--navy); border-color: var(--navy); }
.cb:checked::after { content: ''; width: 10px; height: 6px; border: 2px solid #fff; border-top: 0; border-right: 0; transform: translateY(-1px) rotate(-45deg); }
.cb:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.cb:disabled { opacity: .35; cursor: default; }
.mail-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; }
.mail-body { min-width: 0; }
.mail-subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-snippet { color: var(--muted); font-size: 13px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin-top: 1px; overflow-wrap: anywhere; }
.mail-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.mail-time { color: var(--muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mail-preview { border: 0; background: none; padding: 2px 0; color: var(--navy); font-weight: 600; font-size: 12.5px; }
.mail-preview:hover { text-decoration: underline; }
.mail-loading { text-align: center; color: var(--muted); padding: 12px; }
.mail-sentinel { height: 1px; }
.mobile-select-all { display: none; }

/* ---------- Pływający pasek ---------- */
.actionbar {
  position: absolute; z-index: 30; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 18px; border-radius: 14px;
  background: var(--text); color: #fff; box-shadow: 0 10px 30px rgba(22, 32, 58, .28), 0 2px 6px rgba(22, 32, 58, .2);
  animation: rise .18s ease-out; max-width: calc(100vw - 24px);
}
@keyframes rise { from { transform: translate(-50%, 12px); opacity: 0; } }
.actionbar-count { font-weight: 600; white-space: nowrap; }
.actionbar-sep { opacity: .4; }
.actionbar-link { border: 0; background: none; color: #C9D0E8; padding: 6px 2px; font-weight: 500; }
.actionbar-link:hover { color: #fff; text-decoration: underline; }
.actionbar .btn { height: 38px; }
.actionbar :focus-visible { outline-color: #fff; }

/* ---------- Podgląd ---------- */
.preview-scrim { position: fixed; inset: 0; background: rgba(22, 32, 58, .25); z-index: 40; }
.preview {
  position: fixed; z-index: 41; top: 12px; right: 12px; bottom: 12px; width: min(760px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(calc(100% + 24px)); transition: transform .22s ease; visibility: hidden;
}
.preview.is-open { transform: none; visibility: visible; }
.preview-head { display: flex; gap: 10px; padding: 16px 18px 10px; align-items: flex-start; }
.preview-meta { flex: 1; min-width: 0; }
.preview-subject { margin: 4px 0 6px; font: 700 20px/1.2 var(--display); overflow-wrap: anywhere; }
.preview-from { font-weight: 500; overflow-wrap: anywhere; }
.preview-from span { color: var(--muted); font-weight: 400; }
.preview-date { color: var(--muted); font-size: 12.5px; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.preview-date i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.preview-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 0 18px 14px 66px; border-bottom: 1px solid var(--line); }
.preview-atts { color: var(--muted); font-size: 12.5px; }
.preview-body { flex: 1; position: relative; min-height: 0; background: #fff; }
.preview-body iframe { width: 100%; height: 100%; border: 0; display: block; }
.preview-status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: #fff; padding: 24px; text-align: center; }
.preview-status:empty { display: none; }

/* ---------- Okno skrótów, komunikaty ---------- */
.dialog { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px 24px; max-width: 380px; width: calc(100% - 32px); color: var(--text); }
.dialog::backdrop { background: rgba(22, 32, 58, .3); }
.dialog h3 { margin: 0 0 14px; font: 700 19px var(--display); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0 0 18px; }
.keys dd { margin: 0; color: var(--muted); }
kbd { font: 600 12px var(--sans); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; background: var(--bg); }
.toasts { position: fixed; z-index: 60; top: calc(16px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: #fff; padding: 10px 14px; border-radius: 10px; font-weight: 500; animation: rise2 .18s ease-out; }
.toast--err { background: var(--danger); }
.toast--ok { background: var(--ok); }
@keyframes rise2 { from { transform: translateY(-8px); opacity: 0; } }

/* ============ Średnie ekrany: szyna jako szuflada ============ */
@media (max-width: 1180px) {
  .app { grid-template-columns: minmax(340px, 1fr) minmax(400px, 1.2fr); }
  .rail {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; width: 290px; background: var(--bg);
    padding: calc(16px + var(--safe-t)) 12px calc(12px + var(--safe-b)); transform: translateX(-105%); transition: transform .22s ease;
    visibility: hidden;
  }
  .rail.is-open { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(22,32,58,.2); }
  .rail-close { display: inline-grid; }
  .scrim { position: fixed; inset: 0; z-index: 49; background: rgba(22, 32, 58, .25); }
  .topbar { display: flex; align-items: center; gap: 6px; padding: 10px 10px 0; }
  .topbar-brand { flex: 1; display: flex; align-items: center; gap: 8px; font: 700 16px var(--display); }
  .summary { padding-top: 12px; }
  .chips { display: flex; gap: 6px; margin: 14px -22px 0; padding: 0 22px 2px; overflow-x: auto; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip {
    display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px; flex: none;
    border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 500; font-size: 13.5px;
  }
  .chip[aria-checked="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
  .chip b { font: 600 13.5px var(--display); }
  .chip .mbx-dot { width: 8px; height: 8px; }
}

/* ============ Telefon: dwa ekrany ============ */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .app { display: block; padding: 0; height: auto; min-height: 100dvh; }
  .col { border: 0; border-radius: 0; overflow: visible; }
  .senders { min-height: 100dvh; padding-top: var(--safe-t); }
  .sender-list { overflow: visible; padding: 6px 8px calc(24px + var(--safe-b)); }
  .summary { padding: 12px 18px 14px; }
  .summary-title { font-size: 31px; }
  .chips { margin: 14px -18px 0; padding: 0 18px 2px; }
  .sort select { max-width: 9.5em; }
  .toolbar { padding: 0 18px 12px; position: sticky; top: 0; background: var(--surface); z-index: 5; padding-top: 8px; }
  .sender { padding: 10px; grid-template-columns: 44px 1fr auto; }
  .avatar { width: 44px; height: 44px; }
  .sender-count { font-size: 19px; }

  .mails { display: none; }
  .app.show-mails .senders { display: none; }
  .app.show-mails .mails { display: flex; min-height: 100dvh; }
  .mails-head { position: sticky; top: 0; z-index: 5; background: var(--surface); padding: calc(10px + var(--safe-t)) 14px 10px 6px; gap: 6px; flex-wrap: wrap; }
  .back-btn { display: inline-grid; width: 42px; height: 42px; }
  .back-btn svg { width: 22px; height: 22px; }
  .mails-name { font-size: 22px; }
  .mails-who { padding-top: 6px; }
  .mark-all { display: none; }
  .mails-opts { padding: 0 18px 12px; }
  .mail-scroll { overflow: visible; padding: 4px 8px calc(110px + var(--safe-b)); }
  .mail { grid-template-columns: 26px 8px 1fr auto; padding: 12px 10px; gap: 10px; }
  .cb { width: 24px; height: 24px; border-radius: 7px; margin-top: -2px; }
  .cb:checked::after { width: 12px; height: 7px; }
  .mail-preview { padding: 6px 0; font-size: 13px; }
  .mobile-select-all { display: block; padding: 14px 10px 0; }
  .mobile-select-all .btn { height: 48px; font-size: 15px; }
  .actionbar { position: fixed; left: 12px; right: 12px; transform: none; bottom: calc(12px + var(--safe-b)); padding: 10px 10px 10px 16px; flex-wrap: wrap; }
  @keyframes rise { from { transform: translateY(12px); opacity: 0; } }
  .actionbar .btn { order: 5; width: 100%; height: 50px; font-size: 16px; border-radius: 11px; }
  .actionbar-link { margin-left: auto; padding: 8px 4px; }
  .actionbar-sep { display: none; }
  .preview { top: 0; right: 0; bottom: 0; width: 100%; border-radius: 0; border: 0; padding-top: var(--safe-t); padding-bottom: var(--safe-b); }
  .preview-actions { padding-left: 18px; }
  .preview-actions .btn { flex: 1; height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
