/* TextAI agent console layout. */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(1000px 600px at 20% 0%, var(--primary-soft), transparent), var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  outline: none;
}

.login-card input:focus { border-color: var(--primary); }
.login-error { color: var(--accent); font-size: 13px; margin: 0; }

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: grid; place-items: center; font-weight: 700;
}

.brand-name { font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--muted); }

/* Lock the console to the viewport so each pane scrolls internally instead of
   growing the page: without this the reply composer is pushed below the fold. */
.app { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
  padding-top: max(10px, env(safe-area-inset-top));
}

.topnav { display: flex; gap: 4px; align-items: center; min-width: 0; overflow-x: auto; }

.topnav-item {
  border: 0; background: transparent; cursor: pointer; white-space: nowrap;
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; color: var(--muted);
}

.topnav-item:hover { background: var(--surface-2); color: var(--fg); }
.topnav-item[data-active='1'] { background: var(--primary-soft); color: var(--primary); }

.topbar-stats { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.stat {
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 12px; border-radius: 10px; background: var(--surface-2);
  min-width: 62px;
}

.stat b { font-size: 15px; }
.stat span { font-size: 11px; color: var(--muted); }

.layout {
  flex: 1; display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 280px;
  gap: 0; min-height: 0;
}

.pane { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.list-pane, .chat-pane { border-right: 1px solid var(--line); }

.pane-head {
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
  border-bottom: 1px solid var(--line);
}

.pane-head h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.pane-note { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

.tabs { display: flex; gap: 6px; }

.tabs button {
  flex: 1; padding: 6px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); cursor: pointer;
  font-size: 12px; color: var(--muted);
}

.tabs button[data-active='1'] { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); font-weight: 600; }

.search, .select {
  width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--fg); outline: none;
}

.select { width: auto; }
.search:focus, .select:focus { border-color: var(--primary); }

.list, .agent-list, .queue-list { overflow-y: auto; flex: 1; }

.conv {
  display: flex; gap: 10px; padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.conv:hover { background: var(--surface-2); }
.conv[data-active='1'] { background: var(--primary-soft); }
.conv .grow { flex: 1; min-width: 0; }
.conv .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.conv .preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .unread {
  min-width: 20px; height: 20px; border-radius: 10px; background: var(--accent); color: #fff;
  font-size: 11px; display: grid; place-items: center; padding: 0 6px; font-weight: 700;
}

.avatar {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}

.chat-head {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}

.chat-head .visitor-name { font-weight: 600; }
.chat-head .visitor-meta { font-size: 12px; color: var(--muted); }
.chat-actions { display: flex; gap: 8px; align-items: center; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
}

.msg-row { display: flex; }
.msg-row[data-who='agent'] { justify-content: flex-end; }

.msg {
  max-width: 74%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word;
  background: var(--surface-2); border-bottom-left-radius: 4px;
}

.msg-row[data-who='agent'] .msg {
  background: var(--primary); color: var(--primary-fg);
  border-bottom-left-radius: 14px; border-bottom-right-radius: 4px;
}

.msg-meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; }
.msg-row[data-who='agent'] .msg-meta { justify-content: flex-end; }
.msg-meta .tick[data-status='read'] { color: var(--success); }

.sys {
  align-self: center; font-size: 12px; color: var(--muted);
  background: var(--surface-2); padding: 4px 10px; border-radius: 999px;
}

.typing { height: 18px; font-size: 12px; color: var(--muted); padding: 0 18px; }

.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 12px 16px;
  border-top: 1px solid var(--line);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.composer textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 120px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); outline: none;
}

.composer textarea:focus { border-color: var(--primary); }

.btn {
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 16px; cursor: pointer; font-weight: 600; background: var(--surface-2); color: var(--fg-soft);
  transition: filter .15s ease;
}

.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-fg); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.warn { background: var(--warning); color: #1f1300; }
.btn.danger { background: var(--accent); color: #fff; }

.agent-item, .queue-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line);
}

.agent-item .meta { flex: 1; min-width: 0; }
.agent-item .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-item .sub { font-size: 11px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow-md); z-index: 100; font-size: 13px;
}

.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* Site configuration view: quick answers and console navigation, both edited
   as tables so rows can be added, reordered and removed in place. */

.settings { flex: 1; overflow-y: auto; min-height: 0; background: var(--bg); }

.settings-inner {
  max-width: 960px; margin: 0 auto; padding: 28px 20px 56px;
  display: flex; flex-direction: column; gap: 20px;
}

.settings-head h2 { margin: 0; font-size: 20px; }
.settings-head .pane-note { margin-top: 6px; }
.settings-actions { display: flex; justify-content: flex-end; }

.config-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}

.config-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.config-card-head h3 { margin: 0; font-size: 15px; }

.table-wrap { overflow-x: auto; }
/* Keep a usable editing width on phones by letting the wrapper scroll rather
   than crushing the two text columns into a few characters. */
.config-table { width: 100%; min-width: 560px; border-collapse: collapse; }

.config-table th {
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap;
}

.config-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.config-table tr:last-child td { border-bottom: 0; }
.config-table .col-idx { width: 36px; color: var(--muted); font-size: 12px; }
.config-table .col-act { width: 108px; }

.config-table input, .config-table textarea {
  width: 100%; padding: 8px 10px; outline: none;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--fg);
}

.config-table textarea { resize: vertical; min-height: 40px; }
.config-table input:focus, .config-table textarea:focus { border-color: var(--primary); }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

.icon-btn {
  width: 28px; height: 28px; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--muted); font-size: 13px;
}

.icon-btn:hover:not(:disabled) { color: var(--fg); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn[data-remove]:hover { color: var(--accent); border-color: var(--accent); }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr); }
  .insight-pane { display: none; }
}

/* Narrow screens cannot fit the navigation bar inline, so give it its own row
   instead of letting the flexible stats squeeze it down to zero width. */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .topnav { order: 9; flex: 1 0 100%; }
}

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .list-pane { display: none; }
  .list-pane[data-show='1'] { display: flex; position: absolute; inset: 56px 0 0 0; z-index: 5; }
  .chat-pane[data-show='0'] { display: none; }
}
