/* Cartographie — Linear-inspired dark mode
 * Design tokens from /DESIGN.md
 */

@import url('https://rsms.me/inter/inter.css');

:root {
    /* Backgrounds */
    --bg-marketing: #08090a;
    --bg-panel: #0f1011;
    --bg-surface: #191a1b;
    --bg-surface-2: #28282c;

    /* Text */
    --text-primary: #f7f8f8;
    --text-secondary: #d0d6e0;
    --text-tertiary: #8a8f98;
    --text-quaternary: #62666d;

    /* Brand */
    --brand: #5e6ad2;
    --accent: #7170ff;
    --accent-hover: #828fff;

    /* Status */
    --status-ok: #27a644;
    --status-err: #ef4444;
    --status-warn: #eab308;

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.05);
    --border-standard: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.12);

    /* Radii */
    --r-sm: 4px;
    --r-md: 6px;
    --r-lg: 8px;
    --r-xl: 12px;
    --r-pill: 9999px;

    /* Shadows */
    --shadow-ring: 0 0 0 1px rgba(0, 0, 0, 0.2);
    --shadow-elev: rgba(0, 0, 0, 0.4) 0px 2px 4px;
    --shadow-dialog:
        rgba(0, 0, 0, 0) 0 8px 2px,
        rgba(0, 0, 0, 0.04) 0 3px 2px,
        rgba(0, 0, 0, 0.08) 0 0 1px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg-marketing);
    color: var(--text-primary);
    font-family: 'Inter var', 'Inter', -apple-system, system-ui, sans-serif;
    font-feature-settings: "cv01", "ss03";
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

h1, h2, h3 {
    color: var(--text-primary);
    font-weight: 590;
    letter-spacing: -0.288px;
    margin: 0 0 16px;
}
h1 { font-size: 32px; letter-spacing: -0.704px; }
h2 { font-size: 20px; letter-spacing: -0.24px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); font-weight: 510; }

p { margin: 0 0 12px; }
.muted { color: var(--text-tertiary); font-size: 14px; }
code { font-family: 'Berkeley Mono', ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; background: var(--border-subtle); padding: 2px 6px; border-radius: 3px; }

/* ---------- Layout ---------- */

.app-body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-left, .nav-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    font-weight: 590;
    font-size: 15px;
    letter-spacing: -0.2px;
}
.brand-mark {
    width: 20px;
    height: 20px;
    background: var(--brand);
    border-radius: 5px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
}
.brand-mark.large { width: 48px; height: 48px; border-radius: 12px; }

.nav-link {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 510;
}
.nav-link:hover { color: var(--text-primary); }

.user-email {
    color: var(--text-tertiary);
    font-size: 13px;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ---------- Flash messages ---------- */

.flash-container {
    position: fixed;
    top: 72px;
    right: 24px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 420px;
}
.flash {
    padding: 12px 16px;
    border-radius: var(--r-lg);
    background: var(--bg-surface);
    border: 1px solid var(--border-standard);
    font-size: 14px;
    color: var(--text-primary);
    box-shadow: var(--shadow-elev);
    animation: slide-in 0.25s ease-out;
}
.flash-success { border-left: 3px solid var(--status-ok); }
.flash-error { border-left: 3px solid var(--status-err); }
.flash-warning { border-left: 3px solid var(--status-warn); }

@keyframes slide-in {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-standard);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 510;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.05); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-full { width: 100%; }

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: rgba(255, 255, 255, 0.02); }

.btn-danger { color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); }

/* ---------- Forms ---------- */

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}
.field-label {
    font-size: 12px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 510;
}
.field input, .field select, .field textarea {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-standard);
    border-radius: var(--r-md);
    padding: 10px 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.04);
}

.field-errors {
    color: #fca5a5;
    font-size: 13px;
    margin-bottom: 8px;
}

.admin-form {
    display: flex;
    flex-direction: column;
    max-width: 480px;
    gap: 4px;
}

.inline-form {
    display: inline-block;
}

/* ---------- Login ---------- */

.login-page {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    background:
        radial-gradient(ellipse at top, rgba(94, 106, 210, 0.08), transparent 50%),
        var(--bg-marketing);
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-standard);
    border-radius: var(--r-xl);
    padding: 40px 32px;
    box-shadow: var(--shadow-dialog);
}
.login-header {
    text-align: center;
    margin-bottom: 32px;
}
.login-header .brand-mark {
    margin: 0 auto 16px;
}
.login-header h1 {
    font-size: 28px;
    margin-bottom: 4px;
}
.login-subtitle {
    color: var(--text-tertiary);
    font-size: 14px;
    margin: 0;
}
.login-form .btn {
    margin-top: 8px;
}

/* ---------- Graph page ---------- */

.graph-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    height: calc(100vh - 56px);
}

.graph-sidebar {
    width: 280px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-subtle);
    overflow-y: auto;
    padding: 20px;
}

.sidebar-section {
    margin-bottom: 24px;
}
.sidebar-section h3 {
    margin-bottom: 10px;
}

.search-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-standard);
    border-radius: var(--r-md);
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
}
.search-input:focus { border-color: var(--accent); }

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.filter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: var(--r-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
    user-select: none;
}
.filter-item:hover { background: rgba(255, 255, 255, 0.03); }
.filter-item input[type="checkbox"] {
    accent-color: var(--accent);
}

