/* Jeep Mechanic: dark, high contrast, big tap targets. */
:root {
  --bg: #0e0f0d;
  --panel: #171915;
  --panel-2: #1f221c;
  --line: #2f332a;
  --text: #f1efe6;
  --muted: #a6a895;
  --accent: #f2b420;      /* shop-light amber */
  --accent-ink: #1a1400;
  --danger: #ff6b57;
  --ok: #7fd36b;
  --radius: 12px;
  --tap: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.5 var(--font); -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Controls */
button, .btn {
  min-height: var(--tap); padding: 0 18px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font: 600 1rem var(--font); cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; text-decoration: none;
}
button:hover { border-color: #4a5040; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button.icon { width: var(--tap); padding: 0; font-size: 1.3rem; }
button.sm { min-height: 38px; padding: 0 12px; font-size: .9rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, select, textarea {
  width: 100%; min-height: var(--tap); padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: #0a0b09; color: var(--text); font: 1rem var(--font);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: .95rem; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.error-text { color: var(--danger); min-height: 1.5em; margin: 10px 0 0; }

/* Login */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: 100%; max-width: 420px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand .mark { width: 44px; height: 44px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 1.2rem; }
.brand h1 { font-size: 1.4rem; margin: 0; }
.card button.primary { width: 100%; margin-top: 20px; }

/* App shell */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }
.drawer { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.drawer-head { padding: 12px; border-bottom: 1px solid var(--line); }
.drawer-head button { width: 100%; }
.conv-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.conv-list li { display: flex; align-items: center; border-radius: 10px; }
.conv-list li.active { background: var(--panel-2); }
.conv-list .conv-open { flex: 1; min-width: 0; text-align: left; justify-content: flex-start; background: transparent; border: 0; padding: 10px 12px; display: block; font-weight: 500; }
.conv-list .conv-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-list .conv-meta { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; }
.conv-list .conv-del { opacity: .55; }
.conv-list li:hover .conv-del { opacity: 1; }
.scrim { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg); }
.topbar .title { font-weight: 800; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.pill { min-height: 40px; border-radius: 999px; padding: 0 14px; border: 1px solid var(--accent); color: var(--accent); background: transparent; font-weight: 600; max-width: 55vw; }
.pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#menuBtn { display: none; }

.thread { flex: 1; overflow-y: auto; padding: 16px; scroll-behavior: smooth; }
.thread-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.msg { padding: 12px 16px; border-radius: 14px; max-width: 100%; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--panel-2); border: 1px solid var(--line); max-width: 88%; white-space: pre-wrap; }
.msg.assistant { background: transparent; padding-left: 0; padding-right: 0; }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.msg.assistant strong { color: #fff; background: rgba(242,180,32,.14); padding: 0 3px; border-radius: 4px; }
.msg.assistant code { font-family: var(--mono); background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.msg.assistant pre { background: var(--panel); padding: 12px; border-radius: 10px; overflow-x: auto; }
.msg.assistant table { border-collapse: collapse; width: 100%; display: block; overflow-x: auto; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.msg.assistant li { margin: 4px 0; }
.msg.error { border: 1px solid var(--danger); color: var(--danger); }
.msg.user.blocked { opacity: .55; text-decoration: line-through; }
.msg.notice { align-self: center; border: 1px solid var(--accent); color: var(--accent); font-weight: 600; text-align: center; }
.searched { font-size: .82rem; color: var(--muted); margin-bottom: 8px; display: flex; gap: 6px; flex-wrap: wrap; align-items: baseline; }
.searched .q { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; }
.saved-note { font-size: .82rem; color: var(--ok); margin-top: 8px; }

.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.dots span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 4px; animation: bob 1s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: .15s; } .dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.empty { text-align: center; padding: 5vh 8px 0; }
.setup { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; max-width: 520px; margin: 18px auto 0; }
.setup-dt { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.setup-dt-summary { font-size: .92rem; color: var(--muted); }
.setup-dt button { flex: none; }
.setup-grid { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .setup-grid { grid-template-columns: 1fr 1fr; } }
.setup-field label, .setup-label { display: block; font-weight: 600; margin: 12px 0 6px; font-size: .9rem; }
.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; background: transparent; font-weight: 600; font-size: .92rem; padding: 0 8px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.setup-note { margin: 10px 0 0; }
dialog.help { width: min(640px, calc(100vw - 24px)); padding: 0; display: none; flex-direction: column; }
dialog.help[open] { display: flex; }
.help-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.help-head h2 { margin: 0; }
.help-body { padding: 4px 18px 20px; overflow-y: auto; line-height: 1.55; }
.help-body h3 { font-size: 1.02rem; margin: 20px 0 6px; color: var(--accent); }
.help-body ul { padding-left: 20px; margin: 6px 0; }
.help-body li { margin: 4px 0; }
.help-body p { margin: 6px 0; }
.chat-meta { align-self: center; font-size: .82rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; text-align: center; }
.empty h2 { font-size: 1.5rem; }
.starters { display: grid; gap: 10px; max-width: 520px; margin: 20px auto 0; }
.starters button { justify-content: flex-start; text-align: left; font-weight: 500; }

.composer { border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer form { max-width: 820px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 52px; max-height: 40vh; resize: none; }
.composer button { min-height: 52px; }
.composer .attach { width: 52px; flex: none; padding: 0; background: var(--panel-2); color: var(--text); }
.attach-tray { max-width: 820px; margin: 0 auto 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.tray-item { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.tray-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tray-remove { position: absolute; top: 2px; right: 2px; min-height: 0; width: 26px; height: 26px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.7); border: 0; font-size: 1rem; line-height: 1; }
.msg-photos { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.msg-photos img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; display: block; }
.msg-photos + .msg-text { margin-top: 8px; }

/* Sheets / dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.menu { position: absolute; right: 12px; top: 58px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; z-index: 30; min-width: 200px; display: flex; flex-direction: column; }
.menu button, .menu a { justify-content: flex-start; background: transparent; border: 0; width: 100%; }
.vehicle-opt { width: 100%; justify-content: flex-start; margin-bottom: 8px; }
.vehicle-opt.current { border-color: var(--accent); }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--panel-2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { border-color: var(--danger); color: var(--danger); }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .drawer { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .app.drawer-open .drawer { transform: none; }
  .app.drawer-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 15; }
  #menuBtn { display: inline-flex; }
  .topbar .title { display: none; }
  .conv-list .conv-del { opacity: 1; }
}

/* Admin */
.admin { max-width: 1100px; margin: 0 auto; padding: 16px 16px 60px; }
.admin header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.admin header h1 { margin: 0; font-size: 1.4rem; flex: 1; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.section-head h2 { margin: 0; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th { text-align: left; color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
table.data th, table.data td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data td.actions { white-space: nowrap; }
table.data td.actions button { margin: 0 4px 4px 0; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 700; border: 1px solid var(--line); }
.badge.on { border-color: var(--accent); color: var(--accent); }
.badge.done { border-color: var(--ok); color: var(--ok); }
.badge.error { border-color: var(--danger); color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.creds { background: #0a0b09; border: 1px dashed var(--accent); border-radius: 12px; padding: 14px; font-family: var(--mono); white-space: pre-wrap; margin-top: 12px; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-weight: 600; }
.check input { width: 22px; min-height: 22px; height: 22px; }
