*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #060a12;
  --surface:   #0a1020;
  --surface2:  #0f1830;
  --border:    #1a2a4a;
  --blue:      #00d4ff;
  --blue-dim:  #005580;
  --text:      #c8e0f0;
  --text-muted:#4a7090;
  --text-dim:  #2a4060;
  --red:       #ff4466;
  --green:     #00ffaa;
  --sans:      -apple-system, 'Helvetica Neue', sans-serif;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

html {
  height: 100%;
  height: 100svh;
}

body {
  height: 100%;
  height: 100svh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
}

#app {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Screens ── */
.screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Setup ── */
#setup-screen {
  justify-content: flex-start;
  align-items: center;
  padding: 1.25rem 1.25rem;
  padding-top: calc(var(--safe-top) + 1.25rem);
  padding-bottom: calc(var(--safe-bottom) + 1.25rem);
  padding-left: calc(var(--safe-left) + 1.25rem);
  padding-right: calc(var(--safe-right) + 1.25rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.setup-inner {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.setup-emblem {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  filter: drop-shadow(0 0 12px #00d4ff55);
}

#setup-screen h1 {
  font-size: 1.5rem;
  font-weight: 300;
  letter-spacing: 0.16em;
  color: var(--blue);
  text-shadow: 0 0 20px #00d4ff66;
  margin-bottom: 0.4rem;
}

.setup-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.field {
  text-align: left;
  margin-bottom: 0.75rem;
}

.field label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

.field input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}

.field input:focus {
  border-color: var(--blue-dim);
  box-shadow: 0 0 0 1px #00d4ff22;
}

.btn-google {
  width: 100%;
  background: #4285f4;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 0.75rem;
  transition: background 0.15s;
}

.btn-google:active { background: #3367d6; }

.google-status {
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
  text-align: center;
  min-height: 1rem;
}

.google-status.success { color: var(--green); }
.google-status.error { color: var(--red); }

.sheet-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.5rem;
}

.sheet-field textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.65rem 0.9rem;
  font-size: 0.95rem;
  font-family: var(--sans);
  outline: none;
  -webkit-appearance: none;
  width: 100%;
  caret-color: var(--blue);
  resize: none;
}

.sheet-field textarea:focus { border-color: var(--blue-dim); }
.sheet-field textarea::placeholder { color: var(--text-dim); }

/* ── Buttons ── */
.btn-test {
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 0.65rem;
  font-size: 0.88rem;
  cursor: pointer;
  margin-bottom: 0.75rem;
  transition: background 0.15s;
}

.btn-test:active { background: var(--surface2); }

#test-result {
  font-size: 0.82rem;
  min-height: 1.2rem;
  margin-bottom: 0.75rem;
  text-align: center;
}

.btn-primary {
  width: 100%;
  background: var(--blue);
  color: #060a12;
  border: none;
  border-radius: 12px;
  padding: 0.9rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 0.5rem;
  letter-spacing: 0.06em;
  box-shadow: 0 0 20px #00d4ff44;
  transition: opacity 0.15s;
}

.btn-primary:active { opacity: 0.85; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s, transform 0.1s;
  -webkit-touch-callout: none;
  user-select: none;
}

.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { color: var(--blue); transform: scale(0.88); }

/* Even smaller footer buttons to fit on narrow screens */
@media (max-width: 420px) {
  .footer-btn svg { width: 18px; height: 18px; }
  .footer-btn { padding: 0.25rem; }
  #main-screen footer { gap: 0.15rem; padding: 0.4rem 0.4rem; padding-bottom: max(0.4rem, var(--safe-bottom)); }
  #message-input { font-size: 0.9rem; padding: 0.5rem 0.75rem; }
  .btn-send { width: 34px; height: 34px; }
  .btn-send svg { width: 16px; height: 16px; }
}

/* ── Main screen ── */
#main-screen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#main-screen header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  padding-top: calc(var(--safe-top) + 0.85rem);
  padding-left: calc(var(--safe-left) + 1.25rem);
  padding-right: calc(var(--safe-right) + 1.25rem);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--blue);
  text-shadow: 0 0 12px #00d4ff55;
}

.header-emblem { width: 22px; height: 22px; }

/* ── Chat log ── */
#chat-log {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
  min-width: 0;
  min-height: 0;
}

