/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #e8e3dc;
  --surface:    #f7f4f0;
  --surface2:   #dedad3;
  --border:     #b4ada4;
  --accent:     #8dbdce;
  --accent-dk:  #72aabf;
  --text:       #1e1c1a;
  --text-muted: #635e59;
  --msg-own:    #bedaeb;
  --msg-other:  #dedad3;
  --ok:         #3a7255;
  --err:        #864050;
  --warn:       #6a5018;
  --r:          6px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen { display: none; height: 100vh; height: 100dvh; }
.screen.active { display: flex; }

/* ── Login & Connect screens ──────────────────────────────────────────────── */
#screen-login,
#screen-connect {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.10);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Brand */
.brand { margin-bottom: 2px; }
.brand-name {
  font-size: 22px;
  font-weight: 300;
  letter-spacing: -0.5px;
  color: var(--text);
}
.tagline {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -12px;
}
.size-badge {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
  margin-top: -10px;
}

/* Label row */
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: -10px;
}
.input-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

/* Inputs */
input[type="text"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 14px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus { border-color: var(--accent-dk); }
input[type="text"]::placeholder { color: var(--text-muted); opacity: 1; }
input:disabled { opacity: 0.45; cursor: not-allowed; }

/* Buttons */
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--text);
  border: none;
  border-radius: 4px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dk); }
.btn-primary:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
  transition: color 0.15s;
}
.btn-link:hover { color: var(--text); }

.btn-back {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  align-self: flex-start;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
  transition: color 0.15s;
}
.btn-back:hover { color: var(--text); }

/* Field status */
.field-status {
  font-size: 12px;
  min-height: 14px;
  color: transparent;
  margin-top: -10px;
  transition: color 0.15s;
}
.field-status.ok      { color: var(--ok); }
.field-status.error   { color: var(--err); }
.field-status.waiting { color: var(--warn); }

/* My name box */
.my-name-box {
  background: var(--surface2);
  border-radius: 4px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.my-name {
  font-size: 18px;
  font-weight: 400;
  letter-spacing: -0.3px;
}
.hint {
  font-size: 12px;
  color: var(--text-muted);
}

.separator {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  position: relative;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: -2px 0;
}
.separator::before,
.separator::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 36%;
  height: 1px;
  background: var(--border);
}
.separator::before { left: 0; }
.separator::after  { right: 0; }

/* ── Invitations ──────────────────────────────────────────────────────────── */
.invitations-list {
  display: none;
  flex-direction: column;
  gap: 8px;
}
.invite-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.invite-from {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.invite-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.btn-accept {
  background: var(--accent);
  border: none;
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-accept:hover:not(:disabled) { background: var(--accent-dk); }
.btn-accept:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-decline {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-decline:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-decline:disabled { opacity: 0.38; cursor: not-allowed; }

/* ── Chat screen ──────────────────────────────────────────────────────────── */
#screen-chat {
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.presence-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}
.partner-name { font-size: 15px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 18px; }

.timer {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 600;
  background: var(--surface2);
  padding: 3px 8px;
  border-radius: 4px;
}
.timer.timer-warning { color: var(--err); background: color-mix(in srgb, var(--err) 12%, var(--surface2)); }

.btn-leave {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border);
  transition: color 0.15s;
}
.btn-leave:hover { color: var(--err); }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 3px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg { display: flex; flex-direction: column; max-width: 68%; }
.msg-own   { align-self: flex-end; align-items: flex-end; }
.msg-other { align-self: flex-start; align-items: flex-start; }

.bubble {
  background: var(--msg-other);
  border-radius: 12px 12px 12px 3px;
  padding: 9px 13px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  color: var(--text);
}
.msg-own .bubble {
  background: var(--msg-own);
  border-radius: 12px 12px 3px 12px;
}

.msg-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

.msg-system {
  align-self: center;
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
  margin: 10px 0 6px;
  background: var(--surface2);
  border-radius: 20px;
  padding: 3px 14px;
}

/* File bubbles */
.bubble-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-width: 180px;
}
.file-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.07);
  padding: 3px 6px;
  border-radius: 3px;
  flex-shrink: 0;
  text-transform: uppercase;
}
.file-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.file-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.file-size { font-size: 11px; color: var(--text-muted); }
.btn-dl {
  margin-top: 4px;
  color: var(--accent-dk);
  font-size: 11px;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  display: inline;
}
.btn-dl:hover { color: var(--text); }

/* Drop overlay */
.drop-overlay {
  position: absolute;
  inset: 12px;
  background: rgba(232, 227, 220, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  border: 3px dashed var(--text-muted);
  border-radius: var(--r);
  pointer-events: none;
}
.drop-overlay.visible { display: flex; pointer-events: all; }
.drop-label { font-size: 15px; font-weight: 500; color: var(--text); letter-spacing: 0.2px; }

/* Progress */
.progress-wrap {
  padding: 8px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.progress-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.progress-dir  { font-weight: 600; color: var(--text); }
.progress-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-pct  { font-variant-numeric: tabular-nums; }
.progress-bar {
  height: 3px;
  background: var(--surface2);
  border-radius: 1px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 1px;
  transition: width 0.1s ease;
  width: 0%;
}

/* Footer */
.chat-footer {
  background: var(--surface);
  border-top: 2px solid var(--border);
  padding: 12px 16px 16px;
  flex-shrink: 0;
}
.chat-footer .size-badge {
  display: block;
  text-align: right;
  margin-top: 6px;
  margin-bottom: 0;
}

.input-row { display: flex; gap: 8px; }

.btn-send {
  background: var(--accent);
  border: none;
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  padding: 0 16px;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-send:hover { background: var(--accent-dk); }
.btn-send:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-file {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  padding: 0 12px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-file:hover:not(:disabled) { background: var(--border); color: var(--text); }
.btn-file.p2p-ready { color: var(--ok); border-color: var(--ok); }
.btn-file:disabled { opacity: 0.38; cursor: not-allowed; }

/* ── Scrollbar global ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
