/* Tomogo Chat — Styles
   E-ink compatible: no custom properties, no calc(), no grid, no gap, no border-radius,
   offset-only shadows, webkit-prefixed flex
*/

/* ── Reset ──────────────────────────────────────────────────────────────── */
* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-transition: none !important;
  transition: none !important;
  -webkit-animation: none !important;
  animation: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: #FFFFFF;
  color: #111111;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* ── Chat layout mode — applied by JS when chat screen is active ─────────── */
html.layout-chat {
  overflow: hidden;
}

body.layout-chat {
  height: 100vh;   /* fallback: e-ink and older browsers */
  height: 100dvh;  /* dynamic viewport: excludes Chrome Android bottom bar */
  overflow: hidden;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
}

body.layout-chat #app-header {
  -ms-flex-negative: 0;
  flex-shrink: 0;
}

body.layout-chat #screen-chat {
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ── App Header — sticky on scrolling pages ─────────────────────────────── */
#app-header {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 100;
  background: #FFFFFF;
  border-bottom: 3px solid #111111;
  width: 100%;
}

#header-inner {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding: 7px 16px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
}

#header-logo-group {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

#header-logo {
  width: 22px;
  height: 22px;
  margin-right: 8px;
  -ms-flex-negative: 0;
  flex-shrink: 0;
}

#header-wordmark {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 3px;
  color: #111111;
  text-transform: uppercase;
}

#header-actions {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

.header-icon-btn {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: #111111;
}

.header-icon-btn svg {
  display: block;
}

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
  padding-top: 0;
  padding-bottom: 40px;
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  border: 2px solid #111111;
  box-shadow: 4px 4px 0 #111111;
  background: #FFFFFF;
  padding: 20px;
  margin-top: 24px;
  margin-bottom: 24px;
}

/* ── Typography ──────────────────────────────────────────────────────────── */
.section-label {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  color: #888888;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 0;
  margin-bottom: 12px;
}

.heading-serif {
  font-family: Georgia, serif;
  font-size: 22px;
  font-weight: normal;
  color: #111111;
  margin-top: 8px;
  margin-bottom: 16px;
}

.body-text {
  font-family: Georgia, serif;
  font-size: 16px;
  color: #444444;
  line-height: 1.65;
  margin-top: 0;
  margin-bottom: 16px;
}

.status-msg {
  font-family: Georgia, serif;
  font-size: 16px;
  color: #444444;
  margin-top: 12px;
  margin-bottom: 0;
}

.hint-text {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  color: #888888;
  margin-top: 4px;
  margin-bottom: 0;
  min-height: 1.2em;
}

/* ── Form elements ───────────────────────────────────────────────────────── */
.field-label {
  display: block;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  color: #888888;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 18px;
  margin-bottom: 6px;
}

.input-text,
.input-select,
.input-textarea {
  display: block;
  width: 100%;
  min-height: 44px;
  border: 2px solid #111111;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  padding: 8px 12px;
  background: #FFFFFF;
  color: #111111;
  margin-top: 0;
  margin-bottom: 4px;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

.input-text:focus,
.input-select:focus,
.input-textarea:focus {
  outline: 2px solid #111111;
  outline-offset: 1px;
}

.input-select {
  cursor: pointer;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  min-height: 44px;
  background: #111111;
  color: #FFFFFF;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 1px;
  border: 2px solid #111111;
  box-shadow: 3px 3px 0 #444444;
  cursor: pointer;
  margin-top: 20px;
  padding: 10px 16px;
  text-align: center;
}

.btn-primary:focus {
  outline: 2px solid #444444;
  outline-offset: 2px;
}

.btn-secondary {
  display: block;
  width: 100%;
  min-height: 44px;
  background: #FFFFFF;
  color: #111111;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  border: 2px solid #111111;
  cursor: pointer;
  margin-top: 12px;
  padding: 10px 16px;
  text-align: center;
}

.btn-secondary:focus {
  outline: 2px solid #111111;
  outline-offset: 2px;
}

.btn-danger {
  display: block;
  width: 100%;
  min-height: 44px;
  background: #FFFFFF;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  border: 2px solid #888888;
  cursor: pointer;
  margin-top: 24px;
  padding: 10px 16px;
  text-align: center;
  color: #888888;
}

/* ── Home screen ─────────────────────────────────────────────────────────── */
#screen-home {
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

/* Sticky area: label + New Chat button */
#home-sticky-header {
  position: -webkit-sticky;
  position: sticky;
  top: 0; /* updated by JS to sit below app-header */
  z-index: 50;
  background: #FFFFFF;
  border-bottom: 2px solid #111111;
  width: 100%;
}

#home-sticky-inner {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding: 16px 20px 20px;
}

