/* ============================================================
   LINKERT CARB TUNER — NeuBrutalist UI
   Palette: teal · coral · amber · lavender · black · white
   Fonts: Bricolage Grotesque + Space Mono
   ============================================================ */

:root {
  /* Core palette */
  --black:        #0D0D0D;
  --white:        #FFFFFF;
  --teal:         #00C4A7;
  --teal-light:   #E4F8F4;
  --coral:        #F07272;
  --coral-dim:    #D85F5F;
  --amber:        #E8A020;
  --amber-dim:    #CC8C18;
  --lavender:     #C8BEE0;
  --lavender-dim: #B0A4CC;
  --mid-grey:     #BBBBBB;

  /* Semantic roles */
  --bg-app:       var(--teal-light);
  --bg-chat:      var(--teal-light);
  --bg-header:    var(--teal);
  --bg-input-bar: var(--teal-light);
  --bg-bot:       var(--white);
  --bg-user:      var(--coral);
  --bg-profile:   var(--white);
  --bg-chip:      var(--lavender);

  /* Text */
  --text-primary: var(--black);
  --text-dim:     #4A4A4A;
  --text-user:    var(--white);

  /* NeuBrutalist border + shadow system */
  --border-w:     2px;
  --border:       var(--border-w) solid var(--black);
  --shadow:       3px 3px 0 var(--black);
  --shadow-sm:    2px 2px 0 var(--black);
  --shadow-lg:    4px 4px 0 var(--black);

  /* Shape */
  --radius:       6px;

  /* Typography */
  --font:         'Bricolage Grotesque', 'Inter', system-ui, sans-serif;
  --font-mono:    'Space Mono', 'Courier New', monospace;
}

/* ---- Reset -------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--black);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---- App shell --------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg-chat);
  position: relative;
  border-left: var(--border);
  border-right: var(--border);
}

/* ---- Header ------------------------------------------ */
header {
  flex-shrink: 0;
  background: var(--bg-header);
  border-bottom: var(--border);
  padding: 0 14px;
  padding-top: env(safe-area-inset-top, 0);
  height: calc(60px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  z-index: 20;
}

.header-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--amber);
  border: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.header-info { flex: 1; min-width: 0; }

.header-info h1 {
  font-size: 15px;
  font-weight: 800;
  color: var(--black);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.header-info .header-sub {
  font-size: 10px;
  color: var(--black);
  margin-top: 1px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  font-family: var(--font-mono);
  opacity: 0.7;
}

.profile-toggle {
  flex-shrink: 0;
  background: var(--amber);
  border: var(--border);
  color: var(--black);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: transform 0.08s, box-shadow 0.08s;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.profile-toggle:active,
.profile-toggle.active {
  transform: translate(2px, 2px);
  box-shadow: none;
  background: var(--amber-dim);
}

/* ---- Profile panel ----------------------------------- */
#profile-panel {
  flex-shrink: 0;
  background: var(--bg-profile);
  border-bottom: var(--border);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.22s ease;
}
#profile-panel.open { max-height: 340px; }

.profile-inner {
  padding: 14px 16px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  font-size: 13px;
}

.profile-inner .p-title {
  grid-column: 1 / -1;
  font-size: 14px;
  font-weight: 800;
  color: var(--black);
  margin-bottom: 8px;
  border-bottom: var(--border);
  padding-bottom: 8px;
  letter-spacing: -0.01em;
}

.profile-inner .p-row {
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-mono);
}
.profile-inner .p-row span {
  color: var(--black);
  font-weight: 700;
}

.profile-edit-btn {
  grid-column: 1 / -1;
  margin-top: 10px;
  width: fit-content;
  background: var(--teal);
  border: var(--border);
  color: var(--black);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 800;
  padding: 7px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: transform 0.08s, box-shadow 0.08s;
}
.profile-edit-btn:active {
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* ---- Chat area --------------------------------------- */
#chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--bg-chat);
}
#chat::-webkit-scrollbar { width: 3px; }
#chat::-webkit-scrollbar-thumb { background: var(--black); border-radius: 0; }

/* ---- Message rows ------------------------------------ */
.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  animation: msgIn 0.18s ease-out both;
}
.msg-row.bot  { align-self: flex-start; }
.msg-row.user { align-self: flex-end; }

.msg-row + .msg-row.bot  { margin-top: 2px; }
.msg-row + .msg-row.user { margin-top: 2px; }
.msg-row.user + .msg-row.bot,
.msg-row.bot  + .msg-row.user { margin-top: 10px; }

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

/* ---- Bubbles ----------------------------------------- */
.bubble {
  padding: 10px 13px 8px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
  border: var(--border);
}

/* Bot bubble — white, hard shadow bottom-left */
.msg-row.bot .bubble {
  background: var(--bg-bot);
  box-shadow: var(--shadow);
  color: var(--text-primary);
}

/* User bubble — yellow, hard shadow bottom-right */
.msg-row.user .bubble {
  background: var(--bg-user);
  box-shadow: var(--shadow);
  color: var(--text-user);
}

/* Sarcasm — black bg, amber text */
.msg-row.bot.sarcasm .bubble {
  background: var(--black);
  color: var(--amber);
  font-style: italic;
  font-size: 13.5px;
  box-shadow: var(--shadow);
}

