/**
 * SEHU site theme tokens + theme control UI
 * data-theme is the resolved visual theme only: "light" | "dark"
 * User preference (system|light|dark) lives in localStorage (sehu-theme)
 */

/* Fallback before bootstrap (prefer FOUC script setting data-theme) */
:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --paper: #f4f6f9;
  --card: #ffffff;
  --text: #1b2a44;
  --muted: #5e6c84;
  --line: #dce2ec;
  --input-bg: #ffffff;
  --input-border: #dce2ec;
  --accent: #c4392c;
  --accent-soft: #f8e9e7;
  --result-bg: #f8e9e7;
  --result-text: #c4392c;
  --link: #1b2a44;
  --shadow: 0 12px 30px -18px rgba(27, 42, 68, 0.25);
  --shadow-soft: 0 12px 30px -18px rgba(27, 42, 68, 0.18);
  --shadow-fab: 0 8px 24px rgba(27, 42, 68, 0.22);
  --shadow-seg: 0 1px 3px rgba(27, 42, 68, 0.12);
  --shadow-btn: 0 1px 3px rgba(27, 42, 68, 0.16);
  --focus: #1b2a44;
  --overlay: rgba(27, 42, 68, 0.45);
  --fab-bg: #1b2a44;
  --fab-text: #ffffff;
  --on-ink: #ffffff;
  --tint: #eef2f8;
  --placeholder: #b9c2d0;
  --subtle: #93a0b4;
  --prose: #33415c;
  --row-alt: #fafbfd;
  --stamp-line: #e3c4bf;
  --ps-en: #a6b1c2;
  --seal-bg: rgba(255, 255, 255, 0.55);
  --theme-meta: #f4f6f9;
  --danger: #b54747;
  --danger-bg: #fff4f2;
  --danger-line: #f1c7c2;
  --note-strong: #475467;
  --note-soft: #667085;
  --scrollbar-track: #e8edf4;
  --scrollbar-thumb: #b6c0d0;

  /* Existing page aliases (index inline CSS) */
  --ink: var(--text);
  --stamp: var(--accent);
  --stamp-soft: var(--accent-soft);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f9;
  --paper: #f4f6f9;
  --card: #ffffff;
  --text: #1b2a44;
  --muted: #5e6c84;
  --line: #dce2ec;
  --input-bg: #ffffff;
  --input-border: #dce2ec;
  --accent: #c4392c;
  --accent-soft: #f8e9e7;
  --result-bg: #f8e9e7;
  --result-text: #c4392c;
  --link: #1b2a44;
  --shadow: 0 12px 30px -18px rgba(27, 42, 68, 0.25);
  --shadow-soft: 0 12px 30px -18px rgba(27, 42, 68, 0.18);
  --shadow-fab: 0 8px 24px rgba(27, 42, 68, 0.22);
  --shadow-seg: 0 1px 3px rgba(27, 42, 68, 0.12);
  --shadow-btn: 0 1px 3px rgba(27, 42, 68, 0.16);
  --focus: #1b2a44;
  --overlay: rgba(27, 42, 68, 0.45);
  --fab-bg: #1b2a44;
  --fab-text: #ffffff;
  --on-ink: #ffffff;
  --tint: #eef2f8;
  --placeholder: #b9c2d0;
  --subtle: #93a0b4;
  --prose: #33415c;
  --row-alt: #fafbfd;
  --stamp-line: #e3c4bf;
  --ps-en: #a6b1c2;
  --seal-bg: rgba(255, 255, 255, 0.55);
  --theme-meta: #f4f6f9;
  --danger: #b54747;
  --danger-bg: #fff4f2;
  --danger-line: #f1c7c2;
  --note-strong: #475467;
  --note-soft: #667085;
  --scrollbar-track: #e8edf4;
  --scrollbar-thumb: #b6c0d0;
  --ink: var(--text);
  --stamp: var(--accent);
  --stamp-soft: var(--accent-soft);
}

/* Deep navy-gray (no pure black / pure harsh white text)
   Pilot tweaks: muted +1 step brightness, clearer borders, softer FAB */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121a2a;
  --paper: #121a2a;
  --card: #1a2436;
  --text: #e8edf5;
  /* Secondary copy: brighter than before, still below body text */
  --muted: #b0bccc;
  --line: #4a5d76;
  --input-bg: #1a2436;
  --input-border: #526784;
  --accent: #e25548;
  --accent-soft: #3a2220;
  --result-bg: #3a2220;
  --result-text: #e25548;
  --link: #b8d0f0;
  --shadow: 0 14px 32px -16px rgba(0, 0, 0, 0.55);
  --shadow-soft: 0 12px 28px -14px rgba(0, 0, 0, 0.45);
  --shadow-fab: 0 10px 26px rgba(0, 0, 0, 0.4);
  --shadow-seg: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-btn: 0 1px 3px rgba(0, 0, 0, 0.35);
  --focus: #8eb4e8;
  --overlay: rgba(8, 12, 20, 0.65);
  /* FAB: navy slightly above card — not pure white */
  --fab-bg: #2b3c54;
  --fab-text: #e8edf5;
  --on-ink: #121a2a;
  --tint: #243044;
  --placeholder: #7d8ea5;
  --subtle: #a3b1c4;
  --prose: #c5d0e0;
  --row-alt: #162033;
  --stamp-line: #6b3a36;
  --ps-en: #a3b1c4;
  --seal-bg: rgba(26, 36, 54, 0.72);
  --theme-meta: #121a2a;
  --danger: #f0a0a0;
  --danger-bg: #3a2220;
  --danger-line: #6b3a36;
  --note-strong: #c0cad8;
  --note-soft: #aebacc;
  --scrollbar-track: #1a2436;
  --scrollbar-thumb: #4a5d78;
  --ink: var(--text);
  --stamp: var(--accent);
  --stamp-soft: var(--accent-soft);
}

