/* ============================================================================
   ROAA DIGITAL JOURNAL — Theme Studio & Design Tokens (Site UI ONLY)
   Strict A4 Isolation: Official A4 Letter (.a4-sheet) keeps its fixed Azhar
   Emerald & Gold identity regardless of active site UI theme.
   ============================================================================ */

:root {
  /* Core UI Theme Tokens (Default: Azhar Emerald & Gold) */
  --theme-primary: #053E26;
  --theme-primary-deep: #032617;
  --theme-primary-mid: #0A5C3A;
  --theme-primary-light: #0F7A4D;
  --theme-primary-soft: #E6F4EA;
  --theme-primary-tint: #F2FAF4;
  --theme-accent: #C89B2B;
  --theme-accent-light: #DDB44A;
  --theme-accent-pale: #F5E6B8;
  --theme-accent-soft: #FDF8EB;

  --theme-bg: #F6F4EE;
  --theme-bg-alt: #EFECE3;
  --theme-surface: #FFFFFF;
  --theme-surface-alt: #FAF8F3;
  --theme-header-bg: linear-gradient(135deg, #032617 0%, #053E26 55%, #0A5C3A 100%);
  --theme-header-text: #FFFFFF;
  --theme-sidebar-bg: #FFFFFF;
  --theme-border: #D9DFD8;
  --theme-divider: #E6EAE5;

  --theme-text: #13211A;
  --theme-text-mid: #3D5247;
  --theme-text-muted: #6C7D74;

  --theme-input-bg: #FFFFFF;
  --theme-input-border: #CDD6CE;
  --theme-input-focus: #0A5C3A;

  --theme-table-header-bg: #F2FAF4;
  --theme-table-header-text: #053E26;
  --theme-table-row-hover: #F7FBF8;
  --theme-table-stripe: #FBFDFB;

  --theme-success: #0F7A4D;
  --theme-success-bg: #E6F4EA;
  --theme-warning: #B45309;
  --theme-warning-bg: #FEF3C7;
  --theme-danger: #B42318;
  --theme-danger-bg: #FEF2F2;
  --theme-info: #1D4ED8;
  --theme-info-bg: #EFF6FF;

  /* Background & Visual Atmosphere Controls */
  --theme-bg-mode: default;
  --theme-bg-gradient: linear-gradient(145deg, #F6F4EE 0%, #EEF3EE 55%, #F8F5EC 100%);
  --theme-bg-overlay-opacity: 0.06;
  --theme-card-opacity: 1;
  --theme-blur: 10px;
  --theme-radius: 14px;
  --theme-radius-sm: 9px;
  --theme-shadow-sm: 0 2px 10px rgba(5, 62, 38, 0.06);
  --theme-shadow-md: 0 10px 28px rgba(5, 62, 38, 0.10);
  --theme-shadow-lg: 0 22px 54px rgba(3, 38, 23, 0.18);

  /* UI Typography Controls (Local OFL Fonts Only) */
  --ui-font-body: 'Cairo', 'Tajawal', sans-serif;
  --ui-font-heading: 'Cairo', 'Tajawal', sans-serif;
  --ui-font-table: 'Cairo', 'Tajawal', sans-serif;
  --ui-font-button: 'Cairo', 'Tajawal', sans-serif;
  --ui-font-sidebar: 'Cairo', 'Tajawal', sans-serif;
  --ui-font-number: 'Cairo', 'Readex Pro', sans-serif;
  --ui-font-size: 14px;
  --ui-line-height: 1.65;
  --ui-heading-weight: 800;
  --ui-scale: 1;

  /* Map existing app variables onto Theme Tokens so all existing UI responds */
  --emerald-950: var(--theme-primary-deep);
  --emerald-900: var(--theme-primary);
  --emerald-800: var(--theme-primary-mid);
  --emerald-700: var(--theme-primary-light);
  --emerald-600: var(--theme-primary-light);
  --emerald-100: var(--theme-primary-soft);
  --emerald-50: var(--theme-primary-tint);
  --gold-600: color-mix(in srgb, var(--theme-accent) 82%, #000);
  --gold-500: var(--theme-accent);
  --gold-400: var(--theme-accent-light);
  --gold-300: var(--theme-accent-pale);
  --gold-100: var(--theme-accent-soft);
  --ivory: var(--theme-bg);
  --parchment: var(--theme-bg);
  --cream: var(--theme-bg-alt);
  --surface: var(--theme-surface);
  --ink: var(--theme-text);
  --muted: var(--theme-text-muted);
  --border: var(--theme-border);
  --text-dark: var(--theme-text);
  --text-mid: var(--theme-text-mid);
  --text-muted: var(--theme-text-muted);
  --danger: var(--theme-danger);
  --danger-bg: var(--theme-danger-bg);
  --success: var(--theme-success);
  --radius: var(--theme-radius);
  --radius-lg: calc(var(--theme-radius) + 4px);
  --radius-md: var(--theme-radius);
  --radius-sm: var(--theme-radius-sm);
  --shadow-soft: var(--theme-shadow-md);
  --shadow-card: var(--theme-shadow-sm);
  --shadow-sm: var(--theme-shadow-sm);
  --shadow-md: var(--theme-shadow-md);
  --shadow-lg: var(--theme-shadow-lg);
}

/* Base UI Typography & Background Modes */
html {
  font-size: calc(16px * var(--ui-scale, 1));
}

body {
  font-family: var(--ui-font-body);
  font-size: var(--ui-font-size);
  line-height: var(--ui-line-height);
  background-color: var(--theme-bg);
  color: var(--theme-text);
  transition: background-color 0.25s ease, color 0.25s ease;
}

body[data-bg-mode="solid"] {
  background-image: none;
  background-color: var(--theme-bg);
}

body[data-bg-mode="gradient"] {
  background-image: var(--theme-bg-gradient);
  background-attachment: fixed;
}

body[data-bg-mode="pattern"] {
  background-color: var(--theme-bg);
  background-image:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--theme-primary) 16%, transparent) 1px, transparent 0),
    radial-gradient(circle at 13px 13px, color-mix(in srgb, var(--theme-accent) 14%, transparent) 1px, transparent 0);
  background-size: 24px 24px;
}

