/* ============================================================
   METS Tools Hub — Shared Theme (Light / Dark)
   Include via <link> in <head> BEFORE any inline <style> blocks.
   ============================================================ */

/* ── Light mode (default) ──────────────────────────────────── */
:root {
  color-scheme: light;

  /* Portal tokens */
  --epson-blue: #003399;
  --epson-blue-dark: #00267a;
  --epson-blue-light: #4466bb;
  --epson-accent: #0066cc;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e1e5ee;
  --border-strong: #c8cee0;
  --text: #1a1f36;
  --text-muted: #5a6480;
  --text-light: #8a93a8;
  --success: #00875a;
  --warning: #d97706;
  --danger: #d12b2b;
  --shadow-sm: 0 1px 2px rgba(0,51,153,0.04), 0 1px 3px rgba(0,51,153,0.06);
  --shadow-md: 0 4px 6px rgba(0,51,153,0.05), 0 10px 20px rgba(0,51,153,0.08);
  --shadow-lg: 0 10px 25px rgba(0,51,153,0.1), 0 20px 48px rgba(0,51,153,0.12);
  --radius: 10px;
  --radius-lg: 14px;

  /* Dashboard tokens */
  --ep: #003399;
  --epd: #00205C;
  --ac: #0055B8;
  --al: #4A90D9;
  --or: #FF6600;
  --ok: #00875A;
  --no: #D32F2F;
  --c2: #F0F1F5;
  --bd: #E2E5EC;
  --tx: #1A1A2E;
  --tm: #5F6B7A;
  --td: #8E99A8;
  --sh: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);

  /* Common aliases — let tools that use these names theme automatically */
  --card: var(--surface);
  --card-bg: var(--surface);
  --panel: var(--surface);
  --primary: var(--epson-blue);
  --epson: var(--epson-blue);
  --muted: var(--text-muted);
}

/* ── Dark mode ─────────────────────────────────────────────── */
html[data-theme="dark"] {
  color-scheme: dark;

  /* Portal tokens */
  --epson-blue: #3366cc;
  --epson-blue-dark: #00267a;
  --epson-blue-light: #5588dd;
  --epson-accent: #5599dd;
  --bg: #0d1017;
  --surface: #161a24;
  --border: #2a2f3d;
  --border-strong: #3a4050;
  --text: #e2e4ea;
  --text-muted: #9ba2b2;
  --text-light: #7d8598;
  --success: #22b890;
  --warning: #e6a830;
  --danger: #e05858;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.3), 0 10px 20px rgba(0,0,0,0.25);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.4), 0 20px 48px rgba(0,0,0,0.3);

  /* Dashboard tokens */
  --ep: #3366cc;
  --epd: #00205C;
  --ac: #5599dd;
  --al: #5588dd;
  --or: #ff8533;
  --ok: #22b890;
  --no: #e05858;
  --c2: #1e2230;
  --bd: #2a2f3d;
  --tx: #e2e4ea;
  --tm: #9ba2b2;
  --td: #7d8598;
  --sh: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);

  /* Aliases (higher specificity than a tool's own :root, so they win in dark) */
  --card: var(--surface);
  --card-bg: var(--surface);
  --panel: var(--surface);
  --primary: var(--epson-blue);
  --epson: var(--epson-blue);
  --epson-dark: var(--epson-blue-dark);
  --muted: var(--text-muted);
  /* unambiguous bespoke synonyms used across tools */
  --ink: var(--text);
  --ink-2: var(--text);
  --line: var(--border);
  --line-2: var(--border);
  --muted-2: var(--text-light);
  --gray-bg: var(--bg);
  --gray-card: var(--surface);
  --gray-text: var(--text);
  --gray-light: var(--text-light);
  --gray-line: var(--border);
}

