/* =====================================================
   style.css — base + components
   ===================================================== */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--gradient-app);
  color: var(--text-1);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

/* Typography */
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p  { margin: 0 0 8px; line-height: 1.5; color: var(--text-2); }
.muted { color: var(--text-3); font-size: 13px; }
.small { font-size: 12px; }
code {
  background: rgba(255,255,255,0.06);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 13px;
}

/* ===== Layout ===== */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px calc(12px + env(safe-area-inset-top, 0px));
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: rgba(0,0,0,0.18);
  backdrop-filter: saturate(150%) blur(10px);
  -webkit-backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--surface-stroke);
}
.appbar__title { display: flex; align-items: center; gap: 10px; }
.appbar__title h1 { font-size: 18px; font-weight: 700; }
.appbar__title #appbar-icon { font-size: 22px; }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px 100px;
}

.page { display: none; animation: pageIn 250ms ease-out; }
.page--active { display: block; }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  background-image: var(--gradient-card);
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  padding: 16px;
  margin: 0 0 14px;
}
.card__title { font-size: 16px; margin-bottom: 10px; color: var(--text-1); }
.subtitle    { font-size: 14px; color: var(--text-2); margin: 6px 0; }
.divider {
  border: 0;
  border-top: 1px solid var(--surface-stroke);
  margin: 14px 0;
}

/* ===== Form fields ===== */
.field { display: block; margin: 0 0 12px; }
.field__label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field__input {
  width: 100%;
  background: var(--surface-2);
  color: var(--text-1);
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
}
.field__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.18);
}
textarea.field__input { resize: vertical; min-height: 70px; }

/* ===== Buttons ===== */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text-1);
  --btn-bd: var(--surface-stroke);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-input);
  cursor: pointer;
  transition: transform 120ms, background 120ms, border-color 120ms, opacity 120ms;
  user-select: none;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--primary {
  --btn-bg: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 75%, black));
  --btn-fg: #06140d;
  --btn-bd: transparent;
  color: #06140d;
}
[data-theme="midnight"] .btn--primary { --btn-fg: #100923; color: #100923; }
[data-theme="light"]    .btn--primary { --btn-fg: #ffffff; color: #ffffff; }
.btn--accent {
  --btn-bg: var(--accent-soft);
  --btn-fg: var(--accent);
  --btn-bd: color-mix(in srgb, var(--accent) 40%, transparent);
}
.btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--text-1);
  --btn-bd: var(--surface-stroke);
}
.btn--danger {
  --btn-bg: color-mix(in srgb, var(--error) 15%, transparent);
  --btn-fg: var(--error);
  --btn-bd: color-mix(in srgb, var(--error) 35%, transparent);
}

/* spinner */
.btn__spinner, .gate__form .btn__spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn[aria-busy="true"] .btn__label { opacity: 0.7; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-1);
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

/* row layouts */
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Errors ===== */
.error {
  background: color-mix(in srgb, var(--error) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--error) 35%, transparent);
  color: var(--error);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-top: 8px;
}
.success-text { color: var(--success); font-weight: 600; }

/* ===== Bottom nav ===== */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: rgba(6, 18, 14, 0.7);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--surface-stroke);
}
[data-theme="light"] .bottom-nav { background: rgba(255, 255, 255, 0.85); }
[data-theme="midnight"] .bottom-nav { background: rgba(10, 8, 22, 0.7); }

.nav__btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 4px;
  cursor: pointer;
  border-radius: 12px;
  transition: color 150ms, background 150ms;
}
.nav__btn:hover { color: var(--text-2); }
.nav__btn--active {
  color: var(--accent);
  background: var(--accent-soft);
}
.nav__icon { font-size: 18px; line-height: 1; }
.nav__label { font-size: 10.5px; }

/* ===== Generator ===== */
.form-card__actions { margin-top: 4px; }
.results { display: grid; gap: 14px; }

.result-group {
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-card);
  background: var(--surface);
  background-image: var(--gradient-card);
  overflow: hidden;
}
.result-group__head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--surface-stroke);
  display: flex;
  align-items: center;
  gap: 10px;
}
.result-group__name { font-weight: 700; font-size: 14px; }
.result-group__body { display: grid; gap: 10px; padding: 12px; }

.result-card {
  border: 1px solid var(--surface-stroke);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-2);
}
.result-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge--single { background: rgba(255,255,255,0.08); color: var(--text-2); }
.result-card__text {
  white-space: pre-wrap;
  font-size: 14px;
  color: var(--text-1);
  margin: 0 0 10px;
  line-height: 1.55;
}
.result-card__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
  height: 14px;
  margin: 6px 0;
}
.skeleton--lg { height: 22px; }
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.combine-wrap { margin-top: 8px; }
.combined { margin-top: 12px; }

