:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --line: #e2e8f0;
    --text: #1f2933;
    --muted: #64748b;
    --primary: #2563eb;
    --green: #16a34a;
    --red: #dc2626;
    --amber: #d97706;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    background: #0f172a;
    color: #fff;
    padding: 10px 22px;
    flex-wrap: wrap;
}
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 17px; }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: #cbd5e1; text-decoration: none; font-size: 14px; }
.topbar nav a:hover { color: #fff; }
.topbar .logout { display: flex; align-items: center; gap: 10px; }
.topbar .user { color: #94a3b8; font-size: 13px; }
.topbar .logout button {
    background: transparent; color: #fca5a5; border: 1px solid #475569;
    border-radius: 6px; padding: 5px 10px; cursor: pointer;
}

.container { max-width: 1100px; margin: 24px auto; padding: 0 18px; }

.messages { list-style: none; padding: 0; margin: 0 0 18px; }
.messages .msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-size: 14px; }
.messages .success { background: #dcfce7; color: #166534; }
.messages .error { background: #fee2e2; color: #991b1b; }
.messages .info { background: #dbeafe; color: #1e40af; }

h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 17px; margin: 22px 0 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: 12px; padding: 16px 18px;
}
.card .value { font-size: 30px; font-weight: 700; }
.card .label { color: var(--muted); font-size: 13px; margin-top: 4px; }
.card-alert { border-color: #fca5a5; background: #fef2f2; }
.card-alert .value { color: var(--red); }

table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }

/* --- Поля ввода: единый минималистичный вид --- */
input[type="text"], input[type="search"], input[type="number"],
input[type="password"], input[type="email"], input[type="date"],
select, textarea {
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:hover, select:hover, textarea:hover { border-color: #cbd5e1; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}
input::placeholder { color: #94a3b8; }

/* Нативная стрелка заменяется своей — иначе список выглядит по-системному. */
select {
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    padding-right: 30px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%2364748b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 11px 7px;
}
select.select-open { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13); }
table select, table input[type="text"] { width: 100%; }

/* --- Свой выпадающий список (один на страницу, открывается у поля) --- */
.select-menu {
    position: fixed;
    box-sizing: border-box;
    z-index: 60;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.16);
    padding: 6px;
}
.select-search {
    width: 100%;
    margin-bottom: 6px;
    padding: 7px 9px;
    font-size: 13px;
}
.select-options { max-height: 280px; overflow-y: auto; }
.select-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 14px;
    cursor: pointer;
}
.select-option:hover, .select-option.active { background: #f1f5f9; }
.select-option[aria-selected="true"] { color: var(--primary); font-weight: 600; }
.select-option[aria-selected="true"]::after { content: "✓"; font-size: 12px; }
.select-option.opt-busy, .select-option.opt-no-driver { color: var(--amber); }
.select-option.opt-has-driver { color: var(--green); }
.select-empty { padding: 10px; font-size: 13px; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.on_line, .badge.new { background: #dcfce7; color: #166534; }
.badge.repair, .badge.rejected, .badge.urgent { background: #fee2e2; color: #991b1b; }
.badge.wait_repair, .badge.assigned, .badge.high { background: #fef3c7; color: #92400e; }
.badge.conservation, .badge.no_driver, .badge.no_registration, .badge.done { background: #e2e8f0; color: #475569; }
.badge.in_progress { background: #dbeafe; color: #1e40af; }

.btn {
    display: inline-block; background: var(--primary); color: #fff; border: none;
    border-radius: 8px; padding: 9px 16px; font-size: 14px; cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: #1d4ed8; }
.btn.secondary { background: #e2e8f0; color: #1f2933; }
.btn.danger { background: transparent; color: var(--red); border: 1px solid #fca5a5; padding: 5px 10px; }

.form-grid { display: grid; gap: 14px; max-width: 620px; background: var(--card); padding: 20px; border: 1px solid var(--line); border-radius: 12px; }
.form-grid label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.form-grid input, .form-grid select, .form-grid textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.filters { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }
.suggest { color: var(--green); font-size: 12px; }
a.plain { color: var(--primary); text-decoration: none; }
a.plain:hover { text-decoration: underline; }
.login-box { max-width: 360px; margin: 60px auto; }

/* --- Автокомплит объекта --- */
.autocomplete { position: relative; }
.ac-results {
    position: absolute; z-index: 20; left: 0; right: 0; top: 100%;
    background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12); max-height: 260px; overflow-y: auto;
}
.ac-item { padding: 8px 10px; font-size: 14px; cursor: pointer; }
.ac-item:hover { background: #f1f5f9; }

/* --- Строки позиций (типы техники) --- */
.item-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.item-row .item-type { flex: 1; }
.item-row .item-qty { width: 90px; }
.item-row .item-del { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.item-row .row-remove { padding: 4px 10px; line-height: 1; }

/* --- Сетка формы назначения --- */
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: #f1f5f9; }
tr.overdue td { background: #fef2f2; }
tr.overdue:hover td { background: #fee2e2; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 6px; flex-wrap: wrap; }
.tab {
    padding: 8px 14px; text-decoration: none; color: var(--muted); font-size: 14px;
    border: 1px solid transparent; border-bottom: none; border-radius: 8px 8px 0 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); background: var(--card); border-color: var(--line); font-weight: 600; }
.tab-count {
    display: inline-block; min-width: 18px; text-align: center; padding: 0 6px;
    background: #e2e8f0; color: #475569; border-radius: 999px; font-size: 12px; margin-left: 4px;
}
.tab-count.danger { background: #fee2e2; color: #991b1b; }

.assign-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px 14px; align-items: end; }
.assign-grid label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.assign-grid input, .assign-grid select, .assign-grid textarea {
    width: 100%; padding: 8px 10px; border: 1px solid var(--line);
    border-radius: 8px; font-size: 14px; background: #fff;
}
option.opt-no-driver { color: var(--amber); }
option.opt-has-driver { color: var(--green); }
/* Водитель, уже закреплённый за другой техникой. */
option.opt-busy { color: var(--amber); }
/* Карточка ремонта, заведённая из журнала и ждущая уточнения.
   Селектор с тегом — чтобы перебить более специфичный a.plain. */
.needs-details, a.needs-details { color: var(--amber); font-weight: 600; font-size: 13px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--muted); }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.legend .dot.busy { background: var(--amber); }
.legend .dot.free { background: var(--green); }
.item-block { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 18px; }
.item-block table { border: 1px solid var(--line); }

/* Широкие таблицы прокручиваются внутри себя, а не растягивают страницу. */
.table-wrap { overflow-x: auto; }

/* --- Календарь графика водителя --- */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 12px; }
.cal-head { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 0; }
.cal-day {
    position: relative; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 4px; min-height: 62px; padding: 8px 4px;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px;
    font: inherit; color: var(--text); cursor: pointer;
}
.cal-day:hover { border-color: var(--primary); }
.cal-day.out { opacity: 0.4; }
.cal-day.work { background: #dcfce7; border-color: #86efac; }
.cal-day.absent { background: #fef3c7; border-color: #fcd34d; }
.cal-day.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.cal-num { font-weight: 600; font-size: 15px; }
.cal-mark { font-size: 12px; color: var(--muted); }
.cal-manual { position: absolute; top: 3px; right: 7px; color: var(--primary); line-height: 1; }