/* ── Sakura mode (soft pink — Japan cherry-blossom palette) ──── */
html[data-theme="sakura"] {
  color-scheme: light;

  /* Portal tokens */
  --epson-blue: #c2557e;
  --epson-blue-dark: #a83f68;
  --epson-blue-light: #e29ab8;
  --epson-accent: #d6749a;
  --bg: #fff5f8;
  --surface: #fffafc;
  --border: #f3d9e2;
  --border-strong: #ecc6d4;
  --text: #4a2c38;
  --text-muted: #8a6472;
  --text-light: #b08c98;
  --success: #4c9a6a;
  --warning: #d9863a;
  --danger: #c0506a;
  --shadow-sm: 0 1px 2px rgba(180,80,120,0.06), 0 1px 3px rgba(180,80,120,0.08);
  --shadow-md: 0 4px 6px rgba(180,80,120,0.07), 0 10px 20px rgba(180,80,120,0.10);
  --shadow-lg: 0 10px 25px rgba(180,80,120,0.12), 0 20px 48px rgba(180,80,120,0.14);

  /* Dashboard tokens */
  --ep: #c2557e;
  --epd: #a83f68;
  --ac: #d6749a;
  --al: #e29ab8;
  --or: #e08a3a;
  --ok: #4c9a6a;
  --no: #c0506a;
  --c2: #fbe6ee;
  --bd: #f3d9e2;
  --tx: #4a2c38;
  --tm: #8a6472;
  --td: #b08c98;
  --sh: 0 1px 3px rgba(180,80,120,0.10), 0 1px 2px rgba(180,80,120,0.08);

  /* Aliases */
  --card: var(--surface);
  --card-bg: var(--surface);
  --panel: var(--surface);
  --primary: var(--epson-blue);
  --epson: var(--epson-blue);
  --epson-dark: var(--epson-blue-dark);
  --muted: var(--text-muted);
  /* unambiguous bespoke synonyms used across tools */
  --ink: var(--text);
  --ink-2: var(--text);
  --line: var(--border);
  --line-2: var(--border);
  --muted-2: var(--text-light);
  --gray-bg: var(--bg);
  --gray-card: var(--surface);
  --gray-text: var(--text);
  --gray-light: var(--text-light);
  --gray-line: var(--border);
}

