/* ===========================================================================
   Ollama Web — stylesheet
   Self-hosted only: no external fonts, no CDN.
   =========================================================================== */

:root {
  --bg:        #0e1116;
  --bg-2:      #151a21;
  --bg-3:      #1c222b;
  --bg-hover:  #232b36;
  --border:    #2a323d;
  --text:      #e6ebf2;
  --text-dim:  #9aa7b8;
  --text-faint:#6b7889;
  --accent:    #5b9cf6;
  --accent-2:  #3d7fd6;
  --danger:    #e5574f;
  --ok:        #3fb950;
  --warn:      #d29922;
  --radius:    10px;
  --radius-sm: 7px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg:        #ffffff;
  --bg-2:      #f6f8fa;
  --bg-3:      #eceff3;
  --bg-hover:  #e3e8ee;
  --border:    #d6dce4;
  --text:      #1b2128;
  --text-dim:  #596574;
  --text-faint:#8793a3;
  --accent:    #2f6fd0;
  --accent-2:  #255bab;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* The hidden attribute gets display:none from the browser's own stylesheet,
   which loses to ANY author rule that sets display. Several components here do
   exactly that (.modal is grid, .inspector and .attachments are flex), so
   without this they ignore `hidden` and are permanently on screen. */
[hidden] { display: none !important; }

.hidden { display: none !important; }

/* ----------------------------------------------------------------- buttons */

.btn {
  font: inherit;
  color: var(--text);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }

.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-3); }
.btn-quiet { color: var(--text-dim); }

.btn-icon {
  padding: 0;
  width: 34px; height: 34px;
  display: inline-grid; place-items: center;
  font-size: 16px; line-height: 1;
  flex: 0 0 auto;
}

/* ------------------------------------------------------------------ inputs */

input[type="text"], input[type="password"], input[type="number"],
textarea, select {
  font: inherit;
  width: 100%;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
textarea { resize: vertical; font-family: inherit; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
select { cursor: pointer; }

.field { margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 5px;
  letter-spacing: .01em;
}
.field small, small {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.45;
}
.check {
  display: flex; align-items: center; gap: 9px;
  margin: 10px 0; font-size: 13.5px; color: var(--text-dim);
  cursor: pointer;
}
.check input { width: auto; cursor: pointer; }

code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 4px;
}

.hint {
  font-size: 12.5px;
  color: var(--text-faint);
  margin: 0 0 14px;
  line-height: 1.5;
}

/* ------------------------------------------------------------------ layout */

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}
.app.blurred { filter: blur(6px); pointer-events: none; }
.app:has(.inspector:not([hidden])) {
  grid-template-columns: 260px minmax(0, 1fr) 330px;
}

/* ----------------------------------------------------------------- sidebar */

.sidebar {
  display: flex; flex-direction: column;
  min-width: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
}
.sidebar-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.brand {
  flex: 1; min-width: 0;
  font-weight: 650; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-list { flex: 1; overflow-y: auto; padding: 8px; }

.chat-item {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text-dim);
}
.chat-item:hover { background: var(--bg-3); color: var(--text); }
.chat-item.active { background: var(--bg-hover); color: var(--text); }
.chat-item-title {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-del {
  opacity: 0; border: 0; background: none; color: var(--text-faint);
  cursor: pointer; font-size: 15px; padding: 0 3px; line-height: 1;
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--danger); }

.sidebar-foot {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px;
  border-top: 1px solid var(--border);
}
.sidebar-foot .btn { text-align: left; }

.whoami {
  padding: 5px 13px 2px;
  font-size: 11.5px;
  color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ------------------------------------------------------------------- main */

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.model-pick { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; }
.model-pick select { max-width: 340px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

.status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warn); flex: 0 0 auto;
}
.status.ok .dot   { background: var(--ok); }
.status.bad .dot  { background: var(--danger); }

