/* ==========================================================================
   CodeShield — design tokens
   Color:   near-black blue base, teal/emerald "shield" accent, warm amber
            warning, coral danger. Chosen to read as a security tool, not a
            generic SaaS dashboard.
   Type:    Sora for UI/display, JetBrains Mono for all code surfaces.
   ========================================================================== */

:root {
  --bg: #0A0E13;
  --bg-raised: #0E141B;
  --surface: #131A22;
  --surface-2: #182029;
  --border: #232E3A;
  --border-soft: #1B2530;

  --text: #E8EEF3;
  --text-muted: #8C9BAC;
  --text-faint: #5C6B7C;

  --accent: #2DD4A7;
  --accent-strong: #1FB88E;
  --accent-ink: #05201A;

  --warning: #F0A93E;
  --warning-ink: #2A1B04;
  --danger: #F2545B;
  --danger-ink: #2A0A0C;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-lift: 0 10px 30px -12px rgba(0, 0, 0, 0.55);

  --font-ui: "Sora", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #F4F6F8;
  --bg-raised: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #EDF1F4;
  --border: #D8E0E6;
  --border-soft: #E4EAEE;

  --text: #101820;
  --text-muted: #56636F;
  --text-faint: #8B96A1;

  --accent: #0F9A78;
  --accent-strong: #0C7F63;
  --accent-ink: #E6FBF3;

  --warning: #A8660B;
  --warning-ink: #FDF1DC;
  --danger: #C23A42;
  --danger-ink: #FBE7E8;

  --shadow-lift: 0 10px 30px -14px rgba(20, 30, 40, 0.25);
}

/* ==========================================================================
   Reset / base
   ========================================================================== */

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

h1, h2, h3 { margin: 0; font-family: var(--font-ui); }

button { font-family: inherit; }

.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;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   Header
   ========================================================================== */

.topbar {
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-raised);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand__mark { width: 30px; height: 30px; flex-shrink: 0; }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand__tag { font-size: 0.72rem; color: var(--text-muted); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; }

#themeToggle .icon--sun { display: none; }
:root[data-theme="light"] #themeToggle .icon--sun { display: block; }
:root[data-theme="light"] #themeToggle .icon--moon { display: none; }

/* ==========================================================================
   Layout
   ========================================================================== */

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 260px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Panels (input / output)
   ========================================================================== */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-lift);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel__title { font-size: 0.95rem; font-weight: 600; }

.panel__toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 8px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.05s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--ghost { background: transparent; }
.btn--file { position: relative; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.btn--primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }

.link-btn {
  background: none; border: none; color: var(--accent);
  font-size: 0.78rem; cursor: pointer; padding: 0; text-decoration: underline;
  text-underline-offset: 2px;
}

/* Language row */
.lang-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.lang-row__detected strong { color: var(--text); text-transform: uppercase; letter-spacing: 0.02em; }
.lang-row__override { display: flex; align-items: center; gap: 6px; }
.lang-row__override select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.8rem;
  font-family: inherit;
}

/* Editor */
.editor {
  position: relative;
  display: flex;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  overflow: hidden;
  height: 360px;
}

.editor__gutter {
  flex-shrink: 0;
  width: 44px;
  padding: 12px 8px 12px 0;
  text-align: right;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: pre;
  overflow: hidden;
  background: var(--surface-2);
  border-right: 1px solid var(--border-soft);
  user-select: none;
}

.editor__area {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.6;
  padding: 12px 14px;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}

.editor__area::placeholder { color: var(--text-faint); }

.editor--output .editor__area { color: var(--text); }

.editor__footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* Fullscreen editor state */
.panel.is-fullscreen {
  position: fixed;
  inset: 12px;
  z-index: 50;
}
.panel.is-fullscreen .editor { height: calc(100vh - 220px); }

/* ==========================================================================
   Controls column
   ========================================================================== */

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 78px;
}

@media (max-width: 980px) {
  .controls { position: static; order: 3; }
}

.level-picker {
  border: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.level-picker legend {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 0 0 4px;
}

.level-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.level-card:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}
.level-card input { margin-top: 3px; accent-color: var(--accent); }
.level-card__body { display: flex; flex-direction: column; gap: 2px; }
.level-card__name { font-weight: 600; font-size: 0.88rem; }
.level-card__desc { font-size: 0.76rem; color: var(--text-muted); line-height: 1.4; }

.deterrent-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
}
.deterrent-toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.deterrent-note {
  margin: -6px 0 0;
  font-size: 0.74rem;
  color: var(--warning);
  background: var(--warning-ink);
  border: 1px solid color-mix(in srgb, var(--warning) 40%, transparent);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.btn--protect {
  justify-content: center;
  padding: 13px 16px;
  font-size: 0.92rem;
}
.btn__icon { width: 16px; height: 16px; fill: currentColor; }

.processing-note {
  margin: 0;
  font-size: 0.74rem;
  color: var(--text-faint);
  text-align: center;
}

/* ==========================================================================
   Stats
   ========================================================================== */

.stats {
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stats__row { display: flex; gap: 8px; }
.stat {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat__label { font-size: 0.68rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.03em; }
.stat__value { font-family: var(--font-mono); font-size: 0.88rem; font-weight: 600; }
.stat--accent .stat__value { color: var(--accent); }

/* ==========================================================================
   Security report
   ========================================================================== */

.report {
  max-width: 1280px;
  margin: 20px auto 0;
  padding: 0 24px;
}
.report__title { font-size: 0.95rem; font-weight: 600; margin-bottom: 10px; }
.report__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
}
.report__list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 0.82rem;
}
.report__list li.ok::before { content: "✓"; color: var(--accent); font-weight: 700; }
.report__list li.warn { border-color: color-mix(in srgb, var(--warning) 50%, var(--border)); background: color-mix(in srgb, var(--warning) 8%, var(--surface)); }
.report__list li.warn::before { content: "⚠"; color: var(--warning); font-weight: 700; }
.report__list li.err { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.report__list li.err::before { content: "✕"; color: var(--danger); font-weight: 700; }

/* ==========================================================================
   Toast
   ========================================================================== */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  box-shadow: var(--shadow-lift);
  z-index: 60;
}
.toast.toast--error { border-color: color-mix(in srgb, var(--danger) 60%, var(--border)); color: var(--danger); }

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 40px;
  color: var(--text-faint);
  font-size: 0.78rem;
  line-height: 1.6;
}
.footer strong { color: var(--text-muted); }
