@import './tokens.css';

* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  background: var(--bg-paper);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}
.app--embed {
  grid-template-columns: 1fr;
}

/* Sidebar */
.side {
  background: var(--black);
  color: var(--white);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 2px solid var(--black);
}
.side__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.side__brand img { width: 38px; height: 38px; border-radius: 6px; background: var(--white); padding: 4px; }
.side__brand-text { display: flex; flex-direction: column; gap: 2px; }
.side__brand-name { font-family: var(--font-display); font-weight: 800; letter-spacing: 0.4px; }
.side__brand-tag { font-size: 11px; color: rgba(255,255,255,0.55); }
.side__brand-tag b { color: var(--yellow); font-weight: 700; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side__item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  color: rgba(255,255,255,0.75);
  font-weight: 500;
  border-radius: var(--radius-2);
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.side__item:hover { color: var(--white); background: rgba(255,255,255,0.06); }
.side__item--active {
  color: var(--yellow); background: rgba(255,201,74,0.1); border-color: rgba(255,201,74,0.3);
}
.side__icon { width: 18px; height: 18px; opacity: 0.85; }
.side__group-label { text-transform: uppercase; font-size: 10.5px; letter-spacing: 1.4px; color: rgba(255,255,255,0.4); padding: 12px 12px 4px; }
.side__footer { margin-top: auto; font-size: 11px; color: rgba(255,255,255,0.4); padding: 8px 12px; line-height: 1.5; }
.side__footer a { color: var(--yellow); }

/* Main */
.main {
  padding: 28px 36px 64px;
  max-width: 100%;
  overflow-x: auto;
}
.main--embed { padding: 18px 22px 36px; }

/* Hero / page header */
.page-hero {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  justify-content: space-between;
  padding: 8px 0 22px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 26px;
}
.page-hero__title {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.1;
}
.page-hero__sub { color: var(--text-tertiary); font-size: 14px; margin-top: 6px; }
.hl {
  background: linear-gradient(180deg, transparent 60%, var(--yellow) 60%);
  padding: 0 4px;
}
.hl-soft {
  background: linear-gradient(180deg, transparent 60%, var(--yellow-dim) 60%);
  padding: 0 4px;
}
.hl-coral {
  background: linear-gradient(180deg, transparent 60%, var(--coral-dim) 60%);
  padding: 0 4px;
}

/* Card */
.card {
  background: var(--white);
  border: 2px solid var(--black);
  border-radius: var(--radius-3);
  padding: 18px;
}
.card--soft {
  border-color: var(--border-soft);
}
.card--accent {
  background: var(--yellow-dim);
  border-color: var(--black);
}
.card--shadow { box-shadow: var(--shadow-hard-soft); }
.card--shadow:hover { box-shadow: var(--shadow-hard-y); }
.card__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.2px;
  margin: 0 0 4px;
  display: flex; align-items: center; gap: 8px;
}
.card__sub { color: var(--text-tertiary); font-size: 12px; margin-bottom: 14px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 2px solid var(--black);
  background: var(--white); color: var(--black);
  padding: 9px 16px; border-radius: 999px;
  font-weight: 600; font-size: 13px;
  transition: transform 0.15s var(--ease), background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { background: var(--yellow); border-color: var(--black); color: var(--black); }
.btn--primary { background: var(--black); color: var(--white); }
.btn--primary:hover { background: var(--yellow); color: var(--black); }
.btn--ghost { background: transparent; }
.btn--ghost:hover { background: var(--g-100); }
.btn--small { padding: 6px 12px; font-size: 12px; }
.btn--coral { background: var(--coral); border-color: var(--coral); color: var(--white); }
.btn--coral:hover { background: var(--black); border-color: var(--black); color: var(--yellow); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Input */
.input, .textarea, .select {
  width: 100%;
  border: 2px solid var(--black);
  background: var(--white);
  border-radius: var(--radius-2);
  padding: 10px 12px;
  font-family: inherit; font-size: 13px;
  color: var(--text-primary);
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; box-shadow: 0 0 0 3px var(--yellow-dim);
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field__label {
  font-family: var(--font-display); font-weight: 700; font-size: 12px;
  text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-secondary);
}
.field__hint { color: var(--text-tertiary); font-size: 12px; }

/* Toggle */
.toggle {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none;
}
.toggle input { display: none; }
.toggle__slider {
  width: 38px; height: 22px; border-radius: 999px; background: var(--g-300); position: relative;
  border: 2px solid var(--black);
  transition: background 0.15s;
}
.toggle__slider::after {
  content: ''; position: absolute; top: 1px; left: 1px;
  width: 14px; height: 14px; background: var(--white); border-radius: 999px;
  transition: transform 0.18s var(--ease);
}
.toggle input:checked + .toggle__slider { background: var(--yellow); }
.toggle input:checked + .toggle__slider::after { transform: translateX(16px); }

/* KPI tile */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--white);
  border: 2px solid var(--black);
  border-radius: var(--radius-3);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.kpi__label { font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--text-tertiary); font-weight: 700; }
