/* zalo-archive reader. Look follows the "archive console" mockups: dark top bar, light work area. */

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #16191d;
  --muted: #59616b;
  --line: #e2e5e9;
  --line-soft: #eceef1;
  --bar: #16191d;
  --bar-2: #22272e;
  --bar-line: #3a414a;
  --bar-ink: #c4ccd6;
  --accent: #2b5aa0;
  --accent-ink: #ffffff;
  --self: #e5ecf7;
  --self-line: #cdd9ec;
  --sel: #e9eef6;
  --ok: #1e7a45;
  --ok-bg: #1e3a29;
  --ok-dot: #4fc27a;
  --warn: #8a5300;
  --warn-bg: #fff4dc;
  --warn-line: #f1d08a;
  --bad: #a3242f;
  --bad-bg: #fde8ea;
  --bad-line: #f2b8be;
  --info-bg: #e8f0fb;
  --info-line: #bcd0ee;
  --mark: #fde9a8;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Space Grotesk", var(--sans);
  --r: 6px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 var(--sans); }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
h1, h2 { font-family: var(--display); font-weight: 600; margin: 0; }

#app { min-height: 100%; display: flex; flex-direction: column; }
.shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: var(--r); border: 1px solid #d3d8de; background: var(--panel); text-decoration: none; color: var(--ink); font-size: 13px; font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f6f7f9; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #2c323a; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }

