:root {
  --bg: #f7f8fb;
  --card-bg: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #0b7bd6; /* Accessible blue */
  --primary-600: #0a6ec0;
  --primary-700: #095fa6;
  --border: #e5e7eb;
  --ring: rgba(11, 123, 214, 0.35);
  --table-head-bg: #f3f4f6;
  --input-bg: #ffffff;
  --control-accent: var(--primary);
}

/* Dark theme variables */
[data-theme="dark"] {
  --bg: #0b1220;
  --card-bg: #121a2a;
  --text: #e5e7eb;
  --muted: #9aa4b2;
  --primary: #5aa1ff;
  --primary-600: #4b90ea;
  --primary-700: #3c7ace;
  --border: #243045;
  --ring: rgba(90, 161, 255, 0.35);
  --table-head-bg: #172136;
  --input-bg: #0f1726;
  --control-accent: #2a3448;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* Header */
.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  /* Make header fixed so it remains visible on long pages */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 72px;
  padding: 14px 0;
  justify-content: space-between;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo { height: 48px; width: auto; }
.brand-title { font-weight: 700; letter-spacing: .2px; }
.brand-sub { color: var(--muted); font-size: .95rem; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  scale: 2;
  border-radius: 9999px;
  border: none;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
}
.theme-toggle:hover { filter: brightness(1.05); }
.theme-toggle:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }

/* Layout */
.container {
  /* max-width: 1250px; */
  margin: 0 auto;
  padding: 0 20px;
}

/* Reserve space for fixed header so content doesn't jump under it */
main.container { 
  padding-top: 92px;
  padding-bottom: 20px;
}

.card {
  background: var(--card-bg);
  margin: 24px 0;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.05);
}

h1 {
  margin: 0 0 14px;
  font-size: 1.5rem;
}

h2 {
  margin: 20px 0 10px;
  font-size: 1.25rem;
}

h3 {
  margin: 14px 0 10px;
  font-size: 1.1rem;
}

/* Tables */
.table-wrapper { overflow-x: auto; }

.form-table,
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card-bg);
  border: none;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

.form-table::after,
.data-table::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  pointer-events: none;
}

.form-table td,
.form-table th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table td,
.data-table th {
  padding: 10px 12px;
  border-bottom: 0;
}

.form-table tr:last-child td,
.data-table tr:last-child td { border-bottom: 0; }

.data-table th {
  background: var(--table-head-bg);
  text-align: left;
  font-weight: 600;
}

/* Inputs */
input[type="text"],
input[type="email"],
input[type="number"],
input[type="tel"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}

input[type="radio"],
input[type="checkbox"] { 
  accent-color: var(--control-accent); 
}

.radio { margin-right: 12px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  transition: background-color .2s ease, color .2s ease, border-color .2s ease, transform .02s ease;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-600); }
.btn-primary:focus { box-shadow: 0 0 0 4px var(--ring); }

.btn-secondary {
  background: #e7eef8;
  color: var(--primary-700);
  border-color: #cfd9ea;
}
.btn-secondary:hover { background: #dfe8f6; }
.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #e7eef8;
  color: var(--muted);
}
.btn-secondary:disabled:hover {
  background: #e7eef8;
}

[data-theme="dark"] .btn-secondary {
  background: #1c2637;
  color: var(--text);
  border-color: #2a3852;
}
[data-theme="dark"] .btn-secondary:hover { background: #1f2b3f; }
[data-theme="dark"] .btn-secondary:disabled {
  opacity: 0.5;
  background: #1c2637;
  color: var(--muted);
}
[data-theme="dark"] .btn-secondary:disabled:hover {
  background: #1c2637;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.9rem;
  gap: 3px;
}

.actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.footer {
  margin-top: 18px;
  color: var(--muted);
  margin-bottom: 15px;
  padding-bottom: 15px;
}
.footer-note {
  margin: 5px;
}
.footer-note a { color: var(--primary-700); text-decoration: none; }
.footer-note a:hover { text-decoration: underline; }

/* Static Information grid */
.grid-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 16px;
  margin-bottom: 16px;
}
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-field label {
  font-size: 0.9rem;
  color: var(--muted);
}

.field-info { 
  margin-top: 4px; 
  font-size: 0.85rem; 
  color: var(--primary-700);
}
[data-theme="dark"] .field-info { color: #a9c8ff; }
.hidden { display: none !important; }

.inline-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  text-align: center;
}
.inline-controls.start {
  justify-content: flex-start;
  text-align: left;
}
.inline-controls input[type="number"] {
  width: 120px;
  text-align: center;
}

/* Landing page styles */
.landing-hero {
  text-align: center;
  margin: 40px 0 30px;
}
.landing-hero h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
}
.hero-subtitle {
  font-size: 1.1rem;
  color: var(--muted);
}

.service-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin: 30px 0;
}

.service-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  text-decoration: none;
  color: var(--text);
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
  display: flex;
  flex-direction: column;
  position: relative;
  align-items: center;
}