/* Timestamp */
.msg-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 3px;
  padding: 0 3px;
  font-family: var(--font-mono);
}
.msg-row.user .msg-time { text-align: right; }
.msg-row.bot  .msg-time { text-align: left; }

/* ---- Bubble content ---------------------------------- */
.bubble strong {
  color: var(--coral-dim);
  font-weight: 800;
}
.msg-row.user .bubble strong {
  color: var(--white);
}
.bubble em {
  color: var(--text-dim);
  font-style: italic;
}

/* Warning / ok tags */
.tag-warn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--amber);
  color: var(--black);
  border: var(--border);
  font-size: 11.5px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: var(--radius);
  margin: 3px 0;
  font-family: var(--font);
  box-shadow: var(--shadow-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.tag-ok {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--teal);
  color: var(--black);
  border: var(--border);
  font-size: 11.5px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: var(--radius);
  margin: 3px 0;
  font-family: var(--font);
  box-shadow: var(--shadow-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Bullet list */
.bubble ul {
  list-style: none;
  padding: 0;
  margin: 6px 0 2px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.bubble ul li {
  padding-left: 16px;
  position: relative;
  color: var(--text-primary);
  font-size: 14px;
}
.bubble ul li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--teal);
  font-size: 12px;
  top: 2px;
}
.msg-row.user .bubble ul li::before {
  color: var(--white);
}

/* Numbered list */
.bubble ol {
  list-style: none;
  padding: 0;
  margin: 6px 0 2px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  counter-reset: step-counter;
}
.bubble ol li {
  padding-left: 30px;
  position: relative;
  color: var(--text-primary);
  font-size: 14px;
  counter-increment: step-counter;
}
.bubble ol li::before {
  content: counter(step-counter);
  position: absolute;
  left: 0;
  top: 0px;
  width: 20px;
  height: 20px;
  background: var(--teal);
  color: var(--black);
  border: var(--border);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.msg-row.user .bubble ol li::before {
  background: var(--black);
  color: var(--amber);
}

/* ---- Day divider ------------------------------------- */
.day-chip {
  align-self: center;
  background: var(--black);
  color: var(--amber);
  border: var(--border);
  font-size: 10px;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 12px;
  border-radius: var(--radius);
  margin: 8px 0;
  box-shadow: var(--shadow-sm);
}

/* ---- Typing indicator -------------------------------- */
.typing-row {
  align-self: flex-start;
  animation: msgIn 0.18s ease-out both;
  margin-bottom: 2px;
}
.typing-bubble {
  background: var(--bg-bot);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  display: flex;
  gap: 6px;
  align-items: center;
  width: 58px;
}
.typing-bubble span {
  width: 7px;
  height: 7px;
  background: var(--black);
  border-radius: 50%;
  animation: typeBounce 1.1s infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.18s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.36s; }

@keyframes typeBounce {
  0%,60%,100% { transform: translateY(0); opacity: 0.3; }
  30%          { transform: translateY(-5px); opacity: 1; }
}

/* ---- Quick buttons ----------------------------------- */
#quick-btns {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 8px 12px 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-app);
  border-top: var(--border);
}
#quick-btns::-webkit-scrollbar { display: none; }

.quick-btn {
  white-space: nowrap;
  background: var(--bg-chip);
  border: var(--border);
  color: var(--black);
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 700;
  padding: 6px 13px;
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  transition: transform 0.08s, box-shadow 0.08s;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  -webkit-tap-highlight-color: transparent;
}
.quick-btn:active {
  background: var(--black);
  color: var(--amber);
  transform: translate(2px, 2px);
  box-shadow: none;
}

/* ---- Input bar --------------------------------------- */
#input-area {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-input-bar);
  border-top: var(--border);
}

#user-input {
  flex: 1;
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  color: var(--black);
  font-size: 15px;
  font-family: var(--font);
  font-weight: 500;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 72px;
  max-height: 160px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  transition: box-shadow 0.08s;
  caret-color: var(--teal);
}
#user-input:focus {
  box-shadow: 4px 4px 0 var(--black);
}
#user-input::placeholder {
  color: var(--mid-grey);
  font-weight: 400;
}

#send-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  background: var(--amber);
  border: var(--border);
  border-radius: var(--radius);
  color: var(--black);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s;
  -webkit-tap-highlight-color: transparent;
}
#send-btn:active {
  transform: translate(3px, 3px);
  box-shadow: none;
  background: var(--black);
  color: var(--amber);
}
#send-btn svg { stroke: currentColor; }

/* ---- Carb diagram ------------------------------------ */
.bubble .carb-diagram {
  display: block;
  width: 100%;
  max-width: 340px;
  border-radius: var(--radius);
  border: var(--border);
  margin: 8px 0 4px;
  box-shadow: var(--shadow);
}
.bubble .diagram-caption {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  font-family: var(--font-mono);
  font-style: italic;
}

/* ---- Desktop guard ----------------------------------- */
@media (min-width: 540px) {
  body { background: var(--coral); }
  #app { border-left: var(--border); border-right: var(--border); }
}