.kpi__value { font-family: var(--font-display); font-weight: 800; font-size: 30px; line-height: 1.1; margin-top: 6px; }
.kpi__trend { font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }
.kpi--accent { background: var(--yellow-dim); }
.kpi--coral { background: var(--coral-dim); }
.kpi--dark { background: var(--black); color: var(--white); border-color: var(--black); }
.kpi--dark .kpi__label { color: rgba(255,255,255,0.55); }
.kpi--dark .kpi__trend { color: rgba(255,255,255,0.6); }
.kpi__num {
  position: absolute; right: 10px; top: 8px;
  font-family: var(--font-display); font-weight: 800; font-size: 14px;
  color: rgba(0,0,0,0.15);
}
.kpi--dark .kpi__num { color: rgba(255,255,255,0.18); }

/* Score badge */
.score {
  display: inline-flex; align-items: baseline; gap: 4px;
  padding: 4px 10px;
  border: 2px solid var(--black);
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 800;
  background: var(--white);
}
.score--good { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.score--mid { background: var(--yellow-dim); border-color: var(--yellow-deep); color: var(--black); }
.score--bad { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.score__suffix { font-size: 11px; opacity: 0.7; font-weight: 600; }

/* Tables */
.tbl {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border: 2px solid var(--black);
  border-radius: var(--radius-3);
  overflow: hidden;
}
.tbl th, .tbl td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
  vertical-align: middle;
}
.tbl thead th {
  background: var(--bg-section);
  text-transform: uppercase; letter-spacing: 1px;
  font-size: 11px; font-weight: 800;
  color: var(--text-secondary);
}
.tbl tbody tr:hover { background: var(--bg-paper); }
.tbl tbody tr:last-child td { border-bottom: none; }

/* Two-col */
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 22px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 900px) { .three-col { grid-template-columns: 1fr; } }

/* Pills / chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1.5px solid var(--border-soft);
  border-radius: 999px; font-size: 12px; font-weight: 600;
  color: var(--text-secondary);
  background: var(--white);
}
.chip--yellow { background: var(--yellow-dim); border-color: var(--yellow-deep); color: var(--black); }
.chip--coral { background: var(--coral-dim); border-color: var(--coral); color: var(--coral); }
.chip--green { background: var(--green-dim); border-color: var(--green); color: var(--green); }
.chip--red { background: var(--red-dim); border-color: var(--red); color: var(--red); }
.chip--black { background: var(--black); color: var(--white); border-color: var(--black); }

/* Empty state */
.empty {
  border: 2px dashed var(--border-soft);
  border-radius: var(--radius-3);
  padding: 38px 28px;
  text-align: center;
  color: var(--text-tertiary);
  background: var(--white);
}
.empty__title { font-family: var(--font-display); font-weight: 800; font-size: 18px; color: var(--text-primary); margin-bottom: 6px; }

/* Inline numbered step */
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 999px;
  background: var(--yellow); color: var(--black);
  font-family: var(--font-display); font-weight: 800; font-size: 12px;
  border: 2px solid var(--black);
}

