/* Shared design system for the Sfirew model apps (derived from Flora's UI). */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #ECEEF5;
  --surface:     #FFFFFF;
  --surface-alt: #F7F8FC;
  --border:      #E4E7EF;
  --accent:      #5B6CF9;
  --accent-soft: #EEF0FF;
  --accent-dark: #4452D8;
  --text:        #111827;
  --text-dim:    #6B7280;
  --text-muted:  #9CA3AF;
  --green:       #059669;
  --green-soft:  #ECFDF5;
  --amber:       #B45309;
  --amber-soft:  #FFFBEB;
  --red:         #DC2626;
  --red-soft:    #FEF2F2;
  --shadow-sm:   0 1px 2px rgba(0,0,0,0.05), 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md:   0 2px 4px rgba(0,0,0,0.05), 0 6px 24px rgba(0,0,0,0.08);
  --radius-card: 16px;
  --radius-btn:  10px;
  --mono: ui-monospace, 'SFMono-Regular', 'JetBrains Mono', Menlo, monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Noto Sans TC', sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select, textarea { font-family: inherit; }

/* ── Header ──────────────────────────────────────────────────── */
.app-header {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 0 28px;
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  flex-wrap: wrap;
}
.logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 7px;
}
.header-spacer { margin-left: auto; }

/* ── Segmented control ───────────────────────────────────────── */
.seg-control {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
}
.seg-control button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s;
  white-space: nowrap;
  line-height: 1;
}
.seg-control button.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);
}
.seg-control button:not(.active):hover { color: var(--text); }
.seg-control button:disabled { cursor: not-allowed; opacity: 0.55; }
.seg-control.small button { font-size: 12px; padding: 5px 10px; }

/* ── Card ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 18px 13px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 50px;
}
.card-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.card-meta { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.card-meta.over-limit { color: var(--red); }
.card-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

textarea.editor {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.65;
  padding: 16px 18px;
  resize: none;
  outline: none;
  min-height: 0;
}
textarea.editor::placeholder { color: var(--text-muted); }

.output-area {
  flex: 1;
  font-size: 15.5px;
  line-height: 1.65;
  padding: 16px 18px;
  overflow-y: auto;
  word-break: break-word;
  min-height: 0;
}
.output-area.plain { white-space: pre-wrap; }
.output-placeholder { color: var(--text-muted); font-style: italic; }

/* Blinking cursor */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: sf-blink 0.85s step-end infinite;
  margin-left: 1px;
  border-radius: 1px;
}
@keyframes sf-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  border-radius: var(--radius-btn);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.1s;
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { color: var(--text); border-color: var(--text-dim); background: var(--bg); }
.btn:disabled { cursor: not-allowed; opacity: 0.5; }
.btn.small { font-size: 12px; padding: 4px 10px; border-radius: 8px; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  padding: 8px 20px;
}
.btn.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn.primary:active:not(:disabled) { transform: scale(0.97); }
.btn.primary:disabled { background: var(--border); border-color: var(--border); color: var(--text-muted); opacity: 1; }
.btn.danger { color: var(--red); border-color: #FCA5A5; }
.btn.danger:hover:not(:disabled) { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.btn.copied { color: var(--green); border-color: var(--green); background: #F0FDF4; }
.push-right { margin-left: auto; }

/* ── Badges / pills ──────────────────────────────────────────── */
.badge {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 7px;
  padding: 4px 10px;
  letter-spacing: 0.1px;
  white-space: nowrap;
}
.badge.warn { color: var(--amber); background: var(--amber-soft); }
.badge.ok { color: var(--green); background: var(--green-soft); }
.badge.err { color: var(--red); background: var(--red-soft); }
.badge.muted { color: var(--text-dim); background: var(--bg); }
.hidden { display: none !important; }
.invisible { visibility: hidden; }
.error-text { color: var(--red); }
.muted { color: var(--text-muted); }

/* ── Stats ───────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.stat-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  flex-shrink: 0;
}
.stat-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-dim);
}
.stat-value { font-size: 15px; font-weight: 700; font-family: var(--mono); white-space: nowrap; }

/* ── Model bar ───────────────────────────────────────────────── */
.model-bar { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.model-bar select {
  max-width: 340px;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.model-bar .model-name { font-size: 13px; font-weight: 600; }
.model-bar .model-facts { font-size: 11.5px; color: var(--text-dim); font-family: var(--mono); }
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  margin-right: 5px;
}
.status-dot.ready { background: var(--green); }
.status-dot.generating, .status-dot.loading { background: var(--amber); animation: sf-blink 1s step-end infinite; }
.status-dot.error { background: var(--red); }

/* ── Forms ───────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-dim); }
.field input, .field select {
  font-size: 13px;
  font-weight: 500;
  padding: 6px 9px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  color: var(--text);
  background: var(--surface);
  font-family: var(--mono);
}
.field input:focus, .field select:focus, .model-bar select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field small { font-weight: 400; color: var(--text-muted); }

/* ── Markdown ────────────────────────────────────────────────── */
.md > * + * { margin-top: 0.7em; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { line-height: 1.35; margin-top: 1em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.22em; } .md h3 { font-size: 1.1em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md > :first-child { margin-top: 0; }
.md ul, .md ol { padding-left: 1.5em; }
.md li + li { margin-top: 0.2em; }
.md li > ul, .md li > ol { margin-top: 0.2em; }
.md code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 5px; padding: 0.05em 0.35em; }
.md pre { background: #0F172A; color: #E2E8F0; border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.md pre code { background: none; border: 0; padding: 0; color: inherit; font-size: 0.85em; }
.md blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-dim); }
.md hr { border: 0; border-top: 1px solid var(--border); }
.md table { border-collapse: collapse; font-size: 0.92em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.md th { background: var(--surface-alt); }
.md a { color: var(--accent-dark); }

/* ── Scrollbars ──────────────────────────────────────────────── */
.scroll::-webkit-scrollbar, .output-area::-webkit-scrollbar { width: 5px; height: 5px; }
.scroll::-webkit-scrollbar-track, .output-area::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb, .output-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--text);
  color: #fff;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  max-width: 380px;
}
.toast.err { background: var(--red); }
