:root {
  --navy: #0a2540;
  --navy-light: #1a3a5c;
  --blue-accent: #2563eb;
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --green: #059669;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08);
  --sidebar-left-width: 280px;
  --sidebar-right-width: 300px;
  --mobile-topbar-height: 56px;
  --content-padding: clamp(16px, 3vw, 40px);
  --drawer-width: min(320px, 88vw);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.drawer-open {
  overflow: hidden;
}

/* Mobile top bar */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: var(--mobile-topbar-height);
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  justify-content: center;
}

.mobile-brand-icon {
  background: var(--navy);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 6px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.mobile-brand-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.icon-btn:hover {
  background: #f1f5f9;
  border-color: var(--navy);
}

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 37, 64, 0.45);
  z-index: 45;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.drawer-backdrop.visible {
  display: block;
  opacity: 1;
}

.drawer-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.drawer-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--navy);
}

.drawer-close {
  font-size: 24px;
  line-height: 1;
}

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-left-width) minmax(0, 1fr) var(--sidebar-right-width);
  flex: 1;
  min-height: 0;
  height: auto;
}

/* ── Left Sidebar ── */
.sidebar-left {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--border);
}

.amc-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.amc-icon {
  width: 36px;
  height: 36px;
  background: var(--navy);
  border: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
  cursor: pointer;
  padding: 0;
  transition: background 0.2s;
}

.amc-icon:hover {
  background: var(--navy-light);
}

.amc-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.3;
  font-variant: all-small-caps;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.amc-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.search-box {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.search-box:focus {
  border-color: var(--blue-accent);
}

.category-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
}

.tab-btn:hover:not(.active) {
  border-color: var(--navy);
  color: var(--navy);
}

.scheme-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.scheme-group-label {
  padding: 8px 18px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-light);
  text-transform: uppercase;
}

.scheme-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  cursor: pointer;
  transition: background 0.15s;
}

.scheme-item:hover {
  background: #f1f5f9;
}

.scheme-item input[type="checkbox"] {
  accent-color: var(--navy);
  width: 15px;
  height: 15px;
}

.scheme-item label {
  font-size: 13px;
  cursor: pointer;
  line-height: 1.3;
}

.scheme-actions {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.scheme-action-btn {
  background: none;
  border: none;
  font-size: 12px;
  color: var(--blue-accent);
  cursor: pointer;
  font-weight: 500;
  padding: 0;
}

.scheme-action-btn:hover {
  text-decoration: underline;
}

/* ── Main Content ── */
.main-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.main-header {
  text-align: center;
  padding: clamp(16px, 3vw, 28px) var(--content-padding) 0;
}

.hero-title {
  font-size: clamp(1.35rem, 2.5vw + 0.5rem, 1.75rem);
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 8px;
  line-height: 1.25;
}

.hero-subtitle {
  font-size: clamp(0.6875rem, 0.7vw + 0.45rem, 0.75rem);
  color: var(--text-muted);
  max-width: min(720px, 96%);
  margin: 0 auto;
  line-height: 1.35;
  padding: 0 8px;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(10px, 2vw, 14px);
  padding: clamp(16px, 3vw, 28px) var(--content-padding);
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.engine-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-light);
  text-transform: uppercase;
  margin-bottom: 16px;
}

.suggestion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}

.suggestion-card:hover {
  border-color: var(--navy);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.suggestion-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-light);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.suggestion-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
}

/* Chat area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--content-padding) 20px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.chat-message {
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-user {
  background: var(--navy);
  color: white;
  padding: 12px 16px;
  border-radius: 12px 12px 4px 12px;
  font-size: clamp(0.8125rem, 1vw + 0.4rem, 0.875rem);
  max-width: min(80%, 100%);
  margin-left: auto;
  line-height: 1.5;
  word-wrap: break-word;
}

.msg-assistant {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px 18px;
  border-radius: 12px 12px 12px 4px;
  font-size: clamp(0.8125rem, 1vw + 0.4rem, 0.875rem);
  max-width: min(85%, 100%);
  line-height: 1.6;
  box-shadow: var(--shadow);
  word-wrap: break-word;
}

.msg-assistant.refused {
  border-left: 3px solid #f59e0b;
}

.msg-source {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.msg-source a {
  color: var(--blue-accent);
  font-size: 12px;
  text-decoration: none;
  word-break: break-all;
}

.msg-source a:hover {
  text-decoration: underline;
}

.msg-meta {
  margin-top: 8px;
  font-size: 9px;
  color: var(--text);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 768px) {
  .msg-meta {
    white-space: normal;
  }
}

/* Input bar */
.input-bar {
  padding: 12px var(--content-padding) calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.input-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 760px;
  margin: 0 auto 8px;
  width: 100%;
}