/* ── Theme control (header, in-flow) ── */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  min-width: 0;
}

.site-header .eyebrow {
  margin-bottom: 0;
  margin-left: 0;
  margin-right: 0;
  justify-content: flex-start;
  text-align: left;
  flex: 1 1 auto;
  min-width: 0;
}

.theme-control {
  position: relative;
  flex: 0 0 auto;
  z-index: 30;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  max-width: 100%;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: var(--shadow-seg);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.theme-toggle:hover {
  border-color: var(--text);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.theme-toggle-icon {
  flex: 0 0 auto;
  display: block;
  width: 16px;
  height: 16px;
}

.theme-toggle-label {
  white-space: nowrap;
  line-height: 1;
}

.theme-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 148px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow-soft);
  z-index: 35;
}

.theme-menu[hidden] {
  display: none !important;
}

.theme-option {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.theme-option:hover {
  background: var(--tint);
}

.theme-option:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
}

.theme-option[aria-checked="true"] {
  background: var(--tint);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}

@media (max-width: 360px) {
  .theme-toggle {
    padding: 7px 9px;
    gap: 4px;
  }
  .theme-toggle-label {
    font-size: 12px;
  }
  .site-header .eyebrow {
    letter-spacing: 0.08em;
    font-size: 11.5px;
  }
}

/* Scrollbar (where supported) */
html[data-theme="dark"] {
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

html[data-theme="dark"] ::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

html[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

html[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
  border: 2px solid var(--scrollbar-track);
}

/* Seal: avoid light-only multiply look on dark surfaces */
html[data-theme="dark"] .seal {
  mix-blend-mode: normal;
  opacity: 0.9;
  background: var(--seal-bg);
}

/*
 * Freelancer 3.3% payslip — 실지급액 card only (#pane-w).
 * Drop brown-red fill; navy surface + coral number/left bar.
 * Nudge seal slightly up-right and slightly smaller (away from amount).
 */
html[data-theme="dark"] #pane-w .net {
  background: var(--tint);
  box-shadow: inset 3px 0 0 var(--accent);
}

html[data-theme="dark"] #pane-w .net .lbl {
  color: var(--muted);
}

html[data-theme="dark"] #pane-w .net .val {
  color: var(--accent);
}

html[data-theme="dark"] #pane-w .net .leader {
  border-bottom-color: #5a6b84;
}

html[data-theme="dark"] #pane-w .net .seal {
  right: 0;
  top: -42px; /* ~8px higher than previous -34px; size unchanged */
  width: 50px;
  height: 50px;
  font-size: 11px;
  line-height: 1.2;
}

/* Raise-sim delta cards only: drop brown-red fill; navy card + coral number */
html[data-theme="dark"] .raise-item-up {
  background: var(--tint);
  box-shadow: inset 3px 0 0 var(--accent);
}

html[data-theme="dark"] .raise-item-up .k {
  color: var(--muted);
}

html[data-theme="dark"] .raise-item-up .v {
  color: var(--accent);
}

/* Share button (dark): soften near-white fill — slate navy, keep contrast */
html[data-theme="dark"] .raise-share-btn {
  background: #3a4d66;
  color: #e8edf5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

html[data-theme="dark"] .raise-share-btn:hover {
  opacity: 1;
  background: #455a75;
}

html[data-theme="dark"] .raise-share-btn:active {
  background: #324257;
}

html[data-theme="dark"] .raise-share-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

html[data-theme="dark"] .raise-share-btn .raise-share-icon {
  color: inherit;
}

/*
 * Freelancer top tabs (dark): selected must not use --ink (near-white).
 * Border matches fill (no double edge); keyboard focus-visible only, 1px.
 */
html[data-theme="dark"] .tabs button[aria-selected="true"] {
  background: #3a4d66;
  border-color: #3a4d66;
  color: #e8edf5;
}

html[data-theme="dark"] .tabs button[aria-selected="true"]:hover {
  background: #455a75;
  border-color: #455a75;
  color: #e8edf5;
}

html[data-theme="dark"] .tabs button[aria-selected="true"]:active {
  background: #324257;
  border-color: #324257;
  color: #e8edf5;
}

html[data-theme="dark"] .tabs button[aria-selected="false"]:active {
  background: var(--card);
  border-color: var(--line);
  color: var(--muted);
}

/* Mouse click leaves :focus — suppress ring; keyboard keeps thin ring */
html[data-theme="dark"] .tabs button:focus:not(:focus-visible) {
  outline: none;
}

html[data-theme="dark"] .tabs button:focus-visible {
  outline: 1px solid var(--focus);
  outline-offset: 1px;
}
