/* Lakuhan Buyer Dashboard — Calm Editorial Craft & Strict WCAG 2.2 AAA */
:root {
  --bd-bg: #f5f5f0;
  --bd-surface: #ffffff;
  --bd-surface-2: #f0f2ec;
  --bd-border: #c9d1c6;
  --bd-ctrl-border: #6b7870;
  --bd-ink: #141c17;
  --bd-muted: #3d4a41;
  --bd-accent: #1b3f2d;
  --bd-accent-hover: #132e20;
  --bd-accent-soft: #e4ede7;
  --bd-accent-ink: #123322;
  --bd-link: #1a422e;
  --bd-focus: #143322;
  --bd-danger: #9b1c1c;
  --bd-danger-bg: #fef2f2;
  --bd-danger-ink: #7f1d1d;
  --bd-warn-bg: #fffbeb;
  --bd-warn-border: #92400e;
  --bd-warn-ink: #6b2c06;
  --bd-ok-bg: #eefaf2;
  --bd-ok-ink: #114a29;
  --bd-alert-bg: #7c2d12;
  --bd-alert-ink: #ffffff;
  --ui-ink: #141c17;
  --ui-text: #141c17;
  --ui-muted: #3d4a41;
  --ui-surface: #ffffff;
  --ui-sunken: #f0f2ec;
  --ui-line: #c9d1c6;
  --ui-line-strong: #6b7870;
  --ui-accent: #1b3f2d;
  --ui-accent-hover: #132e20;
  --ui-focus: #143322;
  --kp-ink: #141c17;
  --kp-mute-2: #3d4a41;
  --kp-line: #c9d1c6;
  --kp-line-strong: #6b7870;
  --kp-cream: #f5f5f0;
  --tg-panel: #ffffff;
  --tg-acc: #1b3f2d;
  --tg-soft: #f0f2ec;
  color-scheme: light;
}

body {
  background: var(--bd-bg);
  color: var(--bd-ink);
  line-height: 1.55;
}

#main {
  max-width: 780px;
  padding: 28px 20px 88px;
}

#main.bd-signed-in {
  max-width: 1080px;
}

/* AAA Focus Appearance & Target Not Obscured */
#main :is(a, button, input, select, textarea, summary, [tabindex]):focus-visible,
.auth-shell :is(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--bd-focus) !important;
  outline-offset: 2px !important;
  scroll-margin-top: 96px;
}

.item,
[id^="req-"],
#main section {
  scroll-margin-top: 96px;
}

/* Prose Visual Presentation (SC 1.4.8) */
#main p,
#main .meta,
#main .hint {
  max-width: 68ch;
  line-height: 1.55;
  color: var(--bd-muted);
}

#main ::placeholder {
  color: var(--bd-muted);
  opacity: 1;
}

/* --- Calm Editorial Workspace Header --- */
.bd-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 20px;
  padding-bottom: 18px;
}

#main .bd-head h1 {
  font-size: clamp(28px, 3.5vw, 36px);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.12;
  margin: 0;
  color: var(--bd-ink);
}

.bd-head__who {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  margin-top: 6px;
  font-size: 14px;
  color: var(--bd-muted);
}

.bd-head__who b {
  color: var(--bd-ink);
  font-weight: 700;
}

.bd-head__acts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

#main .btn,
#main .textbtn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#main .btn {
  padding: 0 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid transparent;
}

#main .btn--primary {
  background: var(--bd-accent);
  border-color: var(--bd-accent);
  color: #ffffff;
}

#main .btn--primary:hover:not(:disabled) {
  background: var(--bd-accent-hover);
  border-color: var(--bd-accent-hover);
}

#main .btn--line {
  background: var(--bd-surface);
  border: 1px solid var(--bd-ctrl-border);
  color: var(--bd-ink);
}

#main .btn--line:hover:not(:disabled) {
  background: var(--bd-accent-soft);
  border-color: var(--bd-accent);
  color: var(--bd-accent-ink);
}

#main .textbtn {
  padding: 0 6px;
  color: var(--bd-link);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

#main .textbtn:hover {
  color: var(--bd-accent-hover);
}

/* Conditional Notice Strip (hidden when nothing needs attention) */
.bd-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--bd-warn-bg);
  border: 1px solid var(--bd-warn-border);
  border-radius: 10px;
  color: var(--bd-warn-ink);
  font-size: 14px;
  font-weight: 600;
}

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

/* --- Flat Underline Workspace Tabs --- */
.bd-tabs-wrap {
  margin-top: 4px;
  border-bottom: 1px solid var(--bd-border);
  background: transparent;
}