.input-scope {
  font-size: 11px;
  color: var(--text-muted);
  text-align: left;
  flex: 1;
  min-width: 0;
}

.input-disclaimer {
  font-size: 11px;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: right;
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 6px 6px clamp(12px, 2vw, 16px);
  transition: border-color 0.2s;
  min-width: 0;
}

.input-wrapper input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: clamp(0.8125rem, 1vw + 0.4rem, 0.875rem);
  outline: none;
  padding: 8px 0;
  min-width: 0;
  width: 100%;
}

.input-wrapper:focus-within {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(10, 37, 64, 0.08);
}

.input-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--navy);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--navy-light);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-footer {
  text-align: center;
  font-size: 10px;
  color: var(--text-light);
  margin-top: 8px;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.input-footer-note {
  font-size: 10px;
  color: var(--text-light);
}

/* ── Right Sidebar ── */
.sidebar-right {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.right-header {
  padding: 18px;
}

.new-session-btn {
  width: 100%;
  padding: 10px;
  background: var(--navy);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.new-session-btn:hover {
  background: var(--navy-light);
}

.assurance-box {
  margin: 0 18px 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
}

.assurance-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 12px;
}

.assurance-item {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  margin-bottom: 8px;
  font-size: 9px;
  line-height: 1.25;
  color: var(--text-muted);
}

.assurance-check {
  flex-shrink: 0;
  color: var(--blue-accent);
  font-weight: 700;
  font-size: 9px;
  line-height: 1.25;
  margin-top: 1px;
}

.assurance-item strong {
  color: var(--text);
  font-weight: 700;
}

.assurance-body {
  color: var(--text-muted);
}

.recent-section {
  flex: 1;
  overflow-y: auto;
  padding: 0 18px;
}

.recent-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 10px;
}

.recent-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.recent-item:hover {
  border-color: var(--navy);
  background: #f8fafc;
}

.recent-q {
  font-size: 12px;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 4px;
}

.recent-meta {
  font-size: 10px;
  color: var(--text-light);
}

/* Loading spinner */
.msg-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 200px;
}

.loading-text {
  font-size: 12px;
  color: var(--text-muted);
}

.loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--blue-accent);
  border-radius: 50%;
  animation: loadingPulse 1.2s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.24s; }
.loading-dots span:nth-child(2) { animation-delay: -0.12s; }

