/* ============================================================================
 * IPOL modern base — restyles the core shell using the design tokens
 * (tokens.css). Loaded LAST so it layers over the legacy component CSS. Scope:
 * page surfaces, typography, links, buttons, form controls, panels, tables,
 * code, scrollbars, and the theme toggle. Deep widgets (editor, galleries, map)
 * are migrated to tokens in later iterations.
 * ==========================================================================*/

html {
  color-scheme: light dark;
}

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Typography ---------------------------------------------------------------*/
h1, h2, h3, h4, h5, h6 {
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
p, li, label, td, th {
  color: var(--text-secondary);
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}
hr {
  border: 0;
  border-top: 1px solid var(--border);
}
code, pre, kbd {
  font-family: var(--font-mono);
}
pre {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  overflow: auto;
}

/* Surfaces / panels --------------------------------------------------------*/
.container,
.panel,
.card,
.box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* Buttons ------------------------------------------------------------------*/
.btn,
button:not(.theme-toggle):not(.unstyled),
input[type="button"],
input[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font: inherit;
  font-weight: 600;
  line-height: 1.1;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease,
    transform 0.05s ease, box-shadow 0.15s ease;
}
.btn:hover,
button:not(.theme-toggle):not(.unstyled):hover,
input[type="button"]:hover,
input[type="submit"]:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.btn:active,
button:not(.theme-toggle):not(.unstyled):active {
  transform: translateY(1px);
}
.btn-primary,
.btn.primary,
input[type="submit"] {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
}
.btn-primary:hover,
.btn.primary:hover,
input[type="submit"]:hover {
  background: var(--accent-hover);
  color: var(--accent-contrast);
}
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Form controls ------------------------------------------------------------*/
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 11px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
input[type="range"] {
  accent-color: var(--accent);
}
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
}
::placeholder {
  color: var(--text-muted);
}

/* Tables -------------------------------------------------------------------*/
table {
  border-collapse: collapse;
}
th, td {
  border-color: var(--border);
}

/* Scrollbars ---------------------------------------------------------------*/
* {
  scrollbar-color: var(--border-strong) transparent;
}
::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
  background-clip: padding-box;
}

/* Theme toggle (floating, top-right) --------------------------------------*/
.theme-toggle {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.theme-toggle:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}
.theme-toggle:active {
  transform: translateY(0);
}