.bd-tabs {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.bd-tabs::-webkit-scrollbar {
  display: none;
}

.bd-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-bottom: 2.5px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--bd-muted);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.bd-tab:hover {
  background: var(--bd-surface-2);
  color: var(--bd-ink);
}

.bd-tab[aria-selected="true"] {
  background: var(--bd-accent-soft);
  color: var(--bd-accent-ink);
  border-bottom-color: var(--bd-accent);
  font-weight: 700;
}

.bd-tab__cnt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--bd-surface);
  border: 1px solid var(--bd-ctrl-border);
  color: var(--bd-ink);
}

.bd-tab__cnt.is-alert {
  background: var(--bd-alert-bg);
  border-color: var(--bd-alert-bg);
  color: var(--bd-alert-ink);
}

/* --- Tab Panels & Cards --- */
.bd-panel {
  margin-top: 20px;
}

.bd-panel[hidden] {
  display: none !important;
}

.bd-sec-card,
#main .card {
  margin-top: 16px;
  padding: 20px 22px;
  background: var(--bd-surface);
  border: 1px solid var(--bd-border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(20, 28, 23, 0.04);
}

.bd-panel > section:first-child,
.bd-panel > .card:first-child {
  margin-top: 0;
}

#main h2.head {
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--bd-ink);
}

/* --- Library Toolbar (Search, Filters & Sort) --- */
.bd-lib-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--bd-surface);
  border: 1px solid var(--bd-border);
  border-radius: 10px;
}

.bd-search-wrap {
  position: relative;
  flex: 1 1 240px;
  min-width: 0;
}

.bd-search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--bd-muted);
  pointer-events: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

#main #libSearch {
  width: 100%;
  min-height: 44px;
  padding: 0 12px 0 38px;
  border: 1px solid var(--bd-ctrl-border);
  border-radius: 8px;
  background: var(--bd-surface);
  color: var(--bd-ink);
  font-size: 14px;
}

.bd-filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.bd-filter-pill {
  padding: 0 14px;
  min-height: 44px;
  border: 1px solid var(--bd-ctrl-border);
  border-radius: 8px;
  background: var(--bd-surface);
  color: var(--bd-ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.bd-filter-pill:hover {
  background: var(--bd-surface-2);
}

.bd-filter-pill[aria-pressed="true"] {
  background: var(--bd-accent);
  border-color: var(--bd-accent);
  color: #ffffff;
}

.bd-sort-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

#main .bd-sort-wrap label {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--bd-muted);
}

#main #libSort {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--bd-ctrl-border);
  border-radius: 8px;
  background: var(--bd-surface);
  color: var(--bd-ink);
  font-size: 13.5px;
  font-weight: 600;
}

.bd-filter-status {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--bd-muted);
  font-variant-numeric: tabular-nums;
}

/* --- Item Rows --- */
.list {
  margin-top: 14px;
  gap: 12px;
}

.item {
  background: var(--bd-surface);
  border: 1px solid var(--bd-border);
  border-radius: 10px;
  padding: 18px 20px;
}

.item:hover {
  border-color: var(--bd-ctrl-border);
}

.item h2,
.item h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--bd-ink);
}

.tag {
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bd-accent-soft);
  color: var(--bd-accent-ink);
  font-size: 12px;
  font-weight: 700;
}

.tag--new {
  background: var(--bd-alert-bg);
  color: var(--bd-alert-ink);
}

.tag--off {
  background: var(--bd-danger-bg);
  color: var(--bd-danger-ink);
}

/* Following list */
#followingList {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

/* Form Accessibility (SC 3.3.2 & SC 1.4.8) */
.bd-field {
  display: grid;
  gap: 6px;
  width: 100%;
}

.bd-field__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.bd-field__count {
  font-size: 12px;
  font-weight: 600;
  color: var(--bd-muted);
  font-variant-numeric: tabular-nums;
}

#main .field,
#main select.field,
#main textarea.field {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--bd-ctrl-border);
  border-radius: 8px;
  background: var(--bd-surface);
  color: var(--bd-ink);
  font-size: 14px;
}

#main .err {
  color: var(--bd-danger);
  font-size: 13.5px;
  font-weight: 700;
}

#main .note a,
#main .lead a {
  color: var(--bd-link);
}

#main .switch {
  min-height: 44px;
  padding: 6px 0;
  align-items: center;
}

#main .switch input {
  width: 22px;
  height: 22px;
  min-width: 22px;
}