/* ---------- top bar */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 20px; background: var(--bar); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 600; font-size: 17px; color: #fff; text-decoration: none; }
.nav { display: flex; gap: 4px; }
.nav a { color: var(--bar-ink); padding: 8px 12px; border-radius: var(--r); text-decoration: none; font-weight: 500; }
.nav a[aria-current="page"] { color: #fff; background: #2c323a; }
.topsearch { flex: 1 1 220px; display: flex; max-width: 460px; }
.topsearch input { flex: 1; min-width: 0; height: 36px; border: 1px solid var(--bar-line); background: var(--bar-2); color: #fff; border-radius: var(--r); padding: 0 12px; font-size: 13px; }
.topsearch input::placeholder { color: #8b949f; }
.topright { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.signout { height: 36px; padding: 0 12px; background: transparent; color: var(--bar-ink); border: 1px solid var(--bar-line); border-radius: var(--r); font-size: 13px; }
.pill { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; padding: 6px 10px; border-radius: 999px; text-decoration: none; white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.pill.ok { color: #d7f0df; background: var(--ok-bg); } .pill.ok .dot { background: var(--ok-dot); }
.pill.warn { color: #ffe7b8; background: #4a3a14; } .pill.warn .dot { background: #f0b43c; }
.pill.bad { color: #ffd6da; background: #4a1d22; } .pill.bad .dot { background: #f0606d; }
.pill.info { color: #d6e6ff; background: #1d2f4a; } .pill.info .dot { background: #6aa3f0; }

/* ---------- banners */
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 20px; border-bottom: 1px solid; font-size: 13px; }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.banner.bad { background: var(--bad-bg); border-color: var(--bad-line); }
.banner.info { background: var(--info-bg); border-color: var(--info-line); }
.banner .text { flex: 1 1 320px; }
.banner .actions { display: flex; gap: 8px; }

/* ---------- chats layout */
.chats { flex: 1; display: flex; min-height: 0; }
.chatlist { width: 340px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chatlist-head { display: flex; align-items: baseline; justify-content: space-between; padding: 16px 16px 8px; }
.chatlist-head h2 { font-size: 16px; }
.filters { display: flex; gap: 6px; padding: 0 16px 12px; }
.chip { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid #d3d8de; background: var(--panel); font-size: 12px; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.filters .chip.excl { margin-left: auto; }
.chatrow .excl-tag { flex: none; }
.chatrow.excluded .name, .chatrow.excluded .last { color: var(--muted); }

/* ---------- chat menu and exclusion */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 240px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 4px; }
.menu-pop button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 6px; text-align: left; font-size: 13px; color: var(--ink); cursor: pointer; }
.menu-pop button:hover { background: #f3f4f6; }
.menu-pop button.danger { color: var(--bad); }
.convo-head .tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.excl-banner { border-bottom: 1px solid var(--warn-line); }
.gapline { align-self: stretch; display: flex; align-items: center; gap: 12px; color: var(--warn); font-size: 12px; text-align: center; }
.gapline::before, .gapline::after { content: ""; flex: 1; border-top: 1px dashed var(--warn-line); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger:hover { background: #8a1d27; }
.chatlist ul { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-soft); overflow: auto; flex: 1; }
.chatrow { display: flex; gap: 12px; align-items: center; padding: 10px 16px; text-decoration: none; color: var(--ink); border-bottom: 1px solid #f0f2f4; }
.chatrow:hover { background: #f7f8fa; }
.chatrow[aria-current="true"] { background: var(--sel); }
.chatrow .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chatrow .top { display: flex; justify-content: space-between; gap: 8px; }
.chatrow .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatrow .time { font-family: var(--mono); font-size: 11px; color: var(--muted); flex: none; }
.chatrow .last { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.listmore { padding: 12px 16px; text-align: center; }
.empty { padding: 32px 24px; color: var(--muted); text-align: center; }

/* ---------- avatars */
.avatar { position: relative; flex: none; display: inline-block; }
.avatar img, .avatar .initials { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar .initials { display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-family: var(--display); }
.avatar .groupmark { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); border: 2px solid #fff; display: flex; align-items: center; justify-content: center; }

/* ---------- conversation */
.convo { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.convo-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.convo-head h1 { font-size: 18px; }
.convo-head .sub { font-size: 12px; color: var(--muted); }
.convo-head .back { display: none; }
.convo-head .right { margin-left: auto; }
.stream { flex: 1; overflow: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.daysep { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; font-family: var(--mono); }
.daysep::before, .daysep::after { content: ""; flex: 1; height: 1px; background: #dde1e6; }
.sysline { align-self: center; font-size: 12px; color: var(--muted); background: #eaecef; padding: 4px 10px; border-radius: 999px; text-align: center; max-width: 90%; }
.loadrow { display: flex; justify-content: center; }
.convo-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 10px 24px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.convo-foot .lock { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); font-weight: 500; }
.convo-foot .right { margin-left: auto; font-family: var(--mono); }
.placeholder { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); padding: 24px; text-align: center; }

.msg { display: flex; gap: 10px; align-items: flex-start; max-width: min(640px, 92%); }
.msg.self { align-self: flex-end; flex-direction: row-reverse; }
.msg .col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg.self .col { align-items: flex-end; }
.msg .meta { font-size: 12px; color: var(--muted); }
.msg .meta strong { color: var(--ink); font-weight: 600; }
.msg.flash .bubble, .msg.flash .media-box { box-shadow: 0 0 0 3px var(--mark); }
.bubble { background: var(--panel); border: 1px solid var(--line); padding: 9px 12px; border-radius: 4px 10px 10px 10px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.self .bubble { background: var(--self); border-color: var(--self-line); border-radius: 10px 4px 10px 10px; }
.bubble.recalled { border-style: dashed; border-color: #b9c0c8; color: var(--muted); }
.note { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.note.recalled { color: var(--warn); }
.quote { display: flex; flex-direction: column; gap: 2px; border-left: 3px solid #b9c0c8; background: #eef0f3; padding: 6px 10px; border-radius: 4px; font-size: 12px; text-decoration: none; color: var(--ink); max-width: 100%; }
.quote span:last-child { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reactions { display: flex; flex-wrap: wrap; gap: 6px; }
.reaction { display: inline-flex; align-items: center; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; font-size: 12px; }

.media-box { border-radius: 8px; overflow: hidden; border: 1px solid #dde1e6; background: #e6e9ed; display: block; width: fit-content; max-width: 100%; }
.photo { display: block; max-width: min(320px, 100%); height: auto; cursor: zoom-in; }
.photo-btn { padding: 0; border: 0; background: none; display: block; }
video.video { display: block; width: 420px; max-width: 100%; height: auto; max-height: 360px; background: #000; }
.voice { display: flex; align-items: center; gap: 10px; }
.voice audio { height: 36px; max-width: 260px; }
.file { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 240px; max-width: 100%; }
.file .ext { width: 40px; height: 40px; border-radius: 6px; background: #c2384b; color: #fff; font-size: 11px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex: none; font-family: var(--mono); }
.file .info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.file .fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sticker { display: block; width: 120px; height: 120px; object-fit: contain; }
.linkcard { display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel); text-decoration: none; color: var(--ink); max-width: 360px; }
.linkcard .host { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.callline { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.callline.missed { color: var(--bad); border-color: var(--bad-line); }
.mediastate { display: flex; align-items: center; justify-content: center; width: 240px; height: 120px; border-radius: 8px; border: 1px dashed #b9c0c8; color: var(--muted); font-size: 12px; text-align: center; padding: 8px; background: repeating-linear-gradient(45deg, #eceef1 0 10px, #f3f4f6 10px 20px); }
.mediastate.failed { color: var(--bad); border-color: var(--bad-line); }

/* ---------- lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(10, 12, 15, .9); display: flex; flex-direction: column; z-index: 20; }
.lightbox .bar { display: flex; justify-content: flex-end; gap: 8px; padding: 12px; }
.lightbox .pic { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 0 12px 12px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- pages */
.page { flex: 1; overflow: auto; padding: 24px; }
.page-inner { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card h2 { font-size: 15px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-family: var(--mono); font-size: 12px; }
.big { font-family: var(--display); font-size: 32px; font-weight: 600; line-height: 1.1; }
.bar-track { height: 8px; background: #eceef1; border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--ok); border-radius: 999px; }
.bar-fill.warn { background: #d18b16; } .bar-fill.bad { background: var(--bad); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { display: flex; flex-direction: column; } .stat .n { font-family: var(--display); font-size: 22px; font-weight: 600; } .stat .l { font-size: 12px; color: var(--muted); }
.action { display: flex; flex-direction: column; gap: 6px; } .action .hint { font-size: 12px; color: var(--muted); }
.statechip { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; padding: 6px 12px; border-radius: 999px; border: 1px solid; font-weight: 500; }
.statechip.ok { color: var(--ok); border-color: #b5dec4; background: #ecf8f0; }
.statechip.warn { color: var(--warn); border-color: var(--warn-line); background: var(--warn-bg); }
.statechip.bad { color: var(--bad); border-color: var(--bad-line); background: var(--bad-bg); }
.statechip.info { color: var(--accent); border-color: var(--info-line); background: var(--info-bg); }
.profile { flex-direction: row; align-items: center; flex-wrap: wrap; }
.profile h1 { font-size: 22px; }
table.log { width: 100%; border-collapse: collapse; font-size: 13px; }
table.log th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.log td { padding: 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.log td:first-child { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.tablewrap { overflow-x: auto; }

/* ---------- search */
.searchform { display: flex; gap: 8px; }
.searchform input { flex: 1; min-width: 0; height: 40px; border: 1px solid #c9cfd6; border-radius: var(--r); padding: 0 12px; background: var(--panel); font-size: 15px; }
.searchlayout { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.searchfilters { flex: 1 1 220px; max-width: 280px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.field label { color: var(--muted); font-weight: 500; }
.field select, .field input { height: 34px; border: 1px solid #d3d8de; border-radius: var(--r); padding: 0 8px; background: var(--panel); font-size: 13px; min-width: 0; }
.daterow { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.field input[type="date"] { width: 100%; }
.results { flex: 999 1 420px; min-width: 0; }
.results-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.results-head h1 { font-size: 18px; }
.results ol { list-style: none; margin: 0; padding: 0; }
.hit { display: flex; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line-soft); text-decoration: none; color: var(--ink); }
.hit:hover { background: #f7f8fa; }
.hit .body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.hit .top { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); align-items: baseline; }
.hit .top strong { color: var(--ink); font-size: 13px; }
.hit .when { margin-left: auto; font-family: var(--mono); font-size: 11px; }
.hit .snippet { overflow-wrap: anywhere; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line); }
mark { background: var(--mark); color: var(--ink); border-radius: 2px; padding: 0 1px; }

/* ---------- sign-in */
.signin { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 24px 16px; }
.signin form { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.signin h1 { font-size: 22px; }
.signin input { height: 40px; border: 1px solid #c9cfd6; border-radius: var(--r); padding: 0 12px; font-size: 15px; }
.signin .btn { height: 42px; }
.signin .brand { color: var(--ink); }
.error { color: var(--bad); background: var(--bad-bg); border: 1px solid var(--bad-line); border-radius: var(--r); padding: 8px 10px; font-size: 13px; margin: 0; }
code { font-family: var(--mono); font-size: 12px; background: #eef0f3; padding: 1px 5px; border-radius: 4px; }

/* ---------- renew dialog */
dialog.modal { border: 0; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog.modal::backdrop { background: rgba(10, 12, 15, .55); }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.modal-body h2 { font-size: 18px; }
.stagelabel { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.qr { align-self: center; width: 240px; height: 240px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; }
.qrwait { align-self: center; width: 240px; height: 240px; display: flex; align-items: center; justify-content: center; border: 1px dashed #c9cfd6; border-radius: 8px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.steps { margin: 0; padding-left: 20px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- narrow screens: list and chat become separate views */
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .topsearch { order: 5; flex-basis: 100%; max-width: none; }
  .pill .label { display: none; }
  .chatlist { width: 100%; border-right: 0; }
  .chats.open .chatlist { display: none; }
  .chats:not(.open) .convo { display: none; }
  .convo-head { padding: 10px 16px; }
  .convo-head .back { display: inline-flex; }
  .stream { padding: 16px; }
  .convo-foot { padding: 10px 16px; }
  .page { padding: 16px; }
  .banner { padding: 10px 16px; }
  .searchfilters { max-width: none; }
}
