/* ============================================================
   Route Optimizer — dark theme
   Soft dark palette (not pure black) for readability outdoors.
   Mobile-first, big touch targets, no iOS zoom-on-focus.
   ============================================================ */

:root {
    /* Background layers, from deepest to most surfaced */
    --bg-base:    #0f1419;   /* page background, deep blue-black */
    --bg-card:    #1a1f26;   /* cards on top of base */
    --bg-raised: #232932;    /* raised elements (inputs, list items) */
    --bg-hover:  #2a313b;    /* hover state */

    /* Text */
    --text-primary:   #e8eaed;
    --text-secondary: #9aa0a6;
    --text-tertiary:  #5f6368;

    /* Borders + dividers */
    --border:       #2d333b;
    --border-focus: #4a90e2;

    /* Accent — main brand color */
    --accent:        #4a90e2;   /* a calm, readable blue */
    --accent-hover:  #5ba0f2;
    --accent-soft:   rgba(74, 144, 226, 0.15);

    /* State colors */
    --success: #34d399;
    --warning: #fbbf24;
    --error:   #f87171;
    --error-bg: rgba(248, 113, 113, 0.12);

    /* Spacing rhythm */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    /* Borders + corners */
    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  14px;
    --radius-pill: 999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    margin: 0;
    line-height: 1.55;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

/* Subtle gradient background -- adds depth without being distracting */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: radial-gradient(
        circle at 50% -20%,
        rgba(74, 144, 226, 0.08) 0%,
        transparent 60%
    );
    pointer-events: none;
    z-index: -1;
}

/* ============================================================
   Header / navigation
   ============================================================ */

header {
    background: rgba(15, 20, 25, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: var(--space-3) var(--space-4);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo {
    font-weight: 700;
    font-size: 18px;
    color: var(--accent);
    text-decoration: none;
    letter-spacing: -0.01em;
}
.logo::before {
    content: "📍";
    margin-right: 6px;
}

nav { display: flex; gap: var(--space-4); }
nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    padding: var(--space-1) 0;
    font-weight: 500;
    transition: color 0.15s;
}
nav a:hover, nav a:active { color: var(--text-primary); }

/* ============================================================
   Main layout
   ============================================================ */

main {
    max-width: 720px;
    margin: 0 auto;
    padding: var(--space-4);
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5) var(--space-5);
    box-shadow: var(--shadow-md);
}

h1 {
    margin: 0 0 var(--space-2);
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.01em;
}
h2 {
    font-size: 17px;
    margin-top: var(--space-6);
    margin-bottom: var(--space-2);
    font-weight: 600;
}
.stops-heading { margin-top: var(--space-6); }

.subtitle {
    color: var(--text-secondary);
    margin: 0 0 var(--space-5);
    font-size: 15px;
}
.subtitle strong { color: var(--text-primary); }

.hint {
    color: var(--text-tertiary);
    font-size: 13px;
    margin: var(--space-1) 0 var(--space-4);
}
.optional { color: var(--text-tertiary); font-weight: 400; }

/* ============================================================
   Form elements
   ============================================================ */

label {
    display: block;
    margin-top: var(--space-4);
    margin-bottom: var(--space-2);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="file"] {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 16px; /* >= 16px prevents iOS zoom-on-focus */
    font-family: inherit;
    background: var(--bg-raised);
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: var(--text-tertiary); }
input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="file"] {
    padding: 10px 12px;
    cursor: pointer;
}
input[type="file"]::file-selector-button {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    margin-right: var(--space-3);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
}

/* ============================================================
   Buttons
   ============================================================ */

button,
.btn-primary,
.btn-secondary {
    display: inline-block;
    padding: 14px 22px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    margin-top: var(--space-4);
    font-family: inherit;
    min-height: 48px;
    transition: background 0.15s, transform 0.05s;
}
button:active, .btn-primary:active, .btn-secondary:active { transform: scale(0.98); }

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.25);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
    background: var(--bg-hover);
    color: var(--text-tertiary);
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--text-secondary);
}

.btn-large { padding: 16px 28px; font-size: 17px; }
.btn-block { width: 100%; margin-top: var(--space-3); }

.url-buttons { margin: var(--space-5) 0; }
.url-buttons .btn-primary {
    margin-bottom: var(--space-3);
    width: 100%;
}

/* ============================================================
   Flash messages
   ============================================================ */

.flash {
    padding: 14px 16px;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    font-size: 15px;
    border-left: 4px solid;
}
.flash-success {
    background: rgba(52, 211, 153, 0.1);
    color: var(--success);
    border-left-color: var(--success);
}
.flash-error {
    background: var(--error-bg);
    color: var(--error);
    border-left-color: var(--error);
}