body[data-bg-mode="academic"] {
  background-color: var(--theme-bg);
  background-image:
    linear-gradient(135deg, color-mix(in srgb, var(--theme-primary) 7%, transparent) 0%, transparent 42%),
    linear-gradient(315deg, color-mix(in srgb, var(--theme-accent) 9%, transparent) 0%, transparent 45%),
    repeating-linear-gradient(45deg, color-mix(in srgb, var(--theme-primary) 3.5%, transparent) 0 1px, transparent 1px 28px);
  background-attachment: fixed;
}

h1, h2, h3, h4, .card-title, .brand-title, .section-head {
  font-family: var(--ui-font-heading);
  font-weight: var(--ui-heading-weight);
}

button, .btn, .nav-btn {
  font-family: var(--ui-font-button);
}

.topbar-nav, .mobile-nav-drawer {
  font-family: var(--ui-font-sidebar);
}

.data-table, .data-table th, .data-table td {
  font-family: var(--ui-font-table);
}

.kpi-num, .stat-num, .num-cell, .serial-badge {
  font-family: var(--ui-font-number);
  font-variant-numeric: tabular-nums;
}

.topbar,
.app-footer {
  background: var(--theme-header-bg) !important;
  color: var(--theme-header-text);
}
.topbar {
  border-bottom: 2px solid color-mix(in srgb, var(--theme-accent) 75%, transparent) !important;
}
.app-footer {
  border-top: 2px solid color-mix(in srgb, var(--theme-accent) 75%, transparent) !important;
}

.card, .stat-card, .kpi-card, .editor-panel, .modal-box, .theme-studio-card, .preview-panel, .form-panel .card {
  background-color: var(--theme-surface);
  border-color: var(--theme-border);
  border-radius: var(--theme-radius);
  box-shadow: var(--theme-shadow-sm);
  color: var(--theme-text);
}

.card h2, .card h3, .card h4, .card-title, .kpi-value {
  color: var(--theme-primary);
}

[data-theme-mode="dark"] .card h2,
[data-theme-mode="dark"] .card h3,
[data-theme-mode="dark"] .card h4,
[data-theme-mode="dark"] .card-title,
[data-theme-mode="dark"] .kpi-value,
[data-theme-mode="dark"] #dashDefaultsSummary,
[data-theme-mode="dark"] .quick-item strong {
  color: var(--theme-text) !important;
}

[data-theme-mode="dark"] .preview-panel,
[data-theme-mode="dark"] .preview-stage,
[data-theme-mode="dark"] .preview-toolbar {
  background-color: var(--theme-surface-alt) !important;
  color: var(--theme-text) !important;
  border-color: var(--theme-border) !important;
}

[data-theme-mode="dark"] .quick-item,
[data-theme-mode="dark"] .account-create-box,
[data-theme-mode="dark"] .check-pill,
[data-theme-mode="dark"] .filter-pill,
[data-theme-mode="dark"] .btn-mini {
  background-color: var(--theme-surface-alt) !important;
  color: var(--theme-text) !important;
  border-color: var(--theme-border) !important;
}

[data-theme-mode="dark"] .filter-pill.active {
  background-color: var(--theme-primary) !important;
  color: #FFFFFF !important;
}