/* Lists */
.bullet {
  margin: 0; padding: 0 0 0 18px;
  display: flex; flex-direction: column; gap: 6px;
}
.bullet li { line-height: 1.55; }

/* Misc */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--text-tertiary); }
.divider { height: 1px; background: var(--border-soft); margin: 18px 0; }
.tag-line { font-family: var(--font-display); font-size: 11px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: 8px; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--g-300); border-top-color: var(--black);
  animation: sp 0.8s linear infinite;
  display: inline-block;
}
@keyframes sp { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--black); color: var(--white);
  border: 2px solid var(--black);
  padding: 10px 16px; border-radius: var(--radius-2);
  font-weight: 600;
  box-shadow: var(--shadow-hard-y);
  z-index: 9999;
}

/* Auth gate */
.gate {
  min-height: 100vh; display: grid; place-items: center; padding: 40px;
  background: linear-gradient(180deg, var(--bg-paper) 0%, var(--bg-section) 100%);
}
.gate__card {
  max-width: 520px; width: 100%; background: var(--white);
  border: 2px solid var(--black); border-radius: var(--radius-3);
  padding: 32px; box-shadow: var(--shadow-hard-y);
}
.gate__brand { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.gate__brand img { width: 56px; }

/* About / footer */
.app-footer {
  margin-top: 32px; padding: 16px 0; font-size: 12px;
  color: var(--text-tertiary); display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  border-top: 1px solid var(--border-soft);
}
.app-footer a { font-weight: 700; color: var(--text-primary); border-bottom: 2px solid var(--yellow); }

/* Embedded compact mode */
.embed-tab {
  padding: 18px 20px; max-width: 920px; margin: 0 auto;
}

.code {
  font-family: 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--bg-section);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-soft);
}

.dialog-source {
  background: var(--bg-section);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 13px;
}
.dialog-source__head {
  display: flex; gap: 8px; margin-bottom: 8px; align-items: center; flex-wrap: wrap;
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-tertiary); font-weight: 700;
}
.dialog-source__body { white-space: pre-wrap; line-height: 1.55; color: var(--text-secondary); max-height: 240px; overflow-y: auto; }

/* KB drop zone */
.kb-drop {
  margin-top: 12px;
  border: 2px dashed var(--border-soft);
  border-radius: var(--radius-3);
  padding: 18px;
  text-align: center;
  background: var(--bg-paper);
  transition: background 0.15s, border-color 0.15s;
}
.kb-drop--hot { border-color: var(--yellow-deep); background: var(--yellow-dim); }

/* Help launcher (bottom-right floating button) */
.help-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 9000;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 999px;
  background: var(--black); color: var(--yellow);
  border: 2px solid var(--black);
  font-family: var(--font-display); font-weight: 800; font-size: 13px;
  box-shadow: var(--shadow-hard-y);
  cursor: pointer;
  transition: transform 0.15s var(--ease);
}
.help-fab:hover { transform: translateY(-2px); }

/* Onboarding overlay */
.tour { position: fixed; inset: 0; z-index: 9100; pointer-events: none; }
.tour-dim {
  position: fixed; background: rgba(6, 9, 26, 0.58);
  pointer-events: auto;
  will-change: top, left, width, height;
}
/* Smooth transitions only when not scrolling — JS toggles via .tour--animating */
.tour--animating .tour-dim,
.tour--animating .tour-ring,
.tour--animating .tour-card {
  transition: top 0.42s cubic-bezier(0.22, 1, 0.36, 1),
              left 0.42s cubic-bezier(0.22, 1, 0.36, 1),
              width 0.42s cubic-bezier(0.22, 1, 0.36, 1),
              height 0.42s cubic-bezier(0.22, 1, 0.36, 1),
              right 0.42s cubic-bezier(0.22, 1, 0.36, 1),
              bottom 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}