/* ============================================================
   Preview page: route endpoints + editable stops
   ============================================================ */

.route-endpoints {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    margin-top: var(--space-4);
}
.endpoint-label {
    margin-top: var(--space-2);
    font-size: 11px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}
.endpoint-label:first-child { margin-top: 0; }
.endpoint-row { margin-bottom: var(--space-2); }
.endpoint-row:last-child { margin-bottom: var(--space-1); }
.endpoint-row input {
    background: var(--bg-card);
}

.editable-stops {
    list-style: none;
    padding: 0;
    margin: 0;
}
.stop-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    transition: opacity 0.15s, transform 0.15s;
}
.stop-item.removing {
    opacity: 0;
    transform: translateX(20px);
}
.stop-num {
    flex: 0 0 auto;
    min-width: 28px;
    height: 28px;
    line-height: 28px;
    text-align: center;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 700;
}
.stop-address {
    flex: 1;
    padding: 11px 12px !important;
    font-size: 15px !important;
    border-radius: var(--radius-sm) !important;
    background: var(--bg-raised) !important;
}
.stop-remove {
    flex: 0 0 auto;
    background: var(--error-bg);
    color: var(--error);
    border: none;
    width: 38px;
    height: 38px;
    min-height: 38px;
    border-radius: 50%;
    font-size: 22px;
    font-weight: 700;
    padding: 0;
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.15s;
}
.stop-remove:hover, .stop-remove:active { background: rgba(248, 113, 113, 0.25); }

.action-row {
    margin-top: var(--space-6);
    display: flex;
    gap: var(--space-3);
    flex-direction: column;
}
.action-row .btn-primary { width: 100%; }
.action-row .btn-secondary { width: 100%; margin-top: 0; }

/* ============================================================
   History table
   ============================================================ */

.routes-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--space-3);
    font-size: 14px;
}
.routes-table th {
    text-align: left;
    padding: var(--space-3) var(--space-2);
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
}
.routes-table th:first-child { border-top-left-radius: var(--radius-sm); }
.routes-table th:last-child { border-top-right-radius: var(--radius-sm); }
.routes-table td {
    padding: var(--space-3) var(--space-2);
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}
.routes-table tr:hover td { background: var(--bg-raised); }
.routes-table a { color: var(--accent); text-decoration: none; font-weight: 500; }
.routes-table a:hover { color: var(--accent-hover); }

.status-done           { color: var(--success); font-weight: 600; }
.status-pending        { color: var(--warning); font-weight: 600; }
.status-pending-preview { color: var(--accent);  font-weight: 600; }
.status-error          { color: var(--error);   font-weight: 600; }

/* ============================================================
   Route detail page: ordered stops list
   ============================================================ */

.stops-list {
    padding: 0;
    margin: var(--space-4) 0 0;
    list-style: none;
    counter-reset: stop-counter;
}
.stops-list li {
    padding: var(--space-3) var(--space-4);
    background: var(--bg-raised);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-2);
    position: relative;
    padding-left: 48px;
    counter-increment: stop-counter;
}
.stops-list li::before {
    content: counter(stop-counter);
    position: absolute;
    left: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    background: var(--accent);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}
.stop-start, .stop-end {
    padding: var(--space-3) var(--space-4) !important;
    padding-left: var(--space-4) !important;
    background: var(--bg-card) !important;
    border: 1px solid var(--border);
}
.stop-start::before, .stop-end::before {
    display: none !important;
}
.stop-start strong, .stop-end strong {
    display: inline-block;
    padding: 2px 8px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: var(--radius-sm);
    font-size: 11px;
    letter-spacing: 0.08em;
    margin-right: var(--space-3);
    font-weight: 700;
}

/* ============================================================
   Mobile tweaks
   ============================================================ */

@media (max-width: 600px) {
    main { padding: var(--space-3); }
    .card { padding: var(--space-4); }
    nav { gap: var(--space-3); }
    nav a { font-size: 13px; }
    h1 { font-size: 22px; }

    /* Hide ID column on history table; keep date as the link */
    .routes-table { font-size: 13px; }
    .routes-table th, .routes-table td {
        padding: var(--space-2) var(--space-2);
    }
}

/* ============================================================
   Login page: centered card
   ============================================================ */

.login-wrapper {
    min-height: calc(100vh - 70px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}
.login-card {
    max-width: 380px;
    width: 100%;
}