[data-theme-mode="dark"] .a4-sheet,
.a4-sheet {
  --ink: #1B2420 !important;
  --muted: #54665E !important;
  --parchment: #F5F2EA !important;
  --gold-600: #A87E1E !important;
}

.form-control, .form-select, input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  background-color: var(--theme-input-bg);
  border-color: var(--theme-input-border);
  color: var(--theme-text);
}

.form-control:focus, .form-select:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--theme-input-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-primary) 16%, transparent);
}

.data-table thead th {
  background: var(--theme-table-header-bg);
  color: var(--theme-table-header-text);
  border-bottom-color: var(--theme-border);
}

.data-table tbody tr:hover {
  background-color: var(--theme-table-row-hover);
}

/* Density Presets */
body[data-ui-density="compact"] .card,
body[data-ui-density="compact"] .editor-panel { padding: 14px; }
body[data-ui-density="compact"] .data-table th,
body[data-ui-density="compact"] .data-table td { padding: 7px 9px; font-size: 0.92em; }
body[data-ui-density="compact"] .main-wrap { padding-top: 14px; padding-bottom: 24px; }

body[data-ui-density="spacious"] .card,
body[data-ui-density="spacious"] .editor-panel { padding: 26px; }
body[data-ui-density="spacious"] .data-table th,
body[data-ui-density="spacious"] .data-table td { padding: 14px 13px; }

/* Dark Mode Contrast Guarantees */
[data-theme-mode="dark"] .login-card,
[data-theme-mode="dark"] .card,
[data-theme-mode="dark"] .kpi-card,
[data-theme-mode="dark"] .stat-card,
[data-theme-mode="dark"] .editor-panel,
[data-theme-mode="dark"] .auth-row,
[data-theme-mode="dark"] .sub-panel,
[data-theme-mode="dark"] .theme-studio-card,
[data-theme-mode="dark"] .settings-subcard {
  background-color: var(--theme-surface);
  color: var(--theme-text);
  border-color: var(--theme-border);
}

[data-theme-mode="dark"] .login-overlay {
  background: radial-gradient(circle at top right, #182330 0%, #0D141C 62%, #080D13 100%);
}

[data-theme-mode="dark"] .btn-soft,
[data-theme-mode="dark"] .btn-outline,
[data-theme-mode="dark"] .btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--theme-text);
  border-color: var(--theme-border);
}

[data-theme-mode="dark"] .btn-soft:hover,
[data-theme-mode="dark"] .btn-outline:hover {
  background: rgba(255, 255, 255, 0.12);
}

[data-theme-mode="dark"] .info-box,
[data-theme-mode="dark"] .note-box,
[data-theme-mode="dark"] .alert-box {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: var(--theme-border);
  color: var(--theme-text);
}

[data-theme-mode="dark"] .badge-issued,
[data-theme-mode="dark"] .status-pill.issued {
  background: rgba(16, 185, 129, 0.18);
  color: #6EE7B7;
  border-color: rgba(16, 185, 129, 0.35);
}

[data-theme-mode="dark"] .badge-pending,
[data-theme-mode="dark"] .status-pill.pending {
  background: rgba(245, 158, 11, 0.18);
  color: #FCD34D;
  border-color: rgba(245, 158, 11, 0.35);
}

[data-theme-mode="dark"] .badge-draft,
[data-theme-mode="dark"] .status-pill.draft {
  background: rgba(96, 165, 250, 0.18);
  color: #93C5FD;
  border-color: rgba(96, 165, 250, 0.35);
}

[data-theme-mode="dark"] .preview-pane {
  background: #141C24;
  border-color: var(--theme-border);
}

[data-theme-mode="dark"] select option {
  background-color: #161F29;
  color: #F1F5F9;
}

/* ============================================================================
   CRITICAL ISOLATION: Official A4 Letter Sheet MUST NEVER inherit UI Theme!
   ============================================================================ */
.a4-sheet,
#a4Sheet,
.preview-pane .a4-sheet,
[data-theme-mode="dark"] .a4-sheet,
[data-theme-mode="dark"] #a4Sheet {
  --emerald-950: #032617 !important;
  --emerald-900: #053E26 !important;
  --emerald-800: #0A5C3A !important;
  --emerald-700: #0F7A4D !important;
  --emerald-600: #169862 !important;
  --emerald-100: #E6F4EA !important;
  --emerald-50: #F2FAF4 !important;
  --gold-500: #C89B2B !important;
  --gold-400: #DDB44A !important;
  --gold-300: #F5E6B8 !important;
  --gold-100: #FDF8EB !important;
  --ivory: #F6F4EE !important;
  --cream: #EFECE3 !important;
  --surface: #FFFFFF !important;
  --border: #D9DFD8 !important;
  --text-dark: #13211A !important;
  --text-mid: #3D5247 !important;
  --text-muted: #6C7D74 !important;
  background: #FFFFFF !important;
  background-color: #FFFFFF !important;
  color: #13211A !important;
  font-size: 14px;
}

