/* Blue Marlin ATX admin palette — matches the phone BrandColors. */
:root {
    --brand-primary-dark: #130C44;
    --brand-primary: #0070BC;
    --brand-accent: #19CCF5;
    --brand-accent-alt: #029DD4;
    --brand-crimson: #D11037;
    --brand-on-primary: #FFFFFF;
    --brand-surface: #F5FBFE;
    --brand-surface-variant: #E2F1FA;
    --brand-on-surface: #130C44;
    --brand-muted: #6b7789;
    --brand-border: #cfe1ef;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--brand-surface);
    color: var(--brand-on-surface);
    min-height: 100vh;
}

/* ---------- Login ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, var(--brand-primary-dark) 0%, var(--brand-primary) 100%);
}
.login-card {
    background: var(--brand-surface);
    border-radius: 16px;
    padding: 40px 48px;
    min-width: 360px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    text-align: center;
}
.login-card h1 {
    margin: 0;
    color: var(--brand-primary-dark);
    font-size: 28px;
}
.login-sub {
    color: var(--brand-muted);
    margin-top: 4px;
    margin-bottom: 28px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 12px;
}
.login-form label {
    display: flex;
    flex-direction: column;
    text-align: left;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--brand-muted);
    gap: 6px;
}
.login-form input {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--brand-border);
    font-size: 15px;
    background: white;
    color: var(--brand-on-surface);
}
.login-form input:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(25,204,245,0.2);
}

/* ---------- Layout chrome ---------- */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: var(--brand-primary-dark);
    color: var(--brand-on-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.brand {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}
.brand-title { font-size: 18px; font-weight: 600; }
.brand-sub   { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brand-accent); }

nav ul {
    display: flex;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
    align-items: center;
}
nav a {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 6px;
    color: var(--brand-on-primary);
    text-decoration: none;
    font-size: 14px;
}
nav a:hover { background: rgba(255,255,255,0.08); }
nav a.active { background: var(--brand-primary); }

main {
    max-width: 1080px;
    margin: 0 auto;
    padding: 32px;
}

/* ---------- Sections / forms / tables ---------- */
.section {
    background: white;
    border: 1px solid var(--brand-border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}
.section h2 {
    margin-top: 0;
    margin-bottom: 16px;
    color: var(--brand-primary-dark);
    font-size: 18px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    align-items: end;
}
.form-row label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: var(--brand-muted);
    gap: 6px;
}
.form-row input, .form-row select {
    padding: 9px 11px;
    border-radius: 8px;
    border: 1px solid var(--brand-border);
    font-size: 14px;
    background: white;
    color: var(--brand-on-surface);
}
.form-row input:focus, .form-row select:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(25,204,245,0.2);
}

/* ---------- Buttons ---------- */
button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
}
button.primary {
    background: var(--brand-primary);
    color: var(--brand-on-primary);
}
button.primary:hover { background: var(--brand-accent-alt); }
button.secondary {
    background: var(--brand-surface-variant);
    color: var(--brand-primary-dark);
}
button.secondary:hover { background: var(--brand-border); }
button.danger {
    background: var(--brand-crimson);
    color: var(--brand-on-primary);
}
button.danger:hover { background: #a80e2c; }
button.logout {
    background: transparent;
    color: var(--brand-on-primary);
    border: 1px solid rgba(255,255,255,0.3);
}
button.logout:hover { background: rgba(255,255,255,0.08); }

/* ---------- Tables ---------- */
table {
    width: 100%;
    border-collapse: collapse;
}
thead th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--brand-muted);
    padding: 10px 12px;
    border-bottom: 2px solid var(--brand-border);
}
tbody td {
    padding: 12px;
    border-bottom: 1px solid var(--brand-border);
    font-size: 14px;
}
tbody tr:hover { background: var(--brand-surface-variant); }
td.actions { display: flex; gap: 8px; }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--brand-muted); }
td .subtle { font-size: 12px; color: var(--brand-muted); }

/* role picker inline edit */
.role-cell select {
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid var(--brand-border);
    background: white;
    font-size: 13px;
}