#home-sticky-inner .section-label {
  margin-bottom: 8px;
}

#home-sticky-inner .btn-primary {
  margin-top: 0;
}

#home-thread-area {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding: 0 20px 40px;
}

#thread-list {
  margin-top: 8px;
}

.thread-item {
  border-bottom: 1px solid #CCCCCC;
  padding-top: 2px;
  padding-bottom: 2px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

.thread-item-inner {
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
  padding-top: 12px;
  padding-bottom: 12px;
  padding-right: 8px;
  cursor: pointer;
  min-height: 44px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}

.thread-item-title {
  font-family: Georgia, serif;
  font-size: 16px;
  color: #111111;
  display: block;
}

.thread-item-meta {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  color: #888888;
  display: block;
  margin-top: 4px;
}

.thread-item-actions {
  -ms-flex-negative: 0;
  flex-shrink: 0;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

.thread-export-btn,
.thread-delete-btn {
  -ms-flex-negative: 0;
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: none;
  color: #888888;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  cursor: pointer;
  padding: 8px;
  text-align: center;
}

/* ── Chat screen ─────────────────────────────────────────────────────────── */
#screen-chat {
  max-width: none;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  padding-left: 0;
  padding-right: 0;
  padding-bottom: 0;
}

/* Chat sub-header — flex-shrink:0 keeps it pinned */
#chat-header {
  -ms-flex-negative: 0;
  flex-shrink: 0;
  width: 100%;
  background: #FFFFFF;
  border-bottom: 2px solid #CCCCCC;
}

#chat-header-inner {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding: 10px 20px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
}

.chat-nav-btn {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #111111;
  -ms-flex-negative: 0;
  flex-shrink: 0;
  padding: 0;
}

#chat-title-display {
  font-family: Georgia, serif;
  font-size: 15px;
  color: #111111;
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
  padding-left: 8px;
  padding-right: 8px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Persona bar — flex-shrink:0 */
#chat-persona-bar {
  -ms-flex-negative: 0;
  flex-shrink: 0;
  width: 100%;
  background: #EEEEEE;
  border-bottom: 1px solid #CCCCCC;
}

#chat-persona-bar-inner {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding: 6px 20px;
}

#chat-persona-name {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  color: #888888;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Message list — takes remaining space, scrolls internally */
#message-list {
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  width: 100%;
}

#message-list-inner {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding: 16px 20px;
}

.chat-empty-hint {
  font-family: Georgia, serif;
  font-size: 16px;
  color: #888888;
  text-align: center;
  margin-top: 32px;
  margin-bottom: 32px;
}

/* ── Message bubbles ─────────────────────────────────────────────────────── */
.message-wrap {
  margin-bottom: 16px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
}

/* User messages: right-aligned */
.message-user {
  -webkit-box-align: end;
  -ms-flex-align: end;
  align-items: flex-end;
}

/* Assistant messages: left-aligned */
.message-assistant {
  -webkit-box-align: start;
  -ms-flex-align: start;
  align-items: flex-start;
}

.message-role {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #888888;
  margin-top: 0;
  margin-bottom: 5px;
}

/* Bubble — no border-radius (e-ink sharp edges) */
.message-bubble {
  max-width: 82%;
  font-family: Georgia, serif;
  font-size: 16px;
  line-height: 1.65;
  padding: 10px 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* User bubble: inverted — black bg, white text */
.message-user .message-bubble {
  background: #111111;
  color: #FFFFFF;
  border: 2px solid #111111;
}

/* Assistant bubble: white bg, black border with offset shadow */
.message-assistant .message-bubble {
  background: #FFFFFF;
  color: #111111;
  border: 2px solid #111111;
  box-shadow: 3px 3px 0 #CCCCCC;
}

/* Extra bubbles in same message (multi-paragraph assistant replies) */
.message-bubble + .message-bubble {
  margin-top: 6px;
}

/* Chat status — always present, visibility toggled */
#chat-status {
  -ms-flex-negative: 0;
  flex-shrink: 0;
  width: 100%;
  visibility: hidden;
  min-height: 2em;
}

#chat-status-inner {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding: 6px 20px;
  font-family: Georgia, serif;
  font-size: 15px;
  color: #444444;
}

/* Chat input area — flex-shrink:0, stays at bottom */
#chat-input-area {
  -ms-flex-negative: 0;
  flex-shrink: 0;
  width: 100%;
  border-top: 2px solid #111111;
  background: #FFFFFF;
}

#chat-input-inner {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  padding: 12px 20px 16px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: flex-end;
  -ms-flex-align: flex-end;
  align-items: flex-end;
}