.bd-lf-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 22px;
  align-items: start;
  margin-top: 14px;
}

.bd-lf-grid > #lfList {
  margin-top: 0 !important;
}

.bd-lf-budget {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.bd-rewards-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.bd-rewards-grid > .card {
  margin-top: 0 !important;
}

#main .req-form {
  width: 100%;
  gap: 12px;
  justify-items: stretch;
}

#affForm .bd-aff-inputs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: 100%;
}

/* --- Calm Typographic Empty States --- */
.bd-empty,
#main .empty {
  text-align: left;
  padding: 28px 24px;
  background: var(--bd-surface);
  border: 1px solid var(--bd-border);
  border-radius: 10px;
  margin-top: 0;
}

.bd-empty h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--bd-ink);
  margin: 0 0 6px;
}

.bd-empty p,
#main .empty p {
  color: var(--bd-muted);
  max-width: 60ch;
  margin: 0 0 16px;
  font-size: 14px;
  text-align: left;
}

/* --- AAA No-Timing Dismissible Toasts --- */
.bd-toasts {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 950;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(410px, calc(100vw - 28px));
  pointer-events: none;
}

.bd-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 16px;
  border-radius: 10px;
  background: var(--bd-surface);
  border: 1px solid var(--bd-ctrl-border);
  color: var(--bd-ink);
  box-shadow: 0 10px 28px -10px rgba(0, 0, 0, 0.28);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  pointer-events: auto;
}

.bd-toast--ok {
  background: var(--bd-ok-bg);
  border-color: var(--bd-ok-ink);
  color: var(--bd-ok-ink);
}

.bd-toast--err {
  background: var(--bd-danger-bg);
  border-color: var(--bd-danger-ink);
  color: var(--bd-danger-ink);
}

.bd-toast__text {
  flex: 1;
  min-width: 0;
}

.bd-toast__close {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

.bd-toast__close:hover {
  background: rgba(0, 0, 0, 0.08);
}

.bd-toast__close:focus-visible {
  outline: 3px solid currentColor;
  outline-offset: 2px;
}

/* Signed-out auth header row */
.bd-auth-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.bd-auth-top .auth-back {
  margin: 0 0 0 -8px;
  min-height: 44px;
  color: var(--bd-muted);
}

/* Auth Card & Hero Light Mode AAA Enforcement */
.auth-shell .auth-hero {
  background: #13291e;
  background-image: none;
}

.auth-shell .auth-card::before {
  display: none;
  content: none;
}

.auth-shell .auth-card-logo {
  min-height: 44px;
}

.auth-shell .brand p,
.auth-shell .consent-note,
.auth-shell .hint {
  color: var(--bd-muted);
}

.auth-shell .auth-card .link,
.auth-shell .auth-card .consent-note a,
.auth-shell .auth-card .reveal {
  color: var(--bd-link);
  min-height: 44px;
}

.auth-shell .auth-card .tab {
  min-height: 44px;
  color: var(--bd-muted);
}

.auth-shell .auth-card .tab.active {
  color: var(--bd-ink);
  font-weight: 700;
}

.auth-shell .auth-card .field input {
  border-color: var(--bd-ctrl-border);
  color: var(--bd-ink);
}

.auth-shell .auth-card .field input::placeholder {
  color: var(--bd-muted);
  opacity: 1;
}

.auth-shell .auth-card .btn-primary {
  background: var(--bd-accent);
  border-color: var(--bd-accent);
  color: #ffffff;
}

/* --- Responsive --- */
@media (max-width: 920px) {
  .bd-rewards-grid,
  .bd-lf-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  #main {
    padding: 20px 14px 80px;
  }
  .bd-head__acts {
    width: 100%;
  }
  .bd-head__acts .btn {
    flex: 1;
  }
  .bd-lf-budget {
    grid-template-columns: 1fr;
  }
  .bd-toasts {
    right: 14px;
    left: 14px;
    bottom: 14px;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* =====================================================================
   DARK MODE — STRICT WCAG 2.2 AAA (>= 7:1 normal text)
   ===================================================================== */
html[data-theme="dark"] {
  --bd-bg: #0f1411;
  --bd-surface: #161d19;
  --bd-surface-2: #1e2822;
  --bd-border: #36453c;
  --bd-ctrl-border: #7d9185;
  --bd-ink: #f2f6f3;
  --bd-muted: #b8c8be;
  --bd-accent: #1d4d35;
  --bd-accent-hover: #173e2a;
  --bd-accent-soft: #22342a;
  --bd-accent-ink: #e6f7ec;
  --bd-link: #9ce6ba;
  --bd-focus: #d8f68b;
  --bd-danger: #ffb4b4;
  --bd-danger-bg: #2d1215;
  --bd-danger-ink: #fecaca;
  --bd-warn-bg: #291f0b;
  --bd-warn-border: #d99b38;
  --bd-warn-ink: #fde68a;
  --bd-ok-bg: #10291b;
  --bd-ok-ink: #a7f3d0;
  --bd-alert-bg: #f5c26b;
  --bd-alert-ink: #14110a;
  --ui-ink: #f2f6f3;
  --ui-text: #f2f6f3;
  --ui-muted: #b8c8be;
  --ui-surface: #161d19;
  --ui-sunken: #101613;
  --ui-line: #36453c;
  --ui-line-strong: #7d9185;
  --ui-accent: #1d4d35;
  --ui-accent-hover: #173e2a;
  --ui-focus: #d8f68b;
  --kp-ink: #f2f6f3;
  --kp-mute-2: #b8c8be;
  --kp-line: #36453c;
  --kp-line-strong: #7d9185;
  --kp-cream: #0f1411;
  --tg-panel: #161d19;
  --tg-acc: #9ce6ba;
  --tg-soft: #1e2822;
  color-scheme: dark;
}

html[data-theme="dark"] #main .card,
html[data-theme="dark"] #main .card label,
html[data-theme="dark"] #main .bd-field label,
html[data-theme="dark"] #main .bd-chk {
  color: var(--bd-ink);
}

#main .switch small,
html[data-theme="dark"] #main .switch small {
  color: var(--bd-muted);
}

