:root {
  --tl-navy: #0e2744;
  --tl-navy-deep: #08182c;
  --tl-navy-soft: #16345a;
  --tl-electric: #1e6fff;
  --tl-electric-hover: #155be0;
  --tl-electric-soft: #e8f1ff;
  --tl-white: #ffffff;
  --tl-gray: #f4f6f8;
  --tl-gray-2: #e8edf2;
  --tl-ink: #122033;
  --tl-muted: #5b6b7c;
  --tl-line: #d5dde6;
  --tl-ok: #1b7a4e;
  --tl-warn: #c62828;
  --tl-warn-bg: #fdecea;
  --tl-radius: 12px;
  --tl-radius-sm: 8px;
  --tl-shadow: 0 8px 28px rgba(8, 24, 44, 0.12);
  --tl-font: "IBM Plex Sans", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --sidebar: 340px;
  --infobar: 300px;
  --topbar: 56px;
  --focus: 0 0 0 3px rgba(30, 111, 255, 0.22);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { overflow-x: hidden; }
body {
  margin: 0;
  font-family: var(--tl-font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--tl-ink);
  background: var(--tl-gray);
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--tl-electric); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

.btn, .btn-primary, .btn-ghost, .icon-btn, .send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--tl-radius-sm);
  padding: 0 16px;
  height: 44px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary, .send-btn {
  background: var(--tl-electric);
  color: #fff;
}
.btn-primary:hover, .send-btn:hover { background: var(--tl-electric-hover); }
.btn-primary:focus-visible, .send-btn:focus-visible, .btn-ghost:focus-visible, .icon-btn:focus-visible, .field input:focus, .field textarea:focus, .search-wrap input:focus, .composer textarea:focus {
  outline: none;
  box-shadow: var(--focus);
}
.btn-ghost {
  background: transparent;
  color: inherit;
  border: 1px solid transparent;
}
.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  color: var(--tl-muted);
  border-radius: 10px;
}
.icon-btn:hover { background: var(--tl-gray-2); color: var(--tl-ink); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.is-recording { background: var(--tl-warn-bg); color: var(--tl-warn); }

.field { display: grid; gap: 6px; margin: 0 0 16px; }
.field label, .field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--tl-ink);
}
.field input, .field select, .field textarea, .admin-card input, .admin-card select, .sheet input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--tl-line);
  border-radius: 10px;
  padding: 0 14px;
  background: var(--tl-white);
  color: var(--tl-ink);
}
.field input:hover, .admin-card input:hover { border-color: #b7c3d0; }
.field input:focus, .admin-card input:focus, .admin-card select:focus {
  outline: none;
  border-color: var(--tl-electric);
  box-shadow: var(--focus);
}
.field input.is-invalid, .field input[aria-invalid="true"] {
  border-color: var(--tl-warn);
  box-shadow: 0 0 0 3px rgba(198, 40, 40, 0.12);
}
.field-hint { margin: 0; font-size: 12px; color: var(--tl-muted); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 48px; }
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: var(--tl-muted);
  border-radius: 8px;
  display: grid;
  place-items: center;
}
.pw-toggle:hover { background: var(--tl-gray); color: var(--tl-ink); }
.pw-toggle svg { width: 18px; height: 18px; }
.strength { display: grid; gap: 6px; margin: -6px 0 16px; }
.strength-bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.strength-bars span {
  height: 4px;
  border-radius: 99px;
  background: var(--tl-gray-2);
}
.strength-bars[data-score="1"] span:nth-child(-n+1) { background: #d64545; }
.strength-bars[data-score="2"] span:nth-child(-n+2) { background: #d39b00; }
.strength-bars[data-score="3"] span:nth-child(-n+3) { background: #2f8f5b; }
.strength-bars[data-score="4"] span { background: #1b7a4e; }
.strength-label { font-size: 12px; color: var(--tl-muted); }

.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--tl-warn-bg);
  color: #8e1c1c;
  font-size: 14px;
  font-weight: 500;
  margin: 0 0 18px;
}
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

/* Auth split */
.auth-shell {
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(280px, 0.92fr) minmax(0, 1.08fr);
  background: var(--tl-white);
}
.auth-brand {
  background: var(--tl-navy);
  color: #fff;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}
.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 36px;
}
.brand-mark img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
}
.brand-mark strong {
  display: block;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.brand-mark span {
  display: block;
  font-size: 12px;
  color: rgba(255,255,255,0.62);
  font-weight: 500;
}
.brand-lead {
  margin: 0 0 28px;
  font-size: 22px;
  line-height: 1.35;
  font-weight: 500;
  max-width: 22rem;
}
.brand-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}
.brand-points li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14px;
  color: rgba(255,255,255,0.86);
}
.brand-points svg {
  width: 18px;
  height: 18px;
  flex: none;
  margin-top: 2px;
  color: #7eb0ff;
}
.brand-note {
  margin: 28px 0 0;
  font-size: 13px;
  color: rgba(255,255,255,0.62);
  max-width: 22rem;
}
.brand-foot {
  margin: 40px 0 0;
  font-size: 12px;
  color: rgba(255,255,255,0.45);
}
.auth-main {
  background: var(--tl-gray);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 48px;
  min-width: 0;
}
.auth-card {
  width: 100%;
  max-width: 560px;
  background: var(--tl-white);
  border: 1px solid var(--tl-line);
  border-radius: 16px;
  padding: 36px 40px 40px;
  box-shadow: var(--tl-shadow);
}
.auth-card h1 {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-card .lede {
  margin: 0 0 24px;
  color: var(--tl-muted);
  font-size: 14.5px;
}
.auth-card .btn-primary { width: 100%; height: 48px; margin-top: 8px; font-size: 15px; text-decoration: none; }
.auth-card form { margin: 0; }

.error-page {
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--tl-gray);
}
.error-card {
  width: min(520px, 100%);
  background: #fff;
  border: 1px solid var(--tl-line);
  border-radius: 16px;
  padding: 36px 32px;
  text-align: center;
  box-shadow: var(--tl-shadow);
}
.error-card .mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border-radius: 12px;
}
.error-card h1 { margin: 0 0 8px; font-size: 22px; }
.error-card p { margin: 0 0 20px; color: var(--tl-muted); }
.error-code { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; color: var(--tl-electric); margin-bottom: 8px; }

