: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; }

.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(150px, 1fr)); gap: 12px; }
option.opt-no-driver { color: var(--amber); }
option.opt-has-driver { color: 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); }