@keyframes loadingPulse {
  0%, 80%, 100% {
    opacity: 0.35;
    transform: scale(0.85);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Hide suggestions when chat is active */
.main-content.has-chat .suggestions-grid {
  display: none;
}

.main-content.has-chat .hero-title {
  font-size: clamp(1rem, 2vw + 0.4rem, 1.125rem);
}

.main-content.has-chat .hero-subtitle {
  display: none;
}

.main-content.has-chat .main-header {
  padding-top: clamp(10px, 2vw, 16px);
}

/* ── Responsive breakpoints ── */

/* Large tablets / small laptops */
@media (max-width: 1200px) {
  :root {
    --sidebar-left-width: 240px;
    --sidebar-right-width: 260px;
  }

  .suggestions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Tablets: collapse right sidebar into drawer */
@media (max-width: 992px) {
  body {
    display: flex;
    flex-direction: column;
  }

  .mobile-topbar {
    display: flex;
    flex-shrink: 0;
  }

  #openSchemesBtn {
    visibility: hidden;
    pointer-events: none;
  }

  :root {
    --sidebar-left-width: 240px;
    --sidebar-right-width: 0px;
  }

  .app-layout {
    grid-template-columns: var(--sidebar-left-width) minmax(0, 1fr);
    flex: 1;
    min-height: 0;
  }

  .sidebar-right {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--drawer-width);
    height: 100vh;
    height: 100dvh;
    z-index: 50;
    transform: translateX(100%);
    transition: transform 0.28s ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar-right.open {
    transform: translateX(0);
  }

  .sidebar-right .drawer-header {
    display: flex;
  }
}

/* Mobile: single column + both sidebars as drawers */
@media (max-width: 768px) {
  #openSchemesBtn {
    visibility: visible;
    pointer-events: auto;
  }

  .app-layout {
    grid-template-columns: 1fr;
    flex: 1;
    min-height: 0;
    height: auto;
  }

  .sidebar-left,
  .sidebar-right {
    position: fixed;
    top: 0;
    width: var(--drawer-width);
    height: 100vh;
    height: 100dvh;
    z-index: 50;
    transition: transform 0.28s ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar-left {
    left: 0;
    transform: translateX(-100%);
  }

  .sidebar-left.open {
    transform: translateX(0);
  }

  .sidebar-right {
    right: 0;
    transform: translateX(100%);
  }

  .sidebar-right.open {
    transform: translateX(0);
  }

  .sidebar-left .drawer-header,
  .sidebar-right .drawer-header {
    display: flex;
  }

  .main-content {
    min-height: 0;
    flex: 1;
  }

  .suggestions-grid {
    grid-template-columns: 1fr;
    padding-top: 12px;
  }

  .suggestion-card {
    padding: 14px;
  }

  .msg-user,
  .msg-assistant {
    max-width: 92%;
  }

  .input-footer {
    font-size: 9px;
    padding: 0 4px;
  }

  .main-content.has-chat .main-header {
    padding-top: 10px;
  }

  .engine-label {
    font-size: 10px;
    margin-bottom: 10px;
  }

  .hero-subtitle {
    white-space: normal;
    font-size: 0.6875rem;
    line-height: 1.35;
  }
}

/* Small phones */
@media (max-width: 480px) {
  :root {
    --content-padding: 12px;
    --drawer-width: min(300px, 92vw);
  }

  .mobile-brand-text {
    font-size: 12px;
  }

  .input-meta {
    flex-wrap: wrap;
  }

  .input-disclaimer {
    font-size: 10px;
  }

  .input-wrapper {
    border-radius: 12px;
    padding-left: 12px;
  }

  .hero-title {
    font-size: 1.25rem;
  }

  .assurance-box {
    margin-left: 12px;
    margin-right: 12px;
    padding: 12px;
  }

  .recent-section {
    padding: 0 12px;
  }
}

/* Very small phones */
@media (max-width: 360px) {
  .category-tabs {
    padding: 10px 12px;
  }

  .tab-btn {
    font-size: 11px;
    padding: 4px 10px;
  }

  .sidebar-header {
    padding: 16px 12px 12px;
  }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
  .main-header {
    padding-top: 8px;
  }

  .hero-subtitle {
    display: none;
  }

  .suggestions-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 8px var(--content-padding);
    gap: 8px;
  }

  .suggestion-card {
    padding: 10px;
  }

  .main-content.has-chat .suggestions-grid {
    display: none;
  }
}

/* Large desktops */
@media (min-width: 1440px) {
  .app-layout {
    max-width: 1600px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* Footer banner — bottom illustration, cropped from above */
.footer-banner {
  width: 100%;
  flex-shrink: 0;
  background: #ffffff;
  border-top: 1px solid var(--border);
}

.footer-banner__crop {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  height: clamp(130px, 16vw, 200px);
  overflow: hidden;
  position: relative;
  background: #ffffff;
}

.footer-banner__crop img {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  min-width: 720px;
  height: auto;
  display: block;
}

@media (max-width: 768px) {
  .footer-banner__crop {
    height: clamp(100px, 18vw, 150px);
  }

  .footer-banner__crop img {
    min-width: 560px;
  }
}

@media (max-width: 480px) {
  .footer-banner__crop {
    height: clamp(85px, 22vw, 120px);
  }

  .footer-banner__crop img {
    min-width: 480px;
  }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