/* App shell */
.app {
  height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--infobar);
  grid-template-rows: var(--topbar) minmax(0, 1fr);
  background: var(--tl-white);
  overflow: hidden;
}
.topbar {
  grid-column: 1 / -1;
  background: var(--tl-navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 14px;
  gap: 12px;
  min-width: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  min-width: 0;
}
.brand img {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}
.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}
.top-actions #talk-me {
  font-size: 13px;
  color: rgba(255,255,255,0.82);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top-actions a, .top-actions button.top-link {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 7px 12px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  height: auto;
}
.top-actions a:hover { background: rgba(255,255,255,0.16); text-decoration: none; }

.sidebar, .thread, .info {
  background: var(--tl-white);
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.sidebar { border-right: 1px solid var(--tl-line); background: #fbfcfd; }
.info { border-left: 1px solid var(--tl-line); padding: 0; overflow: auto; }
.pane-head {
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--tl-line);
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}
.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--tl-muted);
  pointer-events: none;
}
.search-wrap input, .pane-head input[type="search"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--tl-line);
  border-radius: 10px;
  padding: 0 12px 0 36px;
  background: #fff;
}
.pane-head .send-btn, #talk-new-btn {
  height: 40px;
  padding: 0 12px;
  flex: none;
}
.list { overflow: auto; flex: 1; }
.conv {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--tl-line);
  align-items: center;
}
.conv.active { background: var(--tl-electric-soft); }
.conv:hover { background: #eef3f8; }
.conv.active:hover { background: var(--tl-electric-soft); }
.conv h3 { margin: 0 0 2px; font-size: 14px; font-weight: 600; }
.conv p {
  margin: 0;
  color: var(--tl-muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tl-navy);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex: none;
  position: relative;
  letter-spacing: 0.02em;
}
.avatar.sm { width: 32px; height: 32px; font-size: 11px; }
.avatar .dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
}
.badge {
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--tl-electric);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex: none;
}
.list-error { padding: 28px 16px; }
.list-error p { margin: 0 0 12px; }
.list-error .btn-primary {
  width: auto;
  min-width: 160px;
  height: 40px;
  margin: 0 auto;
}
.empty-state, .loading-state {
  padding: 32px 20px;
  text-align: center;
  color: var(--tl-muted);
  font-size: 14px;
}
.empty-state svg, .thread-empty svg {
  width: 40px;
  height: 40px;
  margin: 0 auto 12px;
  color: #9aabbc;
}
.thread-empty {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--tl-muted);
  padding: 24px;
}
.thread-empty h2 { margin: 8px 0 6px; color: var(--tl-ink); font-size: 18px; }
.messages {
  flex: 1;
  overflow: auto;
  padding: 20px 22px;
  background: var(--tl-gray);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bubble {
  max-width: min(72%, 640px);
  background: #fff;
  border-radius: 14px 14px 14px 4px;
  padding: 10px 12px 8px;
  margin: 4px 0;
  border: 1px solid var(--tl-line);
}
.bubble.mine {
  margin-left: auto;
  background: var(--tl-electric-soft);
  border-color: #c9dcff;
  border-radius: 14px 14px 4px 14px;
}
.bubble strong { font-size: 12px; color: var(--tl-navy); }
.bubble .body { margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.bubble .meta { color: var(--tl-muted); font-size: 11px; margin-top: 6px; }
.bubble.deleted { font-style: italic; color: var(--tl-muted); background: #f0f3f6; }
.reply-box {
  border-left: 3px solid var(--tl-electric);
  padding: 4px 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--tl-muted);
  background: rgba(14, 39, 68, 0.04);
  border-radius: 0 6px 6px 0;
}
.attach { margin-top: 8px; font-size: 12px; }
.attach a { display: inline-block; margin-right: 8px; }
.attach img { max-width: 240px; border-radius: 10px; }

.thread-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--tl-line);
  min-height: 56px;
}
.thread-head .title-block { flex: 1; min-width: 0; }
.thread-head strong { display: block; font-size: 15px; }
.thread-head .sub { font-size: 12px; color: var(--tl-muted); }
.toolbar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 0;
}
.toolbar .icon-btn { color: var(--tl-muted); }
.composer-wrap {
  border-top: 1px solid var(--tl-line);
  background: #fff;
  padding: 8px 12px 12px;
}
.hint-row {
  min-height: 0;
  font-size: 12px;
  color: var(--tl-muted);
  padding: 0 4px 6px;
}
.hint-row.is-reply { color: var(--tl-electric); }
.composer {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  background: var(--tl-gray);
  border: 1px solid var(--tl-line);
  border-radius: 14px;
  padding: 6px 6px 6px 4px;
}
.composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  border: 0;
  background: transparent;
  padding: 10px 8px;
  resize: none;
}
.composer textarea:focus { outline: none; box-shadow: none; }
.composer .send-btn {
  height: 40px;
  min-width: 40px;
  padding: 0 14px;
  border-radius: 10px;
}
.composer .send-btn svg { width: 18px; height: 18px; }
.info-inner { padding: 18px 16px 24px; }
.info h2 { margin: 0 0 4px; font-size: 16px; }
.info .meta-line { margin: 0 0 16px; color: var(--tl-muted); font-size: 13px; }
.person {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--tl-line);
  font-size: 13px;
}
.person-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; display: inline-block; }
.dot.on { background: var(--tl-ok); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 24, 44, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}
.modal.open { display: flex; }
.sheet {
  background: #fff;
  border-radius: 16px;
  padding: 22px;
  width: min(480px, 100%);
  box-shadow: var(--tl-shadow);
}
.sheet h2 { margin: 0 0 8px; font-size: 18px; }
.sheet p { margin: 0 0 14px; color: var(--tl-muted); font-size: 14px; }
.user-pick { display: grid; gap: 6px; max-height: 320px; overflow: auto; }
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--tl-line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  height: auto;
  color: var(--tl-ink);
}
.user-row:hover { border-color: var(--tl-electric); background: var(--tl-electric-soft); }
.ctx {
  position: absolute;
  background: #fff;
  border: 1px solid var(--tl-line);
  border-radius: 10px;
  box-shadow: var(--tl-shadow);
  z-index: 15;
  min-width: 180px;
  padding: 4px;
}
.ctx button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.ctx button:hover { background: var(--tl-electric-soft); }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--tl-navy);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  z-index: 40;
  max-width: min(420px, calc(100% - 24px));
  transition: opacity 0.2s, transform 0.2s;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.admin-page {
  min-height: 100%;
  background: var(--tl-gray);
}
.admin-page .topbar {
  position: sticky;
  top: 0;
  z-index: 5;
}
.admin-wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}
.admin-grid { display: grid; gap: 16px; }
.admin-card {
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  border: 1px solid var(--tl-line);
  box-shadow: 0 1px 2px rgba(8, 24, 44, 0.04);
}
.admin-card h2 { margin: 0 0 14px; font-size: 16px; }
.admin-card label { display: grid; gap: 6px; margin: 0 0 12px; font-size: 13px; font-weight: 600; }
.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.admin-toolbar input, .admin-toolbar select { height: 40px; min-width: 0; flex: 1; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border-bottom: 1px solid var(--tl-line); padding: 10px 8px; text-align: left; vertical-align: middle; }
th { color: var(--tl-muted); font-weight: 600; font-size: 12px; }