.tour-dim--full { inset: 0; }
.tour-ring {
  position: fixed; pointer-events: none;
  border: 2px solid var(--yellow); border-radius: 12px;
  box-shadow: 0 0 0 4px rgba(255,201,74,0.35), 0 12px 36px rgba(0,0,0,0.35);
  animation: tour-pulse 1.8s ease-in-out infinite;
  will-change: top, left, width, height, box-shadow;
}
@keyframes tour-pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(255,201,74,0.30), 0 12px 36px rgba(0,0,0,0.35); }
  50%      { box-shadow: 0 0 0 10px rgba(255,201,74,0.50), 0 12px 36px rgba(0,0,0,0.45); }
}
.tour-card {
  background: var(--white);
  border: 2px solid var(--black); border-radius: var(--radius-3);
  padding: 22px;
  box-shadow: var(--shadow-hard-y);
  pointer-events: auto;
  opacity: 1;
}
.tour-card { transition: opacity 0.18s ease, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1); }
.tour-card--anchored { position: fixed; }
.tour-card--centered { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 540px; max-width: calc(100vw - 32px); }
.tour-card--fade { opacity: 0; transform: translateY(6px); }
.tour-card--fade.tour-card--centered { transform: translate(-50%, -48%); }
@media (max-width: 720px) {
  .tour-card--anchored { left: 16px !important; right: 16px; width: auto !important; top: auto !important; bottom: 16px; }
}
.tour-card__hero {
  display: flex; gap: 14px; align-items: flex-start;
}
.tour-mascot {
  width: 72px; height: 72px; flex: 0 0 72px;
  border-radius: 18px;
  background: var(--yellow-dim);
  border: 2px solid var(--black);
  display: flex; align-items: center; justify-content: center;
  font-size: 38px;
}
.tour-card__title {
  font-family: var(--font-display); font-weight: 800; font-size: 20px;
  margin: 0 0 6px;
}
.tour-card__step {
  font-family: var(--font-display); font-size: 11px; letter-spacing: 1.6px;
  color: var(--text-tertiary); text-transform: uppercase; margin-bottom: 6px;
}
.tour-card__body { line-height: 1.55; color: var(--text-secondary); margin: 14px 0 6px; font-size: 14px; }
.tour-card__hint {
  background: var(--bg-section); border-left: 3px solid var(--yellow);
  padding: 10px 12px; border-radius: 6px; font-size: 13px;
  color: var(--text-primary);
  margin: 12px 0 6px;
}
.tour-card__bottom {
  display: flex; justify-content: space-between; align-items: center; margin-top: 18px;
}
.tour-dots { display: flex; gap: 6px; }
.tour-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--g-300); }
.tour-dot--active { background: var(--black); }

/* --- Modal dialog --- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: modalFadeIn 0.18s ease-out;
}
.modal {
  background: var(--white);
  border: 2px solid var(--black);
  border-radius: 16px;
  box-shadow: 8px 8px 0 var(--black);
  padding: 26px 26px 22px;
  max-width: 460px; width: 100%;
  animation: modalSlideIn 0.2s ease-out;
}
@keyframes modalFadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes modalSlideIn {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

/* Period picker option (styled radio row) */
.period-option {
  display: flex; gap: 12px; align-items: flex-start;
  border: 2px solid var(--border-soft);
  border-radius: 10px; padding: 12px 14px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.period-option:hover { border-color: var(--g-300); }
.period-option--active {
  border-color: var(--black); background: var(--bg-section);
}
.period-option input[type="radio"] { margin-top: 4px; cursor: pointer; }

/* Support contact (bottom-left FAB, mirror of HelpFab) */
.support-fab {
  position: fixed; left: 22px; bottom: 22px; z-index: 9000;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 999px;
  background: var(--white); color: var(--black);
  border: 2px solid var(--black);
  font-family: var(--font-display); font-weight: 800; font-size: 13px;
  box-shadow: 4px 4px 0 var(--black);
  cursor: pointer;
  transition: transform 0.15s var(--ease);
}
.support-fab:hover { transform: translateY(-2px); }
.support-fab__dot {
  width: 8px; height: 8px; border-radius: 999px; background: var(--coral);
  box-shadow: 0 0 0 2px rgba(250,134,105,0.25);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}