.perim-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.stats-section .stat-line {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 13px;
    color: var(--text-tertiary);
}
.stats-section .stat-line strong {
    color: var(--text-primary);
    font-weight: 510;
}

.graph-stage {
    flex: 1;
    position: relative;
    background: var(--bg-marketing);
    overflow: hidden;
}

#graph-canvas {
    position: absolute;
    inset: 0;
}
#graph-canvas canvas { display: block; }

.tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--bg-surface);
    border: 1px solid var(--border-standard);
    border-radius: var(--r-lg);
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-primary);
    max-width: 280px;
    box-shadow: var(--shadow-dialog);
    z-index: 10;
}
.tooltip strong { display: block; margin-bottom: 4px; }
.tooltip .tooltip-meta { color: var(--text-tertiary); font-size: 12px; }

.loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: var(--bg-marketing);
    color: var(--text-tertiary);
    z-index: 20;
    transition: opacity 0.3s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border-standard);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.legend {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgba(15, 16, 17, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-standard);
    border-radius: var(--r-md);
    padding: 10px 12px;
    font-size: 12px;
    color: var(--text-secondary);
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}
.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* ---------- Zoom controls ---------- */

.zoom-controls {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(15, 16, 17, 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-standard);
    border-radius: var(--r-lg);
    overflow: hidden;
    z-index: 10;
    box-shadow: var(--shadow-elev);
}
.zoom-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    font-weight: 590;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}
.zoom-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}
.zoom-btn:active {
    background: rgba(255, 255, 255, 0.12);
}
.zoom-btn-fit {
    border-top: 1px solid var(--border-subtle);
    font-size: 16px;
}
.zoom-level {
    width: 36px;
    padding: 2px 0;
    text-align: center;
    font-size: 10px;
    font-weight: 510;
    color: var(--text-tertiary);
    border-top: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    user-select: none;
}

/* ---------- Filter toggle buttons ---------- */

.filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.filter-header h3 { margin-bottom: 0; }
.toggle-btns {
    display: flex;
    gap: 4px;
}
.btn-toggle {
    padding: 2px 8px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border-standard);
    background: transparent;
    color: var(--text-tertiary);
    font-family: inherit;
    font-size: 11px;
    font-weight: 510;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-toggle:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

/* ---------- Detail panel (right sidebar) ---------- */

.detail-panel {
    width: 320px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-subtle);
    overflow-y: auto;
    padding: 20px;
    position: relative;
    animation: slide-in-right 0.2s ease-out;
}
.detail-panel[hidden] { display: none; }

@keyframes slide-in-right {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

.detail-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--r-sm);
    line-height: 1;
}
.detail-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.detail-card {
    margin-bottom: 20px;
}
.detail-card-name {
    font-size: 18px;
    font-weight: 590;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.2px;
}
.detail-card-type {
    font-size: 12px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}
.detail-field {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 13px;
}
.detail-field-label {
    color: var(--text-tertiary);
}
.detail-field-value {
    color: var(--text-primary);
    font-weight: 510;
    text-align: right;
    max-width: 60%;
}
.detail-perimeters {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 12px;
}

.detail-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-subtle);
}
.detail-section h3 {
    margin-bottom: 12px;
}

.kpi-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 13px;
}
.kpi-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}
.kpi-value {
    font-weight: 590;
    color: var(--text-primary);
}
.kpi-bar-bg {
    flex: 1;
    height: 4px;
    background: var(--border-subtle);
    border-radius: 2px;
    margin: 0 10px;
    min-width: 40px;
}
.kpi-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* ---------- Admin pages ---------- */

.admin-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}
.admin-title {
    font-size: 28px;
    letter-spacing: -0.56px;
    margin-bottom: 24px;
}
.admin-section {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-standard);
    border-radius: var(--r-xl);
    padding: 24px;
    margin-bottom: 20px;
}
.admin-grid {
    display: grid;
    gap: 20px;
    grid-template-columns: 1fr 1fr;
}
@media (max-width: 900px) {
    .admin-grid { grid-template-columns: 1fr; }
}

.stats-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    margin-bottom: 24px;
}
.stat-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-standard);
    border-radius: var(--r-lg);
    padding: 20px 24px;
}
.stat-value {
    font-size: 32px;
    font-weight: 590;
    color: var(--text-primary);
    letter-spacing: -0.704px;
}
.stat-label {
    color: var(--text-tertiary);
    font-size: 13px;
    margin-top: 4px;
}

.perimeter-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.perimeter-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 14px;
}
.perim-name { flex: 1; color: var(--text-secondary); }
.perim-count { color: var(--text-primary); font-weight: 510; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th, .data-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-subtle);
}
.data-table th {
    color: var(--text-tertiary);
    font-weight: 510;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}
.data-table td { color: var(--text-secondary); }
.data-table tr:hover td { background: rgba(255, 255, 255, 0.02); }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 11px;
    font-weight: 510;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}
.badge-ok { color: #86efac; border-color: rgba(39, 166, 68, 0.3); }
.badge-off { color: var(--text-tertiary); }

.perim-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--r-pill);
    font-size: 11px;
    border: 1px solid;
    margin-right: 4px;
    margin-bottom: 2px;
}

.actions { display: flex; gap: 6px; }

.error-pre {
    font-size: 11px;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px;
    border-radius: var(--r-sm);
    white-space: pre-wrap;
    max-height: 200px;
    overflow: auto;
    color: #fca5a5;
}