.denied, .guest-box {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tl-navy);
  color: #fff;
}
.card {
  background: #fff;
  color: var(--tl-ink);
  border-radius: 16px;
  padding: 28px;
  width: min(560px, 92vw);
  box-shadow: var(--tl-shadow);
}

@media (max-width: 1100px) {
  .app { grid-template-columns: 300px minmax(0, 1fr); }
  .info { display: none; }
  .auth-shell { grid-template-columns: minmax(240px, 0.8fr) minmax(0, 1.2fr); }
  .auth-brand { padding: 36px 32px; }
  .auth-main { padding: 28px 24px; }
  .auth-card { padding: 28px 24px; }
}
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; grid-template-rows: var(--topbar) minmax(0, 1fr); }
  .info { display: none; }
  .app.show-chat .sidebar { display: none; }
  .app:not(.show-chat) .thread { display: none; }
  #talk-back { display: inline-flex; }
}
@media (min-width: 981px) {
  #talk-back { display: none; }
}
@media (max-width: 860px) {
  .auth-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .auth-brand {
    padding: 24px 20px 20px;
  }
  .brand-lead { font-size: 18px; margin-bottom: 16px; }
  .brand-points { gap: 10px; }
  .brand-foot { margin-top: 16px; }
  .auth-main {
    align-items: stretch;
    padding: 16px 16px 28px;
  }
  .auth-card {
    max-width: none;
    padding: 24px 18px 28px;
    border-radius: 14px;
  }
  .auth-card h1 { font-size: 22px; }
}
@media (max-width: 420px) {
  .top-actions #talk-me { display: none; }
  .brand span { font-size: 14px; }
  .messages { padding: 14px 12px; }
  .bubble { max-width: 88%; }
}