/* ===== List items (history, commission) ===== */
.list { display: grid; gap: 10px; }
.list-item {
  background: var(--surface);
  background-image: var(--gradient-card);
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-card);
  padding: 12px 14px;
}
.list-item__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.list-item__title { font-weight: 700; font-size: 14px; }
.list-item__meta { font-size: 12px; color: var(--text-3); }
.list-item__body {
  font-size: 14px;
  color: var(--text-2);
  white-space: pre-wrap;
  max-height: 80px;
  overflow: hidden;
  position: relative;
  transition: max-height 200ms ease;
}
.list-item__body.expanded { max-height: 9999px; }
.list-item__body::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 24px;
  background: linear-gradient(180deg, transparent, var(--surface));
  pointer-events: none;
}
.list-item__body.expanded::after { display: none; }
.list-item__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

/* ===== Stat cards ===== */
.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
@media (min-width: 540px) {
  .stat-row { grid-template-columns: repeat(4, 1fr); }
}
.stat { padding: 12px; }
.stat__label { font-size: 12px; color: var(--text-3); display: block; margin-bottom: 4px; }
.stat__value { font-size: 18px; font-weight: 800; color: var(--text-1); }

.chart-wrap {
  position: relative;
  width: 100%;
  height: 220px;
}

/* ===== FAB ===== */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 70%, black));
  color: #06140d;
  border: none;
  font-size: 28px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-strong);
  z-index: 35;
  transition: transform 150ms;
}
[data-theme="midnight"] .fab { color: #100923; }
[data-theme="light"]    .fab { color: #ffffff; }
.fab:hover { transform: scale(1.05); }
.fab:active { transform: scale(0.97); }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.toolbar--center { justify-content: center; }

.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--surface-stroke);
  border-radius: var(--radius-pill);
  padding: 3px;
}
.seg__btn {
  background: transparent;
  border: none;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text-2);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-weight: 600;
}
.seg__btn--active {
  background: var(--accent);
  color: #06140d;
}
[data-theme="midnight"] .seg__btn--active { color: #100923; }
[data-theme="light"]    .seg__btn--active { color: #ffffff; }

/* ===== Settings : providers ===== */
.providers { display: grid; gap: 10px; }
.provider-panel { display: grid; gap: 10px; margin-top: 10px; }
.provider {
  border: 1px solid var(--surface-stroke);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
}
.provider__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.provider__name { font-weight: 700; font-size: 14px; }
.provider__body { display: grid; gap: 8px; margin-top: 8px; }
.builtin-styles {
  display: grid; gap: 8px;
}
.builtin-style {
  border: 1px solid var(--surface-stroke);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
}
.builtin-style__name { font-weight: 700; font-size: 14px; }
.builtin-style__desc { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ===== Accent picker ===== */
.accent-row { display: flex; gap: 8px; }
.accent {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 100ms, border-color 100ms;
}
.accent:hover { transform: scale(1.08); }
.accent--active { border-color: var(--text-1); }

/* ===== Modal ===== */
.modal-root {
  position: fixed; inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: 60;
  animation: fadeIn 180ms ease-out;
}
@media (min-width: 540px) {
  .modal-root { align-items: center; }
}
.modal {
  width: min(440px, 100%);
  background: var(--surface);
  background-image: var(--gradient-card);
  border: 1px solid var(--surface-stroke);
  border-radius: 18px 18px 0 0;
  padding: 16px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-strong);
}
@media (min-width: 540px) { .modal { border-radius: 18px; } }
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.modal__title { font-size: 16px; font-weight: 700; }
.modal__actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== Gate (login) ===== */
.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate__shell { width: 100%; max-width: 380px; }
.gate__card { padding: 28px 22px; }
.gate__brand { text-align: center; margin-bottom: 20px; }
.gate__logo { font-size: 42px; }
.gate__hint { text-align: center; margin-top: 12px; }

/* ===== Toast ===== */
.toast-stack {
  position: fixed;
  z-index: 70;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  width: min(360px, calc(100% - 24px));
}
.toast {
  background: var(--surface);
  border: 1px solid var(--surface-stroke);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow-strong);
  font-size: 13px;
  animation: toastIn 220ms ease-out;
}
.toast--success { border-color: color-mix(in srgb, var(--success) 50%, transparent); }
.toast--error { border-color: color-mix(in srgb, var(--error) 50%, transparent); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* hide hidden */
[hidden] { display: none !important; }
