:root {
  color-scheme: dark;
  --bg: #07101d;
  --bg-soft: #0b1525;
  --panel: rgba(16, 28, 46, 0.92);
  --panel-strong: #111f33;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.28);
  --text: #edf4ff;
  --muted: #91a4bd;
  --accent: #7dd3fc;
  --accent-strong: #38bdf8;
  --success: #4ade80;
  --warn: #fbbf24;
  --danger: #fb7185;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 82% -10%, rgba(56, 189, 248, 0.14), transparent 34%),
    radial-gradient(circle at 12% 100%, rgba(14, 165, 233, 0.08), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(100%, 430px);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(18, 33, 54, 0.96), rgba(10, 20, 35, 0.96));
  box-shadow: var(--shadow);
  text-align: center;
}

.brand-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  border: 1px solid rgba(125, 211, 252, 0.38);
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.22), rgba(14, 165, 233, 0.05));
  color: #dff6ff;
  font-size: 27px;
  font-weight: 800;
  box-shadow: inset 0 0 24px rgba(125, 211, 252, 0.08);
}

.brand-mark.small {
  width: 40px;
  height: 40px;
  margin: 0;
  border-radius: 13px;
  font-size: 19px;
}

.eyebrow {
  margin: 0 0 7px;
  color: #76bedd;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.auth-card h1 {
  margin: 0 0 10px;
  font-size: 34px;
}

.muted {
  color: var(--muted);
}

.auth-form {
  margin-top: 26px;
  display: grid;
  gap: 10px;
  text-align: right;
}

.auth-form label {
  color: #b8c8da;
  font-size: 13px;
  font-weight: 700;
}

.auth-form input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  outline: none;
  color: var(--text);
  background: rgba(4, 12, 23, 0.76);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.auth-form input {
  height: 50px;
  padding: 0 15px;
  border-radius: 14px;
  direction: ltr;
}

.auth-form input:focus,
.composer textarea:focus {
  border-color: rgba(56, 189, 248, 0.62);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.08);
}

.primary-btn,
.ghost-btn,
.icon-btn,
.nav-item,
.mobile-nav-item {
  border: 0;
}

.primary-btn {
  min-height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, #0ea5e9, #38bdf8);
  color: #04111c;
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(14, 165, 233, 0.18);
}

.primary-btn:disabled {
  opacity: 0.56;
  cursor: wait;
}

.security-note,
.error-text {
  margin: 14px 0 0;
  font-size: 12px;
}

.security-note {
  color: #71849a;
}

.error-text {
  min-height: 17px;
  color: var(--danger);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px 18px;
  border-left: 1px solid var(--line);
  background: rgba(7, 16, 29, 0.84);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-head {
  display: grid;
  gap: 16px;
}

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

.brand-row strong,
.brand-row span {
  display: block;
}

.brand-row strong {
  font-size: 16px;
}

.brand-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.ghost-btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.025);
  color: #c9d7e8;
  font-weight: 700;
}

.ghost-btn:hover,
.nav-item:hover,
.mobile-nav-item:hover {
  border-color: var(--line-strong);
  background: rgba(125, 211, 252, 0.06);
}

.ghost-btn.compact {
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 13px;
  display: flex;
  align-items: center;
  gap: 11px;
  background: transparent;
  color: #a9bbce;
  text-align: right;
  transition: 150ms ease;
}

.nav-item span {
  width: 22px;
  color: #6d8299;
  text-align: center;
}

.nav-item.active {
  border-color: rgba(56, 189, 248, 0.2);
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.11), rgba(56, 189, 248, 0.025));
  color: #e7f7ff;
}

.nav-item.active span {
  color: var(--accent);
}

.sidebar-status {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
  display: grid;
  gap: 10px;
}

.status-line {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 8px;
  color: #9fb0c3;
  font-size: 11px;
}

.status-line strong {
  color: #d7e2ee;
  font-size: 11px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: #64748b;
}

.status-dot.ok {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.08);
}

.status-dot.bad {
  background: var(--danger);
}

.readonly-badge {
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: #7dc7a0;
  font-size: 10px;
  font-weight: 700;
}

