
/* ── Responsive app layout ── */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

body {
  min-height: 100%;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

.app-shell {
  min-height: 100dvh;
  max-width: min(100%, 920px);
}

.chat-container {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.input-area {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

.app-footer {
  flex-shrink: 0;
}

/* Touch-friendly controls */
.btn,
.quick-btn,
.select-lang,
.send-btn,
.mic-btn,
.toolbar-menu-btn {
  min-height: 44px;
  touch-action: manipulation;
}

.btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
}

/* Toolbar: mobile drawer + desktop inline */
.app-toolbar {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
}

.app-toolbar__primary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  flex-wrap: nowrap;
}

.app-toolbar__primary .app-toolbar__group {
  flex: 1;
  min-width: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.app-toolbar__primary .app-toolbar__group::-webkit-scrollbar { display: none; }

.select-lang--toolbar {
  min-width: 108px;
  flex-shrink: 0;
}

.toolbar-menu-btn {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
}
.toolbar-menu-btn[aria-expanded="true"] {
  background: var(--ocp-accent-light);
  border-color: var(--ocp-green);
  color: var(--ocp-green);
}
.toolbar-menu-btn__label { display: none; }

.toolbar-drawer {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 0 12px 12px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface);
  animation: drawerIn 0.2s ease-out;
}
.toolbar-drawer.is-open {
  display: flex;
}
.toolbar-drawer[hidden] { display: none !important; }
.toolbar-drawer.is-open[hidden] { display: flex !important; }

@keyframes drawerIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.app-toolbar__group--toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.app-toolbar__group--toggles .btn,
.app-toolbar__group--toggles .select-lang {
  flex: 1 1 calc(50% - 6px);
  min-width: 0;
  justify-content: center;
  text-align: center;
}

.toolbar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9;
  background: transparent;
}
.toolbar-backdrop.is-visible { display: block; }

/* Tablet */
@media (min-width: 768px) {
  body {
    padding: clamp(12px, 2vw, 24px);
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .app-shell { min-height: min(94dvh, 920px); }
  .chat-container {
    min-height: min(94dvh, 920px);
    border-radius: var(--radius);
  }
  .toolbar-menu-btn { display: none; }
  .toolbar-backdrop { display: none !important; }
  .toolbar-drawer {
    display: flex !important;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 14px;
    border-top: 1px solid rgba(29, 161, 61, 0.2);
    animation: none;
  }
  .toolbar-drawer[hidden] { display: flex !important; }
  .app-toolbar__group--toggles .btn,
  .app-toolbar__group--toggles .select-lang {
    flex: 0 1 auto;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .app-toolbar__primary .app-toolbar__group { overflow: visible; }
  .app-toolbar__group--toggles { margin-inline-start: auto; }
}

/* Phone */
@media (max-width: 767px) {
  body {
    padding: 0;
    padding-top: env(safe-area-inset-top, 0);
  }
  .app-shell {
    max-width: 100%;
    min-height: 100dvh;
  }
  .chat-container {
    min-height: 100dvh;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  .app-header__row {
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .header-logo { max-width: min(180px, 48vw); height: 40px; }
  .header-text h1 { font-size: 1.05rem; }
  .header-status { margin-inline-start: auto; width: auto; }
  .header-status .status-pill { font-size: 0.6875rem; }
  .message {
    max-width: 100%;
    font-size: 0.9375rem;
  }
  .message.user { max-width: 92%; }
  .message.assistant { max-width: 96%; }
  .quick-actions {
    padding: 0 12px 8px;
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .quick-btn {
    scroll-snap-align: start;
    flex-shrink: 0;
    min-height: 40px;
  }
  .input-area {
    padding: 10px 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .input-wrapper { padding: 4px 6px 4px 10px; }
  #userInput { font-size: 16px; /* prevents iOS zoom on focus */ }
  .send-btn, .mic-btn { width: 44px; height: 44px; }
  .app-footer { padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .modal {
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    align-items: flex-end;
  }
  .modal__panel {
    max-height: 90dvh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-bottom: 0;
  }
  .toast {
    bottom: max(20px, env(safe-area-inset-bottom));
    max-width: calc(100vw - 24px);
  }
}

@media (max-width: 380px) {
  .header-text p { display: none; }
  .toolbar-menu-btn__label { display: none; }
  .btn--ghost { padding: 8px 10px; font-size: 0.75rem; }
}

/* Landscape phone */
@media (max-width: 767px) and (orientation: landscape) {
  .app-header__row { padding: 6px 12px; }
  .header-logo { height: 32px; }
  .header-text h1 { font-size: 0.95rem; }
  .header-text p { display: none; }
  .chat-container { min-height: 100dvh; }
  .toolbar-drawer.is-open { max-height: 45dvh; overflow-y: auto; }
}

/* Pack: dark theme */
body.theme-dark {
  --ocp-brand: #22c55e;
  --ocp-green: #22c55e;
  --ocp-green-hover: #16a34a;
  --ocp-accent-light: rgba(34, 197, 94, 0.15);
  --bg-page: #0f172a;
  --surface: #1e293b;
  --surface-chat: #0f172a;
  --border: #334155;
  --border-soft: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --user-msg: rgba(34, 197, 94, 0.12);
  --user-msg-border: rgba(34, 197, 94, 0.35);
  --assistant-msg: #1e293b;
  --assistant-border: #334155;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 12px 40px rgba(0, 0, 0, 0.25);
}
body.theme-dark {
  background: linear-gradient(165deg, #0b1220 0%, var(--bg-page) 45%, #111827 100%);
}
body.theme-dark .app-toolbar,
body.theme-dark .toolbar-drawer {
  background: #1e293b;
}
body.theme-dark .app-toolbar {
  border-top-color: rgba(34, 197, 94, 0.25);
}
body.theme-dark .app-header {
  background: linear-gradient(118deg, #15803d 0%, #166534 55%, #0f172a 100%);
}
body.theme-dark .input-wrapper,
body.theme-dark .btn,
body.theme-dark .select-lang,
body.theme-dark .quick-btn,
body.theme-dark .qa-upload-textarea,
body.theme-dark .qa-edit-panel,
body.theme-dark .toolbar-menu-btn {
  background: #0f172a;
  color: var(--text);
  border-color: var(--border);
}
body.theme-dark .message-content .section-title--alert {
  color: #fdba74;
  border-inline-start-color: #fb923c;
}
body.theme-dark .message-content .actions-box {
  background: rgba(251, 191, 36, 0.08);
  border-color: rgba(251, 191, 36, 0.35);
}

.session-item {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-soft);
}
.session-item .session-load {
  max-width: calc(100% - 40px);
  text-align: start;
  white-space: normal;
}
.session-item .session-del {
  min-width: 28px;
  padding: 4px 8px;
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.35);
}
#sessionList {
  min-height: 120px;
  max-height: min(280px, 40dvh);
  overflow: auto;
  margin-top: 8px;
}
.qa-excel-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.qa-excel-row input[type="file"] {
  font-size: 0.75rem;
  max-width: 100%;
}