/* ---------- Flash / errors ---------- */
#flash, .flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}
.flash.info    { background: var(--brand-surface-variant); color: var(--brand-primary-dark); border: 1px solid var(--brand-border); }
.flash.success { background: #e6f9ef; color: #0a6c36; border: 1px solid #b4ebca; }
.flash.error   { background: #fde9ec; color: #8e0a23; border: 1px solid #f3bcc6; }

.error {
    color: var(--brand-crimson);
    font-size: 13px;
    margin-top: 8px;
}
.empty { color: var(--brand-muted); font-style: italic; }
.hint  { color: var(--brand-muted); font-size: 13px; }

.inline-prompt {
    display: flex;
    gap: 8px;
    align-items: end;
    padding: 10px 12px;
    background: var(--brand-surface-variant);
    border-radius: 8px;
}
.inline-prompt label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: var(--brand-muted);
    gap: 4px;
    flex: 1;
}
.inline-prompt input {
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--brand-border);
}

/* ---------- Password field with reveal toggle ---------- */
.password-field-group {
    position: relative;
    display: flex;
    align-items: stretch;
}
.password-field-group input {
    flex: 1;
    padding-right: 60px;
    padding: 10px 70px 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--brand-border);
    font-size: 15px;
    background: white;
    color: var(--brand-on-surface);
    width: 100%;
}
.password-field-group input:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(25,204,245,0.2);
}
.password-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 10px;
    background: var(--brand-surface-variant);
    color: var(--brand-primary-dark);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--brand-border);
}
.password-toggle:hover {
    background: var(--brand-border);
}

/* ---------- Route Planner ---------- */
.planner-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 20px;
    min-height: 600px;
}
@media (max-width: 900px) {
    .planner-layout { grid-template-columns: 1fr; }
}

.planner-sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#day-selector {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.day-btn {
    position: relative;
    flex: 1;
    min-width: 72px;
    min-height: 64px;
    padding: 8px 6px;
    border: none;
    border-bottom: 3px solid transparent;
    background: var(--brand-surface-variant);
    color: var(--brand-on-surface);
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px 6px 0 0;
    cursor: grab;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-align: center;
}
.day-btn:active { cursor: grabbing; }
.day-btn:hover { background: var(--brand-border); }
.day-btn.active { background: white; border-bottom-width: 3px; }
.day-btn-day {
    font-size: 14px;
    font-weight: 700;
    color: var(--brand-primary-dark);
}
.day-btn-sub {
    font-size: 11px;
    font-weight: 500;
    color: var(--brand-muted);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.day-btn-count {
    position: absolute;
    top: 4px;
    right: 6px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--brand-primary);
    color: white;
    font-size: 10px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}
.day-btn-count:empty { display: none; }

#day-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--brand-primary-dark);
    margin: 0;
    cursor: pointer;
}
#day-title:hover { color: var(--brand-primary); }

.stop-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: white;
    border: 1px solid var(--brand-border);
    border-radius: 8px;
    margin-bottom: 6px;
    transition: box-shadow 0.15s;
}
.stop-row:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.sortable-ghost { opacity: 0.4; }