/* Sakura: header / hero gradients in pink instead of brand blue */
[data-theme="sakura"] .header { background: linear-gradient(135deg, #c2557e 0%, #a83f68 100%); }
[data-theme="sakura"] .hero   { background: linear-gradient(180deg, #a83f68 0%, #c2557e 100%); }
[data-theme="sakura"] .hdr    { background: linear-gradient(135deg, #a83f68 0%, #c2557e 60%, #d6749a 100%); }
[data-theme="sakura"] .brand-mark,
[data-theme="sakura"] .user-avatar { color: #c2557e; }
[data-theme="sakura"] .card-icon { background: linear-gradient(135deg, #c2557e 0%, #d6749a 100%); }


/* ================================================================
   COMPONENT OVERRIDES — Dark mode
   Grouped by: headers, badges, surfaces, forms, modals, dashboard
   ================================================================ */

/* ── A. Header gradients: keep original brand blues ────────── */
[data-theme="dark"] .header {
  background: linear-gradient(135deg, #003399 0%, #00267a 100%);
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
[data-theme="dark"] .hero {
  background: linear-gradient(180deg, #00267a 0%, #003399 100%);
}
[data-theme="dark"] .hdr {
  background: linear-gradient(135deg, #00205C 0%, #003399 60%, #0055B8 100%);
}

/* Brand mark + avatar: keep original blue on white */
[data-theme="dark"] .brand-mark {
  color: #003399;
}
[data-theme="dark"] .user-avatar {
  color: #003399;
}
[data-theme="dark"] .card-icon {
  background: linear-gradient(135deg, #003399 0%, #0066cc 100%);
}

/* ── B. Badge tinted backgrounds ───────────────────────────── */

/* Blue-tinted */
[data-theme="dark"] .badge-category,
[data-theme="dark"] .badge-admin,
[data-theme="dark"] .badge-cat,
[data-theme="dark"] .type-feature,
[data-theme="dark"] .tab-btn.active .tab-badge {
  background: #1a2340;
}
[data-theme="dark"] .card-version {
  background: #1a2340;
}

/* Amber-tinted */
[data-theme="dark"] .badge-poc,
[data-theme="dark"] .type-rating {
  background: #2d2010;
}

/* Green-tinted */
[data-theme="dark"] .badge-new,
[data-theme="dark"] .badge-active {
  background: #0f2a1a;
}

/* Neutral-tinted */
[data-theme="dark"] .badge-hidden,
[data-theme="dark"] .type-general {
  background: #252830;
}

/* Red-tinted */
[data-theme="dark"] .badge-inactive,
[data-theme="dark"] .type-bug {
  background: #2d1515;
}

/* Changelog tags */
[data-theme="dark"] .tag-added { background: #0f2a1a; }
[data-theme="dark"] .tag-fixed { background: #151f30; }
[data-theme="dark"] .tag-changed { background: #2d2010; }
[data-theme="dark"] .tag-removed { background: #2d1515; }

/* ── C. Admin indicator ────────────────────────────────────── */
[data-theme="dark"] .admin-indicator {
  background: linear-gradient(90deg, #1a2340 0%, #182040 100%);
  border-color: #2a3555;
}

/* ── D. Dropdown danger hover ──────────────────────────────── */
[data-theme="dark"] .dropdown-item.danger:hover {
  background: #2d1515;
}

/* ── E. Modal backdrop ─────────────────────────────────────── */
[data-theme="dark"] .modal-backdrop {
  background: rgba(0, 0, 0, 0.75);
}

/* ── F. User dropdown (portal) ─────────────────────────────── */
[data-theme="dark"] .user-dropdown {
  background: var(--surface);
}

/* ── G. Perm UI selections (admin) ─────────────────────────── */
[data-theme="dark"] .perm-user-item.selected,
[data-theme="dark"] .perm-tool.checked,
[data-theme="dark"] .feedback-item.selected {
  background: #1a2340;
}

/* ── H. Form inputs + selects: white → surface ─────────────── */
[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group textarea,
[data-theme="dark"] .form-group select,
[data-theme="dark"] .activity-filters select,
[data-theme="dark"] .feedback-filters select {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

[data-theme="dark"] .form-group input:focus,
[data-theme="dark"] .form-group textarea:focus,
[data-theme="dark"] .form-group select:focus {
  box-shadow: 0 0 0 3px rgba(51,102,204,0.25);
}

[data-theme="dark"] .tag-picker,
[data-theme="dark"] .tag-picker-item,
[data-theme="dark"] .icon-btn {
  background: var(--surface);
}

/* Admin table sticky header */
[data-theme="dark"] .data-table-inner th {
  background: var(--bg);
}

/* ── I. Button overrides ───────────────────────────────────── */
[data-theme="dark"] .btn-danger {
  background: var(--surface);
  border-color: #4a2020;
}
[data-theme="dark"] .btn-danger:hover {
  background: #2d1515;
}

/* ── J. Dashboard: hardcoded #fff surfaces ─────────────────── */
[data-theme="dark"] .upload-zone {
  background: var(--surface);
  border-color: var(--border);
}
[data-theme="dark"] .upload-zone:hover,
[data-theme="dark"] .upload-zone.dg {
  background: #1a2040;
  border-color: var(--ep);
}
[data-theme="dark"] .fi {
  background: var(--surface);
}
[data-theme="dark"] .kpi {
  background: var(--surface);
}
[data-theme="dark"] .card {
  background: var(--surface);
}
[data-theme="dark"] .top5-card {
  background: var(--surface);
}

/* Dashboard table header */
[data-theme="dark"] .dt thead th {
  background: var(--surface);
}

/* Dashboard select options */
[data-theme="dark"] .fg select option {
  background: var(--surface);
  color: var(--text);
}

/* Dashboard top5 rank: keep original brand blue bg */
[data-theme="dark"] .top5-rank {
  background: #003399;
}

/* ── K. Dashboard pivot tree ───────────────────────────────── */
[data-theme="dark"] .piv-bu {
  background: #1a1d27;
}
[data-theme="dark"] .piv-bu:hover {
  background: #1e2545;
}
[data-theme="dark"] .piv-model {
  border-color: #1e2230;
}

/* ── L. Dashboard badges ───────────────────────────────────── */
[data-theme="dark"] .b-a {
  background: #2d1515;
}
[data-theme="dark"] .b-i {
  background: #0f2a1a;
}

/* ── M. Dashboard footer ───────────────────────────────────── */
[data-theme="dark"] .mets-tool-footer {
  background: var(--surface);
}

/* ── N. Inline-styled elements (need !important) ───────────── */

/* Dashboard: load choice box */
[data-theme="dark"] #loadChoice {
  background: var(--surface) !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3) !important;
}
[data-theme="dark"] #loadChoice h3 {
  color: var(--ep) !important;
}
[data-theme="dark"] #loadChoice p {
  color: var(--tm) !important;
}
[data-theme="dark"] #btnLoadDB {
  background: var(--epson-blue) !important;
}
[data-theme="dark"] #loadChoice button:last-of-type {
  background: var(--surface) !important;
  color: var(--epson-blue) !important;
  border-color: var(--epson-blue) !important;
}

/* Dashboard: changelog */
[data-theme="dark"] #changelog {
  background: var(--surface) !important;
}

/* Admin: share link info box */
[data-theme="dark"] [data-panel="share-links"] > :nth-child(2) {
  background: #152030 !important;
  border-color: #2a3555 !important;
  color: #7db0e8 !important;
}

/* Admin: share link result modal */
[data-theme="dark"] #shareLinkResultModal .modal-body > div:first-child {
  background: #0f2a1a !important;
  border-color: #1a3d28 !important;
}
[data-theme="dark"] #shareLinkResultModal .modal-body > div:first-child > div:first-child {
  color: var(--success) !important;
}
[data-theme="dark"] #slResultUrl {
  background: var(--surface) !important;
  border-color: var(--border) !important;
}

/* Admin: share link error */
[data-theme="dark"] #slError {
  background: #2d1515 !important;
  border-color: #4a2020 !important;
  color: var(--danger) !important;
}

/* Admin: password strength meter */
[data-theme="dark"] .pwd-strength {
  background: var(--border);
}


/* ================================================================
   TRANSITION CONTROL
   ================================================================ */

/* Suppress all transitions on initial page load */
html.theme-loading,
html.theme-loading *,
html.theme-loading *::before,
html.theme-loading *::after {
  transition: none !important;
}

/* Smooth transitions when toggling */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color 0.2s ease,
              color 0.2s ease,
              border-color 0.2s ease,
              box-shadow 0.2s ease !important;
}


/* ================================================================
   THEME TOGGLE BUTTON (injected by mets-theme.js into header)
   Styled for dark-blue header background across all pages.
   ================================================================ */

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
  padding: 0;
}
.theme-toggle:hover {
  background: rgba(255,255,255,0.22);
}
.theme-toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Theme picker popup (appended to <body>, positioned by JS) */
.theme-menu {
  position: fixed;
  z-index: 10000;
  min-width: 180px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e1e5ee);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  padding: 6px;
  display: none;
}
.theme-menu.open { display: block; }
.theme-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  color: var(--text, #1a1f36);
  text-align: left;
}
.theme-menu button:hover { background: var(--bg, #f5f7fb); }
.theme-menu .tm-ic { width: 16px; height: 16px; display: inline-flex; flex-shrink: 0; }
.theme-menu .tm-ic svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.theme-menu .tm-lb { flex: 1; }
.theme-menu .tm-ck { opacity: 0; color: var(--epson-blue, #003399); font-weight: 700; }
.theme-menu [aria-checked="true"] .tm-ck { opacity: 1; }


/* ================================================================
   PRINT — Force light mode
   ================================================================ */

@media print {
  :root {
    color-scheme: light !important;

    --epson-blue: #003399 !important;
    --epson-blue-dark: #00267a !important;
    --epson-blue-light: #4466bb !important;
    --epson-accent: #0066cc !important;
    --bg: #ffffff !important;
    --surface: #ffffff !important;
    --border: #e1e5ee !important;
    --border-strong: #c8cee0 !important;
    --text: #1a1f36 !important;
    --text-muted: #5a6480 !important;
    --text-light: #8a93a8 !important;
    --success: #00875a !important;
    --warning: #d97706 !important;
    --danger: #d12b2b !important;

    --ep: #003399 !important;
    --epd: #00205C !important;
    --ac: #0055B8 !important;
    --al: #4A90D9 !important;
    --or: #FF6600 !important;
    --ok: #00875A !important;
    --no: #D32F2F !important;
    --c2: #F0F1F5 !important;
    --bd: #E2E5EC !important;
    --tx: #1A1A2E !important;
    --tm: #5F6B7A !important;
    --td: #8E99A8 !important;
  }

  .theme-toggle {
    display: none !important;
  }
}
