/*
 * Shared design tokens and theme-switching chrome for the optimizer
 * (index.html) and the results viewer (results.html).
 *
 * Everything colour-related is a custom property declared twice: once on :root
 * for the light theme, once on html.dark for the dark theme. js/theme.js puts
 * the `dark` class on <html> before first paint, so the two pages need no
 * per-rule dark overrides — they just consume the variables.
 *
 * Adding a colour? Declare it in BOTH blocks. A variable that only exists in
 * :root silently keeps its light value in dark mode.
 */

/* ── Light theme (default) ─────────────────────────────────────── */
:root {
    --primary: #1a73e8;
    --primary-hover: #1557b0;
    --on-primary: #ffffff;

    --danger: #d93025;
    --danger-hover: #b3261e;
    --on-danger: #ffffff;

    --success: #188038;
    --success-hover: #137333;
    --success-disabled: #a8dab5;
    --on-success: #ffffff;

    --warning: #ea8600;

    --bg: #f8f9fa;
    --card-bg: #ffffff;
    --input-bg: #ffffff;
    --surface: #f1f3f4;
    --surface-hover: #e8eaed;
    --border: #dadce0;
    --track: #cccccc;

    --text: #202124;
    --text-secondary: #5f6368;

    /* Soft status tints (pill backgrounds) */
    --tint-success: #e6f4ea;
    --tint-warning: #fef7e0;
    --tint-danger: #fce8e6;

    /* Translucent accents */
    --overlay: rgba(0, 0, 0, 0.45);
    --focus-ring: rgba(26, 115, 232, 0.2);
    --danger-ring: rgba(217, 48, 37, 0.15);
    --danger-soft: rgba(217, 48, 37, 0.08);
    --primary-soft: rgba(26, 115, 232, 0.04);

    /* Chart / map tooltips */
    --tooltip-bg: rgba(32, 33, 36, 0.92);
    --tooltip-text: #ffffff;
    --tooltip-title-unassigned: #fca5a5;

    /* Euclidean scatter plot */
    --grid-line: #e8eaed;
    --axis-line: #80868b;
    --node-stroke: #ffffff;

    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);

    /* Applied to OSM raster tiles; `none` leaves them untouched. */
    --tile-filter: none;
}

/* ── Dark theme ────────────────────────────────────────────────────
   Accents are lightened so they stay legible on a dark surface, which
   flips the required text colour on filled buttons from white to near
   black — hence the separate --on-* variables. */
html.dark {
    --primary: #8ab4f8;
    --primary-hover: #aecbfa;
    --on-primary: #17232f;

    --danger: #f28b82;
    --danger-hover: #f6aea9;
    --on-danger: #2c1512;

    --success: #81c995;
    --success-hover: #a8dab5;
    --success-disabled: #38493d;
    --on-success: #12251a;

    --warning: #fdd663;

    --bg: #1b1c1e;
    --card-bg: #26282b;
    --input-bg: #2f3134;
    --surface: #303236;
    --surface-hover: #3c4043;
    --border: #494c50;
    --track: #5f6368;

    --text: #e8eaed;
    --text-secondary: #9aa0a6;

    --tint-success: rgba(129, 201, 149, 0.16);
    --tint-warning: rgba(253, 214, 99, 0.16);
    --tint-danger: rgba(242, 139, 130, 0.16);

    --overlay: rgba(0, 0, 0, 0.7);
    --focus-ring: rgba(138, 180, 248, 0.35);
    --danger-ring: rgba(242, 139, 130, 0.3);
    --danger-soft: rgba(242, 139, 130, 0.12);
    --primary-soft: rgba(138, 180, 248, 0.1);

    --tooltip-bg: rgba(16, 17, 19, 0.95);
    --tooltip-text: #e8eaed;
    --tooltip-title-unassigned: #f28b82;

    --grid-line: #35373b;
    --axis-line: #7c8288;
    --node-stroke: #1b1c1e;

    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);

    /* Invert + re-rotate hue turns the light OSM raster into a dark basemap.
       Only tiles are filtered, so vector routes and markers keep their hues. */
    --tile-filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

/* ── Theme + language controls ─────────────────────────────────── */
.ui-controls {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Square icon button, sized to line up with .btn-action on the optimizer. */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
    background: var(--surface);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* Show the sun in dark mode (click = go light) and the moon in light mode. */
.icon-btn .icon-sun { display: none; }
.icon-btn .icon-moon { display: block; }
html.dark .icon-btn .icon-sun { display: block; }
html.dark .icon-btn .icon-moon { display: none; }

/* EN | TR segmented control */
.lang-switch {
    display: inline-flex;
    align-items: stretch;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

.lang-switch button {
    min-width: 38px;
    padding: 0 9px;
    background: none;
    border: none;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.lang-switch button + button {
    border-left: 1px solid var(--border);
}

.lang-switch button:hover {
    background: var(--surface);
    color: var(--text);
}

.lang-switch button.is-active {
    background: var(--primary);
    color: var(--on-primary);
}

/* Compact variant for the results page top bar, which is 16px shorter. */
.ui-controls.compact .icon-btn,
.ui-controls.compact .lang-switch {
    height: 32px;
}

.ui-controls.compact .icon-btn {
    width: 32px;
}

.ui-controls.compact .lang-switch button {
    min-width: 32px;
    padding: 0 7px;
    font-size: 11px;
}

/* ── Leaflet dark treatment ────────────────────────────────────── */
.leaflet-container {
    background: var(--surface);
}

.leaflet-tile {
    filter: var(--tile-filter);
}

html.dark .leaflet-bar a,
html.dark .leaflet-control-attribution {
    background: var(--card-bg);
    color: var(--text-secondary);
}

html.dark .leaflet-bar a {
    border-bottom-color: var(--border);
}

html.dark .leaflet-bar a:hover {
    background: var(--surface-hover);
    color: var(--text);
}

html.dark .leaflet-control-attribution a {
    color: var(--primary);
}
