:root {
    --c-bg: #f6f8fb;
    --c-card: #ffffff;
    --c-text: #1a1a1a;
    --c-muted: #6b7280;
    --c-border: #e5e7eb;
    --c-primary: #1864ab;
    --c-primary-hover: #114e85;
    --c-ok: #2b8a3e;
    --c-error: #c92a2a;
    --c-warn: #f59f00;
    --c-row-disabled: #f3f4f6;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 14px;
    line-height: 1.5;
}

body.centered {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code { background: #f3f4f6; padding: 1px 6px; border-radius: 4px; font-size: 13px; }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
    background: #fff;
    border-bottom: 1px solid var(--c-border);
    box-shadow: var(--shadow);
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}
.brand { font-weight: 700; font-size: 18px; color: var(--c-text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.nav a { color: var(--c-text); }
.btn-link {
    background: none; border: none; color: var(--c-primary);
    cursor: pointer; font-size: 14px; padding: 0;
}
.btn-link:hover { text-decoration: underline; }
.inline { display: inline; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 24px auto; padding: 0 24px; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 24px 0 12px; }

/* ── Login card ──────────────────────────────────────────────────────────── */
.login-card {
    background: var(--c-card);
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.08);
    min-width: 320px;
    max-width: 380px;
    width: 100%;
}
.login-card h1 { font-size: 22px; margin: 0 0 4px; text-align: center; }
.login-card p { text-align: center; margin: 0 0 24px; }
.login-card label, .grid-form label {
    display: block;
    margin-bottom: 14px;
}
.login-card label > span, .grid-form label > span {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--c-muted);
}
input[type="text"], input[type="password"], select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--c-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(24, 100, 171, 0.15);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.btn-primary { background: var(--c-primary); color: white; width: 100%; }
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    border: 1px solid var(--c-border);
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
}
.btn-sm:hover { background: #f3f4f6; }
.btn-danger { color: var(--c-error); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 13px;
}
.alert-error { background: #fef2f2; color: var(--c-error); border: 1px solid #fecaca; }
.alert-ok { background: #ecfdf5; color: var(--c-ok); border: 1px solid #a7f3d0; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Cards (dashboard) ──────────────────────────────────────────────────── */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.card {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    color: var(--c-text);
    transition: transform 0.1s, box-shadow 0.1s;
}
a.card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.08); text-decoration: none; }
.card.disabled { opacity: 0.55; }
.card h3 { margin: 0 0 8px; font-size: 16px; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-block {
    background: #fff;
    border: 1px solid var(--c-border);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
}
.form-block summary { cursor: pointer; padding: 4px 0; }
.grid-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 14px;
}
.form-actions { grid-column: 1 / -1; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.data-table th, .data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--c-border);
    font-size: 13px;
    vertical-align: middle;
}
.data-table th {
    background: #f9fafb;
    font-weight: 600;
    color: var(--c-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}
.data-table tr:last-child td { border-bottom: none; }
.row-disabled { background: var(--c-row-disabled); }
.row-disabled td { color: var(--c-muted); }

.kv { border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.kv th, .kv td { padding: 10px 14px; border-bottom: 1px solid var(--c-border); text-align: left; font-size: 14px; }
.kv th { background: #f9fafb; color: var(--c-muted); font-weight: 600; min-width: 140px; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: none; }

.actions { white-space: nowrap; }
.inline-form { display: inline-flex; gap: 4px; align-items: center; margin-right: 6px; }
.inline-form input { padding: 4px 8px; font-size: 12px; width: 140px; }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-admin { background: #fef3c7; color: #92400e; }
.badge-dispatcher { background: #dbeafe; color: #1e40af; }
.badge-driver { background: #d1fae5; color: #065f46; }
.badge-draft { background: #f3f4f6; color: #374151; }
.badge-planned { background: #dbeafe; color: #1e40af; }
.badge-progress { background: #fef3c7; color: #92400e; }
.badge-done { background: #d1fae5; color: #065f46; }
.badge-cancel { background: #fee2e2; color: #991b1b; }

/* ── Page header + empty state ──────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.page-header h1 { margin: 0; }
.btn-inline { width: auto; }
.empty-state {
    background: #fff;
    border: 1px dashed var(--c-border);
    border-radius: 12px;
    padding: 40px 24px;
    text-align: center;
}
.empty-state p { margin: 0 0 16px; color: var(--c-muted); }

.filters {
    display: flex;
    gap: 16px;
    align-items: end;
    flex-wrap: wrap;
}
.filters label { margin: 0; min-width: 180px; }

/* ── Map ────────────────────────────────────────────────────────────────── */
.map-canvas {
    width: 100%;
    height: 480px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    background: #eef2f6;
    margin-bottom: 24px;
}

/* Поля ширины для координат в инлайн-форме */
.inline-form input[name="lat"],
.inline-form input[name="lng"] {
    width: 90px;
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.status-ok { color: var(--c-ok); font-weight: 600; }
.status-off { color: var(--c-error); font-weight: 600; }

.muted { color: var(--c-muted); font-size: 13px; }

/* ── Driver: прогресс + действия по точкам ──────────────────────────── */
.progress-block {
    background: #fff;
    border: 1px solid var(--c-border);
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 20px;
}
.progress-bar {
    display: flex;
    height: 16px;
    width: 100%;
    background: #f3f4f6;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 12px;
}
.progress-fill {
    background: var(--c-ok);
    transition: width 0.3s;
}
.progress-fill.skipped { background: var(--c-warn); }
.progress-stats {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    font-size: 13px;
}

.row-delivered { background: #f0fdf4; }
.row-delivered td { color: #166534; }

.point-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
}
.point-form { background: none; }
.point-form summary {
    display: inline-block;
    text-align: center;
    width: 100%;
    list-style: none;
    cursor: pointer;
    font-weight: 600;
}
.point-form summary::-webkit-details-marker { display: none; }
.btn-ok-summary {
    background: #ecfdf5 !important;
    border-color: #a7f3d0 !important;
    color: #065f46;
}
.btn-ok-summary:hover { background: #d1fae5 !important; }
.btn-skip-summary {
    background: #fef3c7 !important;
    border-color: #fde68a !important;
    color: #92400e;
}
.btn-skip-summary:hover { background: #fde68a !important; }
.point-form-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
    padding: 6px;
    background: #f9fafb;
    border-radius: 6px;
}
.point-form-body input[type="text"] { padding: 6px 8px; font-size: 12px; }
.btn-ok-submit { background: var(--c-ok); color: white; border-color: var(--c-ok); }
.btn-ok-submit:hover { background: #1e6f30; }
.btn-skip-submit { background: var(--c-warn); color: white; border-color: var(--c-warn); }
.btn-skip-submit:hover { background: #d68a00; }