.drag-handle {
    cursor: grab;
    font-size: 18px;
    color: var(--brand-muted);
    user-select: none;
}
.stop-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: white;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}
.stop-info { flex: 1; min-width: 0; }
.stop-name { font-weight: 600; font-size: 14px; color: var(--brand-on-surface); }
.stop-address { font-size: 12px; color: var(--brand-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.remove-btn {
    background: none;
    border: none;
    color: var(--brand-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.remove-btn:hover { background: #fde9ec; color: var(--brand-crimson); }
.empty-stops { color: var(--brand-muted); font-style: italic; padding: 20px; text-align: center; }

.add-customer-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
/* Without min-width:0 the select grows to fit the widest <option> (long
   "Name — Address" strings), overflowing the 380px sidebar and pushing the
   Add button off-screen. Forces the select to obey flex shrinking. */
.add-customer-row select {
    flex: 1 1 0;
    min-width: 0;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--brand-border);
    font-size: 13px;
    background: white;
    color: var(--brand-on-surface);
}
.add-customer-row button {
    flex-shrink: 0;
    white-space: nowrap;
}

/* Compact per-stop day selector used on each stop row to reassign a stop
   to a different day of the week. */
.stop-day-select {
    padding: 4px 6px;
    border: 1px solid var(--brand-border);
    border-radius: 6px;
    font-size: 12px;
    background: var(--brand-surface-variant);
    color: var(--brand-primary-dark);
    font-weight: 600;
    cursor: pointer;
}
.stop-day-select:hover { background: var(--brand-border); }

/* Leaflet's internal panes use z-index 200-700; clamping the map container
   to a low z-index keeps native <select> popups from being overlayed in the
   rare case they're rendered inside the same stacking context. */
#route-map {
    border-radius: 12px;
    border: 1px solid var(--brand-border);
    min-height: 500px;
    position: relative;
    z-index: 0;
}
.planner-sidebar {
    position: relative;
    z-index: 2;
    min-width: 0;   /* allow children to shrink properly inside grid */
}
/* Widen sidebar slightly on large desktops so the Generate + Optimize
   buttons sit on one row instead of wrapping. */
@media (min-width: 1400px) {
    .planner-layout { grid-template-columns: 420px 1fr; }
}

.route-stats-bar {
    display: flex;
    gap: 20px;
    padding: 12px 16px;
    background: var(--brand-surface-variant);
    border-radius: 8px;
    margin-top: 12px;
}
.stat { font-size: 14px; color: var(--brand-on-surface); }
.stat b { color: var(--brand-primary-dark); }
.stat-loading, .stat-empty { color: var(--brand-muted); font-style: italic; }

.planner-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.marker-label {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    font-weight: 700;
    font-size: 11px;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

/* ---------- Dashboard ---------- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.dashboard-tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: white;
    border: 1px solid var(--brand-border);
    border-radius: 10px;
    padding: 16px;
    text-decoration: none;
    color: inherit;
    transition: border-color 120ms, transform 120ms;
}
.dashboard-tile:hover {
    border-color: var(--brand-primary);
    transform: translateY(-1px);
}
.dashboard-tile.placeholder {
    opacity: 0.7;
}
.tile-heading {
    font-size: 12px;
    font-weight: 600;
    color: var(--brand-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.tile-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--brand-primary-dark);
    margin: 4px 0 2px;
}
.tile-sub {
    font-size: 12px;
    color: var(--brand-muted);
}

/* ---------- Customer edit ---------- */
.site-card {
    background: white;
    border: 1px solid var(--brand-border);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 20px;
}
.site-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.site-card-head h2 {
    margin: 0;
    font-size: 18px;
}
.pin-badge {
    background: var(--brand-accent);
    color: var(--brand-primary-dark);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 10px;
}
.site-map {
    height: 220px;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--brand-border);
}
.site-pin-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.service-days-row {
    margin: 12px 0;
    padding: 12px;
    background: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 8px;
}
.service-days-label {
    display: block;
    font-size: 12px;
    color: var(--brand-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}
.service-days-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.day-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--brand-border);
    border-radius: 999px;
    background: white;
    font-size: 13px;
    font-weight: 600;
    color: var(--brand-muted);
    cursor: pointer;
    user-select: none;
    transition: background 120ms, color 120ms, border-color 120ms;
}
.day-chip input { margin: 0; }
.day-chip.on {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
    color: white;
}
.day-chip:hover { border-color: var(--brand-primary); }

.codes-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed var(--brand-border);
}
.codes-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.codes-header h2 { margin: 0; font-size: 16px; }
.codes-list { margin-bottom: 12px; }
.codes-list .empty {
    color: var(--brand-muted);
    font-size: 13px;
    padding: 12px;
    background: var(--brand-surface);
    border-radius: 6px;
    text-align: center;
}
.code-row {
    display: grid;
    grid-template-columns: minmax(140px, 1fr) minmax(100px, 140px) minmax(140px, 1fr) auto;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.code-row input {
    padding: 8px 10px;
    border: 1px solid var(--brand-border);
    border-radius: 6px;
    font: inherit;
    color: var(--brand-on-surface);
    min-width: 0;
}
.code-row input[name="codeValue"] {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-weight: 600;
    letter-spacing: 0.03em;
}
@media (max-width: 700px) {
    .code-row { grid-template-columns: 1fr 1fr auto; }
    .code-row input[name="codeNotes"] { grid-column: 1 / -1; }
}
.site-form label, .customer-form label {
    display: block;
    margin-top: 10px;
    font-size: 13px;
    color: var(--brand-muted);
}
.site-form input, .site-form textarea, .site-form select,
.customer-form input, .customer-form textarea, .customer-form select {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid var(--brand-border);
    border-radius: 6px;
    font: inherit;
    color: var(--brand-on-surface);
}
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.row-action {
    color: var(--brand-primary);
    font-weight: 600;
    text-decoration: none;
}
.row-action:hover { text-decoration: underline; }
button.secondary {
    background: var(--brand-surface-variant);
    color: var(--brand-primary-dark);
    border: 1px solid var(--brand-border);
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
}
button.ghost {
    background: transparent;
    color: var(--brand-primary);
    border: 1px solid var(--brand-border);
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
}
