:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #101d4a;
    --primary-soft: #eef2ff;
    --yellow: #ffd200;
    --green-bg: #dcfce7;
    --green-text: #166534;
    --orange-bg: #ffedd5;
    --orange-text: #9a3412;
    --red-bg: #fee2e2;
    --red-text: #991b1b;
    --gray-bg: #f3f4f6;
    --gray-text: #4b5563;
    --shadow: 0 20px 50px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

a { color: inherit; text-decoration: none; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 24px 34px;
    background: linear-gradient(135deg, var(--primary), #1c2d68);
    color: white;
    box-shadow: var(--shadow);
}
.topbar h1 { margin: 0; font-size: 26px; }
.topbar p { margin: 6px 0 0; color: rgba(255,255,255,.75); }
.topbar nav { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.nav-link {
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255,255,255,.1);
    color: white;
    font-size: 14px;
}
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.2); }
.nav-link.danger { background: rgba(239,68,68,.2); }

.wrap { width: min(1480px, calc(100% - 40px)); margin: 28px auto; }
.wrap.narrow { width: min(980px, calc(100% - 40px)); }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(130px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    box-shadow: var(--shadow);
}
.stat-card span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.stat-card strong { font-size: 26px; }
.stat-card.warning { background: var(--orange-bg); color: var(--orange-text); }
.stat-card.urgent { background: var(--red-bg); color: var(--red-text); }
.stat-card.money { background: var(--primary-soft); }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 18px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.panel-head h2, .form-panel h2 { margin: 0; }
.panel-head span { color: var(--muted); }

.filters {
    display: grid;
    grid-template-columns: minmax(230px, 1fr) 170px 190px 170px auto auto;
    gap: 10px;
}
input, select, textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 13px;
    font: inherit;
    background: white;
    color: var(--text);
}
textarea { resize: vertical; }
label span { display: block; margin-bottom: 7px; font-weight: 700; font-size: 14px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
    background: var(--gray-bg);
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    white-space: nowrap;
}
.btn.primary { background: var(--primary); color: white; }
.btn.ghost { background: var(--primary-soft); color: var(--primary); }
.btn.danger { background: var(--red-bg); color: var(--red-text); }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.full { width: 100%; margin-top: 14px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1120px; }
th, td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
    font-size: 14px;
}
th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .05em;
    background: #fafafa;
}
tr:hover td { background: #fafafa; }
.note-cell { max-width: 260px; color: var(--muted); }
.actions { text-align: right; }
.muted { color: var(--muted); }

.status, .company-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}
.status.ok { background: var(--green-bg); color: var(--green-text); }
.status.soon { background: var(--orange-bg); color: var(--orange-text); }
.status.urgent, .status.expired { background: var(--red-bg); color: var(--red-text); }
.status.muted { background: var(--gray-bg); color: var(--gray-text); }
.company-pill { background: var(--primary-soft); color: var(--primary); }

.form-panel { display: grid; gap: 22px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 14px;
}
.check-row input { width: auto; }
.check-row span { margin: 0; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.alert {
    padding: 14px 16px;
    border-radius: 14px;
    margin-bottom: 16px;
    font-weight: 700;
}
.alert.error { background: var(--red-bg); color: var(--red-text); }
.alert.success { background: var(--green-bg); color: var(--green-text); }
.alert.info { background: var(--primary-soft); color: var(--primary); }

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #101d4a, #263d8c);
}
.login-card {
    width: min(420px, calc(100% - 32px));
    background: white;
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 30px 80px rgba(0,0,0,.22);
}
.login-card h1 { margin: 0 0 8px; }
.login-card p { margin: 0 0 18px; color: var(--muted); }

@media (max-width: 1100px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .topbar nav { justify-content: flex-start; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filters { grid-template-columns: 1fr 1fr; }
    .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
    .wrap { width: min(100% - 24px, 1480px); margin: 16px auto; }
    .topbar { padding: 20px; }
    .stats-grid, .filters { grid-template-columns: 1fr; }
}