.main {
  min-width: 0;
  padding: 28px clamp(18px, 3.4vw, 48px) 48px;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar h2 {
  margin: 0;
  font-size: clamp(23px, 3vw, 31px);
}

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

.live-pill {
  height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(74, 222, 128, 0.18);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #85eaa7;
  background: rgba(74, 222, 128, 0.05);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.08);
}

.overview-strip {
  margin: 22px 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  min-height: 92px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: linear-gradient(160deg, rgba(17, 31, 51, 0.95), rgba(10, 20, 35, 0.85));
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric-card strong {
  display: block;
  margin-top: 9px;
  font-size: 24px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.16);
  overflow: hidden;
}

.panel-head {
  min-height: 72px;
  padding: 17px 19px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-head h3,
.welcome-card h3 {
  margin: 0;
}

.panel-head p {
  margin: 5px 0 0;
  font-size: 11px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: transparent;
  color: #b9c8da;
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
}

.chat-panel {
  min-height: calc(100vh - 235px);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.chat-messages {
  max-height: calc(100vh - 340px);
  min-height: 420px;
  padding: 24px;
  overflow: auto;
  scroll-behavior: smooth;
}

.welcome-card {
  margin: 40px auto;
  max-width: 520px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  display: flex;
  gap: 15px;
  align-items: flex-start;
  background: rgba(125, 211, 252, 0.035);
}

.welcome-card p {
  margin: 7px 0 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 13px;
}

.message {
  max-width: min(82%, 760px);
  margin: 0 0 16px;
  padding: 13px 15px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.75;
  font-size: 14px;
}

.message.user {
  margin-right: auto;
  border-bottom-left-radius: 5px;
  background: linear-gradient(135deg, #0ea5e9, #38bdf8);
  color: #03121d;
  font-weight: 600;
}

.message.assistant {
  margin-left: auto;
  border: 1px solid var(--line);
  border-bottom-right-radius: 5px;
  background: rgba(255, 255, 255, 0.035);
  color: #dce7f3;
}

.message.pending {
  color: #8194a9;
  font-style: italic;
}

.composer {
  padding: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.composer textarea {
  min-height: 52px;
  max-height: 160px;
  resize: none;
  padding: 14px;
  border-radius: 15px;
  line-height: 1.55;
}

.composer-actions {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.send-btn {
  min-height: 52px;
  min-width: 78px;
}

.voice-btn {
  width: 52px;
  min-width: 52px;
  min-height: 52px;
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 15px;
  background: rgba(56, 189, 248, 0.07);
  color: #bfeeff;
  font-size: 20px;
  line-height: 1;
}

.voice-btn.recording {
  border-color: rgba(251, 113, 133, 0.52);
  background: rgba(251, 113, 133, 0.12);
  color: #ff9dad;
  box-shadow: 0 0 0 5px rgba(251, 113, 133, 0.08);
  animation: voicePulse 1.2s ease-in-out infinite;
}

.voice-btn.processing {
  cursor: wait;
  opacity: 0.78;
}

.voice-btn:disabled {
  cursor: wait;
  opacity: 0.56;
}

.voice-status {
  grid-column: 1 / -1;
  min-height: 20px;
  padding: 1px 4px 0;
  color: #8fcfe8;
  font-size: 11px;
  line-height: 1.5;
}

.voice-reply {
  width: min(100%, 360px);
  height: 36px;
  margin-top: 10px;
  display: block;
}

@keyframes voicePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.conversation-panel {
  min-height: calc(100vh - 235px);
}

.list,
.timeline {
  padding: 8px;
}

.compact-list {
  max-height: calc(100vh - 320px);
  overflow: auto;
}

.list-item {
  width: 100%;
  padding: 15px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  text-align: right;
  transition: 130ms ease;
}

button.list-item:hover,
button.list-item.active {
  border-color: var(--line);
  background: rgba(125, 211, 252, 0.045);
}

.list-item + .list-item {
  margin-top: 5px;
}

.item-title {
  color: #e5eef8;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.55;
}

.item-meta,
.item-body {
  color: var(--muted);
  font-size: 11px;
}

.item-meta {
  margin-top: 4px;
}

.item-body {
  margin-top: 7px;
  line-height: 1.6;
}

.timeline-item {
  position: relative;
  margin: 0 13px;
  padding: 16px 24px 16px 10px;
  border-right: 1px solid var(--line);
}

.timeline-item::before {
  content: "";
  position: absolute;
  right: -5px;
  top: 23px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--panel-strong);
  border-radius: 99px;
  background: var(--accent-strong);
}

.badge-row {
  margin-top: 9px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.badge {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #aebdd0;
  font-size: 10px;
}

.badge.active,
.badge.approved {
  color: #8be8ab;
  border-color: rgba(74, 222, 128, 0.16);
}

.badge.pending {
  color: #f8ce69;
  border-color: rgba(251, 191, 36, 0.18);
}

.badge.failed,
.badge.rejected {
  color: #ff95a4;
  border-color: rgba(251, 113, 133, 0.18);
}

.approval-actions {
  margin-top: 11px;
  display: flex;
  gap: 8px;
}

.approval-actions button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-weight: 750;
}

.approve-btn {
  background: rgba(74, 222, 128, 0.08);
  color: #8ee9ad;
}

.reject-btn {
  background: rgba(251, 113, 133, 0.07);
  color: #ff9dad;
}

.empty-state,
.loading-state {
  padding: 44px 20px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 48px));
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #101d30;
  color: #dce7f3;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 180ms ease;
  font-size: 12px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: rgba(251, 113, 133, 0.28);
}

.mobile-nav {
  display: none;
}

@media (max-width: 1050px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .conversation-panel {
    display: none;
  }

  .chat-panel {
    min-height: calc(100vh - 240px);
  }

  .overview-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 760px) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 18px 14px 92px;
  }

  .topbar {
    min-height: 52px;
  }

  .top-actions .ghost-btn {
    display: none;
  }

  .overview-strip {
    margin: 15px 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric-card {
    min-height: 76px;
    padding: 13px;
  }

  .metric-card strong {
    font-size: 21px;
  }

  .panel {
    border-radius: 18px;
  }

  .chat-panel {
    min-height: calc(100vh - 280px);
  }

  .chat-messages {
    min-height: 360px;
    max-height: calc(100vh - 380px);
    padding: 16px 12px;
  }

  .message {
    max-width: 92%;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 10px;
    gap: 8px;
  }

  .composer-actions {
    gap: 6px;
  }

  .send-btn {
    min-width: 62px;
  }

  .voice-btn {
    width: 48px;
    min-width: 48px;
  }

  .mobile-nav {
    position: fixed;
    right: 10px;
    left: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 20;
    min-height: 58px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 18px;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 3px;
    background: rgba(9, 18, 31, 0.94);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow);
  }

  .mobile-nav-item {
    border-radius: 12px;
    background: transparent;
    color: #8092a8;
    font-size: 10px;
    font-weight: 700;
  }

  .mobile-nav-item.active {
    background: rgba(56, 189, 248, 0.09);
    color: #bfeeff;
  }

  .auth-card {
    padding: 28px 20px;
  }
}


.text-btn {
  margin-top: 12px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.compact-form {
  margin-top: 14px;
}

.memory-form {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
}

.memory-form textarea {
  width: 100%;
  min-height: 86px;
  resize: vertical;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  color: var(--text);
  background: rgba(4, 12, 23, 0.76);
  line-height: 1.65;
}

.memory-form textarea:focus {
  border-color: rgba(56, 189, 248, 0.62);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.08);
}

.private-toggle {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.private-toggle input {
  margin-top: 2px;
}

.memory-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge.private {
  color: #c7a7ff;
  border-color: rgba(196, 157, 255, 0.22);
}

.memory-actions {
  margin-top: 10px;
}

.memory-actions button {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-weight: 750;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 8, 18, 0.82);
  backdrop-filter: blur(12px);
}

.modal-card {
  width: min(100%, 430px);
  padding: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 24px;
  background: #0d192a;
  box-shadow: var(--shadow);
}

.modal-card .brand-mark {
  margin: 0 0 16px;
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 22px;
}

@media (max-width: 760px) {
  .memory-form {
    padding: 14px;
  }

  .modal-card {
    padding: 24px 18px;
  }
}