/* ============================================================================
   Theme Studio Workspace Styles
   ============================================================================ */
.theme-studio-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.theme-studio-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 12.5px;
  color: var(--theme-text-muted);
}

.theme-meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--theme-primary-tint);
  color: var(--theme-primary);
  border: 1px solid color-mix(in srgb, var(--theme-primary) 22%, transparent);
  font-weight: 700;
  font-size: 12px;
}

.theme-isolation-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--theme-accent) 12%, var(--theme-surface));
  border: 1px solid color-mix(in srgb, var(--theme-accent) 40%, transparent);
  color: var(--theme-text);
  margin-bottom: 18px;
  font-size: 13px;
}

.theme-presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.theme-preset-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 9px;
  padding: 14px;
  border-radius: 15px;
  border: 2px solid var(--theme-border);
  background: var(--theme-surface);
  color: var(--theme-text);
  cursor: pointer;
  text-align: center;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.theme-preset-card:hover {
  transform: translateY(-3px);
  border-color: var(--theme-primary);
  box-shadow: var(--theme-shadow-md);
}

.theme-preset-card.active {
  border-color: var(--theme-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-accent) 28%, transparent), var(--theme-shadow-md);
}

.theme-preset-swatches {
  display: flex;
  height: 32px;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.theme-preset-swatches span {
  flex: 1;
  height: 100%;
}

.theme-preset-name {
  font-weight: 800;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  text-align: center;
}

.theme-preset-desc {
  font-size: 11.5px;
  color: var(--theme-text-muted);
  line-height: 1.5;
  text-align: center;
}

.theme-studio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.85fr);
  gap: 18px;
  align-items: start;
}

.theme-controls-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--theme-border);
  padding-bottom: 12px;
}

.theme-subtab-btn {
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--theme-border);
  background: var(--theme-surface-alt);
  color: var(--theme-text-mid);
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.theme-subtab-btn.active {
  background: var(--theme-primary);
  color: #FFFFFF;
  border-color: var(--theme-primary);
}

.theme-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.theme-color-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--theme-border);
  background: var(--theme-surface-alt);
}

.theme-color-item label {
  font-size: 12px;
  font-weight: 700;
  color: var(--theme-text-mid);
}

.theme-color-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-color-input-row input[type="color"] {
  width: 38px;
  height: 34px;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--theme-border);
  cursor: pointer;
  background: transparent;
  flex-shrink: 0;
}

.theme-color-input-row input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border-radius: 8px;
  font-family: monospace;
  font-size: 12.5px;
  direction: ltr;
  text-align: left;
}

.theme-live-preview-box {
  position: sticky;
  top: 76px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.theme-mini-app {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--theme-border);
  box-shadow: var(--theme-shadow-md);
  background: var(--theme-bg);
}

.theme-mini-header {
  padding: 11px 14px;
  background: var(--theme-header-bg);
  color: var(--theme-header-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 800;
  font-size: 12.5px;
}

.theme-mini-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-mini-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.theme-mini-kpi {
  background: var(--theme-surface);
  border: 1px solid var(--theme-border);
  border-radius: var(--theme-radius-sm);
  padding: 8px;
  text-align: center;
}

.theme-mini-kpi strong {
  display: block;
  font-size: 15px;
  color: var(--theme-primary);
}

.theme-mini-kpi span {
  font-size: 10.5px;
  color: var(--theme-text-muted);
}

.theme-mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  background: var(--theme-surface);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--theme-border);
}

.theme-mini-table th {
  background: var(--theme-table-header-bg);
  color: var(--theme-table-header-text);
  padding: 6px 8px;
  text-align: right;
}

.theme-mini-table td {
  padding: 6px 8px;
  border-top: 1px solid var(--theme-divider);
  color: var(--theme-text);
}

.theme-contrast-meter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--theme-border);
  background: var(--theme-surface-alt);
}

.theme-contrast-meter.pass {
  border-color: color-mix(in srgb, var(--theme-success) 40%, transparent);
  background: var(--theme-success-bg);
  color: var(--theme-success);
}

.theme-contrast-meter.warn {
  border-color: color-mix(in srgb, var(--theme-warning) 45%, transparent);
  background: var(--theme-warning-bg);
  color: var(--theme-warning);
}

.theme-compare-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  border: 1px dashed var(--theme-border);
  background: var(--theme-surface-alt);
  font-size: 12px;
}

.theme-studio-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.custom-presets-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.custom-preset-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--theme-border);
  background: var(--theme-surface-alt);
}