/* --------------------------------------------------------------- messages */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 8px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 820px;
  margin: 0 auto 20px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 12px;
}
.avatar {
  width: 30px; height: 30px;
  border-radius: 7px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  background: var(--bg-3); color: var(--text-dim);
  user-select: none;
}
.msg.user .avatar      { background: var(--accent); color: #fff; }
.msg.assistant .avatar { background: #2f7d55; color: #fff; }
.msg.tool .avatar      { background: var(--warn); color: #000; }
.msg.error .avatar     { background: var(--danger); color: #fff; }

.bubble { min-width: 0; }
.msg-role {
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-faint);
  margin-bottom: 3px;
}
.content { overflow-wrap: anywhere; }
.content > *:first-child { margin-top: 0; }
.content > *:last-child  { margin-bottom: 0; }
.content p { margin: 0 0 11px; }
.content ul, .content ol { margin: 0 0 11px; padding-left: 22px; }
.content li { margin-bottom: 4px; }
.content h1, .content h2, .content h3 {
  margin: 18px 0 9px; line-height: 1.3; font-weight: 650;
}
.content h1 { font-size: 1.32em; }
.content h2 { font-size: 1.18em; }
.content h3 { font-size: 1.05em; }
.content blockquote {
  margin: 0 0 11px; padding: 2px 0 2px 13px;
  border-left: 3px solid var(--border); color: var(--text-dim);
}
.content hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.content table { border-collapse: collapse; margin: 0 0 11px; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.content th { background: var(--bg-3); font-weight: 600; }
.content :not(pre) > code { background: var(--bg-3); }

.codewrap {
  position: relative;
  margin: 0 0 13px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.codehead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 10px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--text-faint);
  font-family: var(--mono);
}
.codewrap pre { margin: 0; padding: 12px; overflow-x: auto; }
.codewrap pre code {
  background: none; padding: 0;
  font-family: var(--mono); font-size: 12.8px; line-height: 1.6;
}
.copy-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 5px;
  font-size: 11px; padding: 2px 8px; cursor: pointer;
}
.copy-btn:hover { background: var(--bg-hover); color: var(--text); }

.think {
  margin: 0 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
}
.think > summary {
  cursor: pointer; padding: 7px 11px;
  font-size: 12px; color: var(--text-dim); user-select: none;
}
.think > div {
  padding: 0 11px 10px;
  font-size: 13px; color: var(--text-dim);
  white-space: pre-wrap;
}

.toolcall {
  margin: 0 0 11px; padding: 9px 11px;
  border: 1px dashed var(--warn);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 9%, transparent);
  font-family: var(--mono); font-size: 12.3px;
  white-space: pre-wrap; overflow-x: auto;
}

.img-grid { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 9px; }
.img-grid img {
  max-width: 190px; max-height: 190px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}

.msg-actions { display: flex; gap: 6px; margin-top: 7px; opacity: 0; transition: opacity .12s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  background: none; border: 1px solid var(--border); color: var(--text-faint);
  border-radius: 5px; font-size: 11px; padding: 2px 8px; cursor: pointer;
}
.msg-actions button:hover { background: var(--bg-3); color: var(--text); }

.cursor {
  display: inline-block;
  width: 7px; height: 15px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.empty {
  max-width: 560px; margin: 12vh auto; text-align: center; color: var(--text-faint);
}
.empty h2 { color: var(--text); font-weight: 600; margin-bottom: 8px; }

.stats {
  max-width: 820px; margin: 0 auto;
  padding: 0 18px 6px 60px;
  font-size: 11.5px; color: var(--text-faint); font-family: var(--mono);
}

/* --------------------------------------------------------------- composer */

.composer {
  border-top: 1px solid var(--border);
  padding: 12px 18px 16px;
  background: var(--bg);
}
.composer-row {
  display: flex; align-items: flex-end; gap: 8px;
  max-width: 820px; margin: 0 auto;
}
#input { max-height: 220px; overflow-y: auto; resize: none; padding: 9px 11px; }

.attachments {
  display: flex; flex-wrap: wrap; gap: 7px;
  max-width: 820px; margin: 0 auto 9px;
}
.chip {
  position: relative;
  display: inline-flex; align-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--bg-2);
}
.chip img { width: 54px; height: 54px; object-fit: cover; display: block; }
.chip button {
  position: absolute; top: 1px; right: 1px;
  width: 17px; height: 17px;
  border: 0; border-radius: 4px;
  background: rgba(0,0,0,.65); color: #fff;
  font-size: 12px; line-height: 1; cursor: pointer;
}

/* -------------------------------------------------------------- inspector */

.inspector {
  display: flex; flex-direction: column;
  min-width: 0;
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  overflow: hidden;
}
.inspector-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 3px; flex: 1; min-width: 0; overflow-x: auto; }
.tab {
  font: inherit; font-size: 12.5px;
  background: none; border: 0; border-radius: 6px;
  color: var(--text-faint); padding: 5px 9px; cursor: pointer;
  white-space: nowrap;
}
.tab:hover { background: var(--bg-3); color: var(--text); }
.tab.active { background: var(--bg-hover); color: var(--text); }