html[data-theme="dark"] #main .field,
html[data-theme="dark"] #main select.field,
html[data-theme="dark"] #main textarea.field,
html[data-theme="dark"] #main #libSearch,
html[data-theme="dark"] #main #libSort {
  background: #101613;
  border-color: var(--bd-ctrl-border);
  color: var(--bd-ink);
}

html[data-theme="dark"] #main code,
html[data-theme="dark"] .recovery-code {
  background: #101613 !important;
  color: #e6f7ec;
  border: 1px solid var(--bd-ctrl-border);
}

html[data-theme="dark"] .req-reply {
  background: #1a241e;
  border-left-color: #9ce6ba;
  color: var(--bd-ink);
}

html[data-theme="dark"] .req-reply.is-mine {
  border-left-color: #6b8073;
}

html[data-theme="dark"] .req-flag {
  background: var(--bd-warn-bg);
  border-color: var(--bd-warn-border);
  color: var(--bd-warn-ink);
}

html[data-theme="dark"] .bd-toast__close:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* Signed-out auth shell Dark Mode AAA */
html[data-theme="dark"] .auth-shell .auth-panel {
  background: #0f1411;
}

html[data-theme="dark"] .auth-shell .auth-card {
  background: #161d19;
  border-color: #36453c;
  color: #f2f6f3;
}

html[data-theme="dark"] .auth-shell .auth-card::before {
  display: none;
  content: none;
}

html[data-theme="dark"] .auth-shell .brand h1,
html[data-theme="dark"] .auth-shell .auth-card .section-title,
html[data-theme="dark"] .auth-shell .auth-card .field label,
html[data-theme="dark"] .auth-shell .auth-card-logo span,
html[data-theme="dark"] .auth-shell .auth-card .tg-mark {
  color: #f2f6f3;
}

html[data-theme="dark"] .auth-shell .auth-card .tg-mark__sym {
  background-image: url("/assets/brand/lakuhan-mark-dark.svg?v=20261203-2");
}

html[data-theme="dark"] .auth-shell .auth-back:hover {
  background: #1e2822;
  color: #f2f6f3;
}

html[data-theme="dark"] .auth-shell .tabs {
  background: #101613;
  border: 1px solid #36453c;
}

html[data-theme="dark"] .auth-shell .tab {
  color: #b8c8be;
}

html[data-theme="dark"] .auth-shell .tab.active {
  background: #22342a;
  color: #e6f7ec;
}

html[data-theme="dark"] .auth-shell .auth-card .field input {
  background: #101613;
  border-color: #7d9185;
  color: #f2f6f3;
}

html[data-theme="dark"] .auth-shell .auth-card .reveal:hover {
  background: #22342a;
}

html[data-theme="dark"] .auth-shell .auth-card .reg-err {
  color: #ffb4b4;
}