.service-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0,0,0,.1);
  border: 2px solid var(--primary);
}

.service-icon {
  font-size: 3rem;
  color: var(--primary);
  margin-bottom: 12px;
}

.service-card h2 {
  margin: 0 0 8px;
  font-size: 1.4rem;
}

.service-card p {
  color: var(--muted);
  margin: 0;
  flex-grow: 1;
}

.service-arrow {
  position: absolute;
  bottom: 20px;
  right: 20px;
  font-size: 1.5rem;
  color: var(--primary);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
}

.service-card:hover .service-arrow {
  opacity: 1;
  transform: translateX(4px);
}

.info-section {
  margin-top: 40px;
}

.info-links {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.info-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.info-links a:hover {
  text-decoration: underline;
}

/* Toast notification */
.toast {
  position: fixed;
  top: 92px;
  right: 20px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,.15);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 400px;
  z-index: 1000;
  opacity: 0;
  transform: translateY(-20px);
  transition: opacity .3s ease, transform .3s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-icon {
  font-size: 1.5rem;
  color: #10b981;
}

.toast-content {
  flex-grow: 1;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.toast-message {
  font-size: 0.9rem;
  color: var(--muted);
}

.toast-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
  line-height: 1;
}

.toast-close:hover {
  color: var(--text);
}

/* Responsive */
@media (max-width: 1024px) {
  .grid-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .header-inner { padding: 12px 0; height: auto; }
  .logo { height: 40px; }
  .form-table td:first-child { width: 40%; }
  .landing-hero h1 { font-size: 2rem; }
}

@media (max-width: 640px) {
  .grid-form { grid-template-columns: 1fr; }
  .inline-controls { flex-wrap: wrap; }
  .toast {
    left: 10px;
    right: 10px;
    max-width: none;
  }
}

.data-table + .btn { margin-top: 14px; }

/* ELSA-specific styles */
.legal-notice {
  background: rgba(11, 123, 214, 0.1);
  border-left: 4px solid var(--primary);
  border-radius: 12px;
  padding: 20px;
  margin: 20px 0;
  border-radius: 8px;
}

.legal-notice h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--primary);
}

.legal-notice p {
  margin: 0;
  line-height: 1.6;
}

[data-theme="dark"] .legal-notice {
  background: rgba(90, 161, 255, 0.15);
  border-left-color: var(--primary);
}

.media-controls {
  display: flex;
  gap: 12px;
  margin: 20px 0;
  flex-wrap: wrap;
}

.media-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin: 20px 0;
}

.media-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.media-section-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.2rem;
}

.media-table {
  margin-bottom: 12px;
}

.media-table input[type="text"],
.media-table input[type="number"] {
  min-width: 80px;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background-color .2s ease, color .2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.btn-icon:hover {
  background: rgba(0,0,0,.05);
  color: var(--text);
}

[data-theme="dark"] .btn-icon:hover {
  background: rgba(255,255,255,.05);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 0.9rem;
}

/* Signature validation states */
.signature-validating {
  border-color: #f59e0b !important;
  background-image: linear-gradient(45deg, rgba(245, 158, 11, 0.1) 25%, transparent 25%, transparent 50%, rgba(245, 158, 11, 0.1) 50%, rgba(245, 158, 11, 0.1) 75%, transparent 75%, transparent);
  background-size: 20px 20px;
  animation: signature-loading 1s linear infinite;
}

@keyframes signature-loading {
  0% { background-position: 0 0; }
  100% { background-position: 20px 20px; }
}

.signature-valid {
  border-color: #10b981 !important;
  background-color: rgba(16, 185, 129, 0.05);
}

.signature-invalid {
  border-color: #ef4444 !important;
  background-color: #eb5151 !important;
}

.threshold-exceeded {
  background-color: rgba(239, 68, 68, 0.08);
}

[data-theme="dark"] .threshold-exceeded {
  background-color: rgba(239, 68, 68, 0.12);
}

/* Modal/Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  transform: scale(0.9);
  transition: transform 0.2s;
}

.modal-overlay.show .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-header h2 {
  margin: 0;
  flex: 1;
  font-size: 1.25rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  margin-bottom: 20px;
}

.validation-progress {
  margin: 20px 0;
}

.validation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  margin-bottom: 8px;
  border-radius: 4px;
  background: var(--bg);
}

.validation-item .mdi {
  font-size: 1.2rem;
}

.validation-item.checking .mdi-loading {
  animation: spin 1s linear infinite;
}

.validation-item.valid {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
}

.validation-item.invalid {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.validation-item.warning {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.validation-signature {
  font-family: monospace;
  font-weight: 600;
}

.validation-message {
  flex: 1;
  font-size: 0.9rem;
}

.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Academic-title picker modal */
.title-modal-error {
  color: #dc2626;
  margin: 8px 0 0;
  font-size: 0.9rem;
}