.tab-panel, .mtab-panel { display: none; }
.tab-panel { padding: 14px; overflow-y: auto; }
.tab-panel.active, .mtab-panel.active { display: block; }

.fields { display: grid; gap: 12px; }
.fields .field { margin: 0; }

/* ----------------------------------------------------------------- modals */

.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(0,0,0,.6);
  padding: 18px;
}
.modal-card {
  width: 100%; max-width: 560px;
  max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  overflow: hidden;
}
.modal-wide { max-width: 760px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 15.5px; font-weight: 650; }
.modal-body { padding: 16px; overflow-y: auto; }
.tabs-sub { margin-bottom: 14px; }

.model-table { display: grid; gap: 7px; }
.model-row {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;                 /* user rows carry up to four actions */
  padding: 9px 11px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.model-row .mname {
  flex: 1 1 170px; min-width: 0;
  font-family: var(--mono); font-size: 12.8px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.model-row .btn { font-size: 12.5px; padding: 5px 10px; }
.model-row .msize { font-size: 11.5px; color: var(--text-faint); flex: 0 0 auto; }

.inline-form { display: flex; gap: 8px; margin-bottom: 13px; }

.progress { margin-bottom: 14px; }
.progress-bar {
  height: 6px; background: var(--bg-3);
  border-radius: 99px; overflow: hidden; margin-bottom: 5px;
}
.progress-fill {
  height: 100%; width: 0;
  background: var(--accent);
  transition: width .18s ease;
}
.progress-text { font-family: var(--mono); font-size: 11.5px; }

.library { display: grid; gap: 7px; margin-top: 6px; }
.library h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); margin: 14px 0 3px; font-weight: 600;
}
.lib-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.lib-info { flex: 1; min-width: 0; }
.lib-name { font-family: var(--mono); font-size: 12.8px; }
.lib-desc { font-size: 11.5px; color: var(--text-faint); }

.log {
  margin: 12px 0 0;
  padding: 10px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 11.8px;
  max-height: 220px; overflow: auto;
  white-space: pre-wrap; word-break: break-all;
}

.row-buttons { display: flex; flex-wrap: wrap; gap: 7px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------------------------------------------------- login / setup / toast */

.overlay {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background: var(--bg);
  padding: 20px;
}
.login-card, .setup-card {
  width: 100%; max-width: 340px;
  display: grid; gap: 11px;
  padding: 26px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.login-card h1, .setup-card h1 { margin: 0 0 4px; font-size: 19px; font-weight: 650; }
.login-error { margin: 0; color: var(--danger); font-size: 12.5px; min-height: 17px; }

.setup { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.setup-card { max-width: 560px; gap: 13px; }
.setup-card ol { margin: 0; padding-left: 20px; }
.setup-card li { margin-bottom: 7px; font-size: 13.5px; }
.setup-card p { margin: 0; color: var(--text-dim); font-size: 13.5px; }
.setup-note {
  padding: 11px; border-radius: var(--radius-sm);
  background: var(--bg-3); font-size: 12.5px !important;
}

.toasts {
  position: fixed; bottom: 18px; right: 18px; z-index: 100;
  display: grid; gap: 8px; max-width: 360px;
}
.toast {
  padding: 10px 13px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  animation: slide-in .16s ease;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok  { border-left-color: var(--ok); }
@keyframes slide-in { from { opacity: 0; transform: translateX(14px); } }

/* ----------------------------------------------------------------- mobile */

.mobile-only { display: none; }

@media (max-width: 900px) {
  .app, .app:has(.inspector:not([hidden])) { grid-template-columns: minmax(0, 1fr); }
  .mobile-only { display: inline-grid; }

  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    width: 260px;
    transform: translateX(-100%);
    transition: transform .18s ease;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }

  .inspector {
    position: fixed; inset: 0 0 0 auto; z-index: 50;
    width: min(330px, 86vw);
    border-left: 1px solid var(--border);
  }

  .messages  { padding: 16px 12px 6px; }
  .composer  { padding: 10px 12px 14px; }
  .stats     { padding-left: 12px; }
  .msg { grid-template-columns: 26px minmax(0, 1fr); gap: 9px; }
  .avatar { width: 26px; height: 26px; font-size: 10px; }
  .model-pick select { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