#chat-input {
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
  border: 2px solid #111111;
  font-family: Georgia, serif;
  font-size: 16px;
  padding: 10px 12px;
  min-height: 60px;
  resize: none;
  color: #111111;
  background: #FFFFFF;
  margin-right: 10px;
  display: block;
  outline: none;
}

#chat-input:focus {
  outline: 2px solid #111111;
  outline-offset: 1px;
}

#chat-send-btn {
  -ms-flex-negative: 0;
  flex-shrink: 0;
  min-width: 64px;
  min-height: 44px;
  background: #111111;
  color: #FFFFFF;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 1px;
  border: 2px solid #111111;
  cursor: pointer;
  padding: 10px 12px;
  -ms-flex-item-align: end;
  align-self: flex-end;
}

#chat-send-btn:focus {
  outline: 2px solid #444444;
  outline-offset: 2px;
}

/* ── New Chat modal ──────────────────────────────────────────────────────── */
#new-chat-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  background: #FFFFFF;
  overflow-y: auto;
}

#new-chat-modal-inner {
  max-width: 440px;
  margin-left: auto;
  margin-right: auto;
  padding: 32px 24px 40px;
}

#new-chat-modal-inner .section-label {
  font-size: 15px;
  margin-bottom: 4px;
}

/* Response length toggle buttons */
#new-chat-length-group {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  margin-top: 8px;
  margin-bottom: 4px;
}

.length-btn {
  -webkit-box-flex: 1;
  -ms-flex: 1 1 0%;
  flex: 1 1 0%;
  min-height: 44px;
  border: 2px solid #111111;
  background: #FFFFFF;
  color: #111111;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  cursor: pointer;
  padding: 10px 4px;
  text-align: center;
  margin-right: 8px;
}

.length-btn:last-child {
  margin-right: 0;
}

.length-btn.length-selected {
  background: #111111;
  color: #FFFFFF;
}

/* ── Export modal — full-screen overlay ──────────────────────────────────── */
#export-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  background: #FFFFFF;
  overflow-y: auto;
}

#export-modal-inner {
  max-width: 440px;
  margin-left: auto;
  margin-right: auto;
  padding: 40px 24px 40px;
}

#export-modal-inner .section-label {
  font-size: 15px;
  margin-bottom: 20px;
}

#export-modal-inner .btn-secondary {
  margin-top: 0;
  margin-bottom: 12px;
}

#export-modal-inner .btn-primary {
  margin-top: 8px;
  box-shadow: none;
}

.export-copy-hint {
  font-family: Georgia, serif;
  font-size: 14px;
  color: #444444;
  margin-top: 16px;
  margin-bottom: 8px;
}

.export-fallback-ta {
  display: block;
  width: 100%;
  height: 200px;
  border: 2px solid #111111;
  font-family: Georgia, serif;
  font-size: 14px;
  padding: 10px;
  background: #FFFFFF;
  color: #111111;
  resize: vertical;
}

/* ── Settings screen ─────────────────────────────────────────────────────── */
#settings-saved-msg {
  font-family: Georgia, serif;
  font-size: 16px;
  color: #444444;
  margin-top: 12px;
  margin-bottom: 0;
}

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid #CCCCCC;
  margin-top: 24px;
  margin-bottom: 24px;
}

/* ── Print / PDF export ──────────────────────────────────────────────────── */
#print-area {
  display: none;
}

@media print {
  #app-header,
  #screen-setup,
  #screen-home,
  #screen-settings,
  #chat-header,
  #chat-persona-bar,
  #chat-input-area,
  #export-modal,
  #chat-status,
  .screen:not(#screen-chat) {
    display: none !important;
  }

  html.layout-chat,
  body.layout-chat {
    height: auto !important;
    overflow: visible !important;
    display: block !important;
  }

  #screen-chat {
    display: block !important;
    overflow: visible !important;
    height: auto !important;
  }

  #message-list {
    display: none !important;
  }

  #print-area {
    display: block !important;
    padding: 20px;
  }

  body {
    font-size: 12pt;
    color: #000000;
  }

  #print-area h1 {
    font-family: Georgia, serif;
    font-size: 18pt;
    color: #000000;
    margin-bottom: 4pt;
  }

  .print-meta {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 9pt;
    color: #555555;
    margin-bottom: 16pt;
  }

  .print-message {
    margin-bottom: 14pt;
    page-break-inside: avoid;
  }

  .print-role {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 9pt;
    text-transform: uppercase;
    letter-spacing: 1pt;
    color: #555555;
    margin-bottom: 3pt;
  }

  .print-content {
    font-family: Georgia, serif;
    font-size: 11pt;
    line-height: 1.6;
    color: #000000;
    margin: 0;
  }
}