/* ── Message bubbles ── */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  min-width: 0;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.ahab {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
  padding: 0 0.25rem;
}

.bubble {
  padding: 0.65rem 0.9rem;
  border-radius: 16px;
  font-size: 0.97rem;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: break-word;
}

.msg.user .bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.msg.ahab .bubble {
  background: #001a2e;
  border: 1px solid var(--blue-dim);
  color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 0 12px #00d4ff18;
}

/* ── Typing indicator ── */
.bubble.typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.75rem 1rem;
}

.bubble.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
  opacity: 0.4;
  animation: blink 1.2s infinite;
}

.bubble.typing span:nth-child(2) { animation-delay: 0.2s; }
.bubble.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.4; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.2); }
}

/* ── Attachment preview (between chat and footer) ── */
#attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  padding: 0.5rem 1rem;
}

#attachment-info {
  font-size: 0.82rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn.small svg { width: 16px; height: 16px; }

/* ── Footer / input bar ── */
#main-screen footer {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.5rem;
  padding-bottom: max(0.5rem, var(--safe-bottom));
  padding-left: calc(var(--safe-left) + 0.5rem);
  padding-right: calc(var(--safe-right) + 0.5rem);
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: nowrap;
  flex-shrink: 0;
  overflow: hidden;
}

.footer-btn svg { width: 20px; height: 20px; }
.footer-btn { padding: 0.3rem; flex-shrink: 0; }

#message-input {
  flex: 1;
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 22px;
  color: var(--text);
  padding: 0.55rem 0.85rem;
  font-size: 0.95rem;
  font-family: var(--sans);
  outline: none;
  -webkit-appearance: none;
  caret-color: var(--blue);
  transition: border-color 0.15s;
}

#message-input:focus {
  border-color: var(--blue-dim);
}

#message-input::placeholder { color: var(--text-dim); }

.btn-send {
  width: 36px;
  height: 36px;
  background: var(--blue);
  color: #060a12;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 14px #00d4ff44;
  transition: opacity 0.15s;
}

.btn-send svg { width: 18px; height: 18px; }
.btn-send:active { opacity: 0.8; }
.btn-send:disabled { opacity: 0.3; cursor: default; box-shadow: none; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 1.25rem;
  border-radius: 20px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 100;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast.success { border-color: var(--green); color: var(--green); }
#toast.error   { border-color: var(--red);   color: var(--red);   }

/* ── Recording state ── */
#voice-btn.recording {
  color: var(--red);
  animation: pulse-rec 1s ease-in-out infinite;
}

@keyframes pulse-rec {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

#attachment-preview.recording #attachment-info {
  color: var(--red);
}

/* ── Sheet backdrop ── */
#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 18, 0.7);
  z-index: 200;
}

/* ── Task capture sheet ── */
.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 1.25rem 1.25rem max(1.25rem, var(--safe-bottom));
  padding-left: calc(var(--safe-left) + 1.25rem);
  padding-right: calc(var(--safe-right) + 1.25rem);
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 90vh;
  overflow-y: auto;
}

.sheet:not(.hidden) {
  transform: translateY(0);
}

.sheet-inner {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.sheet-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--blue);
}

.sheet-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sheet-field label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.sheet-field input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 0.65rem 0.9rem;
  font-size: 0.95rem;
  font-family: var(--sans);
  outline: none;
  -webkit-appearance: none;
  width: 100%;
  caret-color: var(--blue);
}

.sheet-field input:focus { border-color: var(--blue-dim); }
.sheet-field input::placeholder { color: var(--text-dim); }
.sheet-field input[type="date"] { color-scheme: dark; }

.sheet-row {
  display: flex;
  gap: 0.75rem;
}

.sheet-field.half { flex: 1; }

/* ── Priority pills ── */
.pill-group {
  display: flex;
  gap: 0.5rem;
}

.pill {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  padding: 0.45rem 0.25rem;
  font-size: 0.78rem;
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.pill.active {
  background: #001a2e;
  border-color: var(--blue);
  color: var(--blue);
}

.pill[data-value="urgent"].active { border-color: var(--red); color: var(--red); background: #1a0010; }
.pill[data-value="low"].active    { border-color: var(--text-dim); color: var(--text-muted); }
