:root {
  --navy: #0B1220;
  --navy-2: #151C2E;
  --bg: #F3F4F7;
  --card: #ffffff;
  --text: #0F172A;
  --muted: #64748B;
  --line: #E8EBF0;
  --mint: #10B981;
  --mint-soft: #D1FAE5;
  --danger: #DC2626;
  --warn: #D97706;
  --gold: #C4A574;
  --gold-soft: #FFF1E6;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, Segoe UI, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
button, input, select, textarea { font-family: inherit; }
a { color: inherit; }
button { cursor: pointer; }

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #F8FAFC 0%, #EEF1F6 100%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  text-align: center;
}
.auth-card img { width: 88px; height: 88px; object-fit: contain; margin-bottom: 8px; }
.auth-card h1 { margin: 8px 0 4px; font-size: 22px; }
.auth-card p { margin: 0 0 24px; color: var(--muted); }
.auth-card .field { text-align: left; margin-bottom: 14px; }
.err { color: var(--danger); font-size: 13px; margin: 8px 0; min-height: 1em; }

.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 88px;
  background: var(--navy);
  color: #CBD5E1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 10px;
}
.sidebar img { width: 48px; height: 48px; object-fit: contain; margin-bottom: 18px; }
.nav-btn {
  width: 48px; height: 48px; border: 0; border-radius: 14px;
  background: transparent; color: #94A3B8; margin: 4px 0;
  display: grid; place-items: center; font-size: 16px;
}
.nav-btn:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-btn.active { background: #fff; color: var(--navy); }
.sidebar .spacer { flex: 1; }

.main { flex: 1; overflow: auto; padding: 28px 32px 48px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.page-head .sub { margin: 4px 0 0; color: var(--muted); }

.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-2); }
.btn-ghost { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: #CBD5E1; }
.btn-danger { background: #FEF2F2; color: #B91C1C; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.metric {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 18px 18px 16px; min-height: 96px;
}
.metric.hero { background: var(--navy); color: #fff; box-shadow: var(--shadow); }
.metric .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.metric.hero .label { color: #94A3B8; }
.metric .value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.03em; }
.metric .hint { font-size: 12px; margin-top: 6px; color: var(--mint); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; }

.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.list-row:last-child { border-bottom: 0; }
.list-row.needs-reply { background: var(--gold-soft); margin: 0; padding: 12px 12px; border-radius: 10px; border-bottom: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--navy); color: #fff; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.right { margin-left: auto; text-align: right; }

.tag {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: #F1F5F9; color: #334155;
}
.tag-new { background: #EEF2FF; color: #1E3A8A; }
.tag-to_reply { background: #FFF1E6; color: #C2410C; }
.tag-in_discussion, .tag-contacted { background: #FFF8E7; color: #B45309; }
.tag-proposal_sent { background: #E8F8F0; color: #047857; }
.tag-awaiting_deposit { background: #F3EFE7; color: #92400E; }
.tag-confirmed { background: var(--mint-soft); color: #065F46; }
.tag-ready { background: #D1FAE5; color: #047857; }
.tag-completed { background: #F1F5F9; color: #475569; }
.tag-cancelled, .tag-lost { background: #FEE2E2; color: #991B1B; }
.tag-off_topic { background: #F1F5F9; color: #64748B; }

.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col {
  min-width: 260px; width: 260px;
  background: var(--tint, #F8FAFC);
  border-radius: 16px; padding: 12px;
  min-height: 70vh;
}
.col-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding: 4px 4px 8px; }
.col-head strong { font-size: 13px; }
.col-count { background: #fff; color: var(--muted); font-size: 11px; padding: 2px 8px; border-radius: 999px; }

.kcard {
  background: #fff; border-radius: 14px; padding: 12px;
  box-shadow: var(--shadow-sm); margin-bottom: 10px; cursor: grab;
}
.kcard:active { cursor: grabbing; }
.kcard .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.kcard .name { font-weight: 700; font-size: 13px; }
.kcard .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kcard .foot { display: flex; gap: 6px; margin-top: 10px; }

.icon-btn {
  width: 28px; height: 28px; border-radius: 8px; border: 0;
  display: grid; place-items: center; font-size: 12px; color: #fff;
}
.ib-phone { background: #F59E0B; }
.ib-mail { background: #F97316; }
.ib-wa { background: #22C55E; }
.ib-del { background: #EF4444; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.search { max-width: 280px; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 9px 12px; color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(11,18,32,.08); }
.field { margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); }
td { padding: 12px; border-bottom: 1px solid #F1F5F9; vertical-align: middle; }
tr:hover td { background: #F8FAFC; cursor: pointer; }

.overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 50; overflow: auto;
}
.overlay.hidden { display: none; }
.modal {
  background: #fff; width: min(820px, 100%);
  border-radius: 18px; box-shadow: var(--shadow); padding: 24px;
  margin-bottom: 40px;
}
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin: 16px 0; }
.tab { border: 0; background: transparent; padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tab.on { color: var(--navy); border-bottom-color: var(--navy); }

.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.check input { width: auto; }

.cal { background: #fff; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-sm); }
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); background: #F8FAFC; }
.cal-head div { padding: 10px; text-align: center; font-size: 11px; color: var(--muted); font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-cell { min-height: 92px; border-top: 1px solid var(--line); border-right: 1px solid var(--line); padding: 8px; }
.cal-cell .d { font-size: 13px; }
.cal-cell .today { background: var(--navy); color: #fff; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; }
.ev { font-size: 11px; padding: 2px 6px; border-radius: 6px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-blocked { background: #D1FAE5; color: #065F46; }
.ev-option { background: #FEF3C7; color: #92400E; }
.ev-ask { background: #DBEAFE; color: #1E3A8A; }

.rule {
  background: #fff; border-radius: 16px; box-shadow: var(--shadow-sm);
  padding: 16px 18px; margin-bottom: 10px;
  display: grid; grid-template-columns: 1fr 90px 1fr auto; gap: 12px; align-items: center;
}
.switch { position: relative; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: #CBD5E1; border-radius: 999px; cursor: pointer;
}
.switch span:before {
  content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .15s;
}
.switch input:checked + span { background: var(--navy); }
.switch input:checked + span:before { transform: translateX(18px); }

#toast { position: fixed; right: 20px; bottom: 20px; z-index: 80; }
.thread {
  max-height: min(52vh, 480px);
  overflow-y: auto;
  padding: 8px 4px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f6f4ef;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.thread-day {
  align-self: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: capitalize;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
}
.bubble-row { display: flex; }
.bubble-row.in { justify-content: flex-start; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: min(86%, 520px);
  padding: 10px 12px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.bubble.in { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.out { background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.bubble-meta { font-size: 11px; opacity: .72; margin-bottom: 4px; }
.bubble-subj { font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.bubble-body { font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.bubble .linkish {
  margin-top: 6px; background: none; border: 0; padding: 0;
  font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; text-decoration: underline;
  color: inherit; opacity: .85;
}
.wait-banner {
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--gold-soft);
  color: #7a4a00;
  font-weight: 700;
  font-size: 14px;
}
.wait-chip {
  display: inline-block; margin-top: 8px; font-size: 11px; font-weight: 700;
  color: #7a4a00; background: var(--gold-soft); border-radius: 999px; padding: 3px 8px;
}
.mail-composer { margin-top: 12px; }

.file-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%;
  background: #fff; color: var(--navy); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 600;
  text-decoration: none; word-break: break-all;
}
.bubble.out .file-chip { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.file-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 0; }

.toast {
  background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 12px;
  margin-top: 8px; box-shadow: var(--shadow);
}

.filters .chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 12px; font-weight: 600; color: var(--muted);
}
.filters .chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }

.alert-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 12px; border-radius: 12px; background: #FFF7ED; margin-bottom: 8px;
}

@media (max-width: 960px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .grid-2, .rule { grid-template-columns: 1fr; }
  .sidebar { width: 68px; }
  .main { padding: 18px 14px 40px; }
}

@media (max-width: 720px) {
  .app-shell { flex-direction: column; height: 100dvh; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    height: 64px;
    padding: 8px 10px;
    order: 2;
    position: sticky;
    bottom: 0;
    z-index: 40;
    justify-content: space-around;
  }
  .sidebar img, .sidebar .spacer { display: none; }
  .nav-btn { width: 42px; height: 42px; margin: 0; }
  .main { order: 1; padding: 14px 12px 20px; overflow: auto; }
  .page-head { flex-direction: column; }
  .overlay { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; min-height: 100%; margin: 0; width: 100%; }
  .cal-cell { min-height: 58px; padding: 4px; }
  .tabs { overflow-x: auto; }
  #toast { left: 12px; right: 12px; bottom: 76px; }
  .empty {
    text-align: center; padding: 28px 16px; color: var(--muted);
  }
}

.lang-toggle { display: inline-flex; gap: 6px; margin-top: 6px; }
.lang-toggle button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 12px; font-weight: 600; color: var(--muted);
}
.lang-toggle button.on { background: var(--navy); color: #fff; border-color: var(--navy); }

.card, .metric, .kcard { animation: rise .22s ease; }
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.empty {
  text-align: center; padding: 22px 12px; color: var(--muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: 6px; }
