:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1c2129;
  --muted: #6b7380;
  --accent: #1f5fd6;
  --accent-hover: #194fb4;
  --accent-text: #ffffff;
  --accent-soft: #e8effc;
  --own-bubble: #1f5fd6;
  --own-text: #ffffff;
  --other-bubble: #ffffff;
  --danger: #c4372f;
  --ok: #1f9d55;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #232830;
    --border: #2c323b;
    --text: #e6e9ee;
    --muted: #8d95a2;
    --accent: #4d84f0;
    --accent-hover: #6595f3;
    --accent-text: #ffffff;
    --accent-soft: #1d2a42;
    --own-bubble: #2f63c9;
    --own-text: #ffffff;
    --other-bubble: #1f242b;
    --danger: #e5675f;
    --ok: #3ccf7f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 8px 14px; font-weight: 600; font-size: 14px;
  background: var(--surface-2); transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; padding: 11px 14px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; border: 0;
  background: transparent; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 13px; letter-spacing: .5px;
}
.brand-name { font-size: 16px; letter-spacing: -.01em; }
.brand-lg .logo { width: 44px; height: 44px; border-radius: 12px; font-size: 16px; }
.brand-lg .brand-name { font-size: 22px; }

/* Login */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; padding: 32px 28px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.login-card .brand { margin-bottom: 14px; }
.label { font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin: 0; }

/* App layout */
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex: none;
}
.partner { display: flex; align-items: center; gap: 10px; flex: 1; justify-content: center; min-width: 0; }
.partner-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.partner-name { font-weight: 700; }
.partner-status { font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.actions { display: flex; align-items: center; gap: 4px; }
.me { font-size: 13px; color: var(--muted); padding: 0 8px; border-left: 1px solid var(--border); margin-left: 4px; }
.count {
  background: var(--accent); color: #fff; border-radius: 999px;
  font-size: 11px; padding: 1px 7px; line-height: 16px;
}

.body { flex: 1; display: flex; min-height: 0; position: relative; }
.scroller { flex: 1; overflow-y: auto; min-width: 0; }
.thread { max-width: 860px; margin: 0 auto; padding: 16px 16px 8px; }
.older-wrap { display: flex; justify-content: center; margin-bottom: 8px; }

.empty { text-align: center; padding: 80px 16px; color: var(--muted); }
.empty-title { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: 4px; }

/* Messages */
.day { display: flex; align-items: center; gap: 12px; margin: 20px 0 10px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.msg { display: flex; flex-direction: column; align-items: flex-start; margin-top: 3px; }
.msg.own { align-items: flex-end; }
.msg.first { margin-top: 14px; }
.meta { font-size: 12px; color: var(--muted); margin: 0 4px 4px; display: flex; gap: 8px; }
.meta .who { font-weight: 700; color: var(--text); }
.row { display: flex; align-items: center; gap: 6px; max-width: min(78%, 620px); }
.msg.own .row { flex-direction: row-reverse; }
.bubble {
  background: var(--other-bubble); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 12px; min-width: 0;
  box-shadow: var(--shadow); overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.own .bubble { background: var(--own-bubble); color: var(--own-text); border-color: transparent; }
.msg.own .bubble a { color: #fff; }
.bubble.files-only { padding: 6px; }
.text + .attachments { margin-top: 8px; }
.time { font-size: 11px; color: var(--muted); opacity: 0; transition: opacity .15s; white-space: nowrap; }
.msg:hover .time, .msg:hover .del { opacity: 1; }
.del {
  opacity: 0; border: 0; background: transparent; color: var(--muted);
  font-size: 12px; padding: 2px 6px; border-radius: 6px;
}
.del:hover { color: var(--danger); background: var(--surface-2); }

/* Attachments */
.attachments { display: flex; flex-direction: column; gap: 6px; white-space: normal; }
.file {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 10px; background: var(--surface-2); color: var(--text);
  min-width: 240px; max-width: 100%;
}
.msg.own .file { background: rgba(255, 255, 255, .14); color: #fff; }
.ext {
  width: 40px; height: 40px; border-radius: 8px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  font-size: 10px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase;
}
.msg.own .ext { background: rgba(255, 255, 255, .2); color: #fff; }
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 12px; opacity: .75; }
.file.expired { opacity: .55; }
.file.expired .file-name { text-decoration: line-through; }
.dl {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  color: inherit; text-decoration: none;
}
.dl:hover { background: rgba(127, 127, 127, .18); }
.thumb { display: block; border-radius: 10px; overflow: hidden; max-width: 320px; }
.thumb img { display: block; max-width: 100%; max-height: 260px; object-fit: cover; }
.zip-all {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  font-size: 13px; font-weight: 600; text-decoration: none;
  padding: 6px 10px; border-radius: 8px; background: var(--surface-2);
}
.msg.own .zip-all { background: rgba(255, 255, 255, .14); }
.zip-all:hover { filter: brightness(.96); }
.zip-all svg { width: 16px; height: 16px; }

/* Files panel */
.files-panel {
  width: 360px; flex: none; background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 14px 12px 12px 16px; border-bottom: 1px solid var(--border); }
.panel-title { font-weight: 700; }
.panel-sub { font-size: 12px; color: var(--muted); }
.files-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.files-list .file { background: transparent; min-width: 0; }
.files-list .file:hover { background: var(--surface-2); }
.files-empty { color: var(--muted); font-size: 14px; padding: 24px 8px; text-align: center; }

/* Composer */
.composer-wrap { flex: none; background: var(--surface); border-top: 1px solid var(--border); padding: 8px 16px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer-inner { max-width: 860px; margin: 0 auto; }
.typing { font-size: 12px; color: var(--muted); height: 16px; margin: 0 4px 4px; }
.composer {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 5px;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none; background: transparent; color: var(--text);
  font: inherit; padding: 9px 4px; max-height: 180px; min-height: 40px;
}
.composer .btn.primary { height: 40px; }
.hint { font-size: 11px; color: var(--muted); margin: 6px 4px 0; }

.pending { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 280px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 5px 4px 5px 8px; font-size: 13px;
}
.chip .ext { width: 28px; height: 28px; font-size: 9px; border-radius: 6px; }
.chip-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.chip-size { color: var(--muted); white-space: nowrap; }
.chip button { border: 0; background: transparent; color: var(--muted); width: 26px; height: 26px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; }
.chip button:hover { color: var(--danger); background: var(--surface); }
.chip button svg { width: 14px; height: 14px; }
.pending-total { font-size: 12px; color: var(--muted); align-self: center; margin-left: 4px; }

.progress { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.progress-track { flex: 1; height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-text { font-size: 12px; color: var(--muted); min-width: 140px; text-align: right; }

/* Drop overlay */
.drop {
  position: fixed; inset: 0; z-index: 50; padding: 16px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center;
}
.drop-inner {
  width: 100%; max-width: 520px; height: 280px; border: 2px dashed var(--accent); border-radius: 20px;
  background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  color: var(--accent); pointer-events: none;
}
.drop-inner svg { width: 40px; height: 40px; }
.drop-title { font-size: 20px; font-weight: 700; color: var(--text); }
.drop-sub { font-size: 14px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100% - 32px);
}

@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .brand-name, .me, .hide-sm, .hint { display: none; }
  .partner { justify-content: flex-start; }
  .thread { padding: 12px 12px 8px; }
  .row { max-width: 90%; }
  .file { min-width: 0; }
  .files-panel { position: absolute; inset: 0; width: auto; border-left: 0; z-index: 20; }
  .composer-wrap { padding-left: 12px; padding-right: 12px; }
  .time { opacity: 1; }
  .del { opacity: 1; }
}
