:root {
    --bg: #0f1420;
    --panel: #1a2132;
    --panel-2: #222b40;
    --border: #2c3650;
    --text: #e6ebf5;
    --muted: #8b95ad;
    --primary: #3b82f6;
    --primary-hover: #2f6fd6;
    --danger: #ef4444;
    --green: #22c55e;
    --amber: #f59e0b;
    --gray: #64748b;
}

* { box-sizing: border-box; }

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

/* ----------------------------- Buttons ----------------------------- */
.btn {
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background .15s, border-color .15s;
}
.btn:hover { background: #2a3552; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; }

.icon-btn {
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    width: 30px;
    height: 30px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: #2a3552; }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.icon-btn.danger:hover:not(:disabled) { background: #3a1f24; border-color: var(--danger); }

/* ----------------------------- Topbar ----------------------------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.logo {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 1px;
}
.logo span { color: var(--primary); }
.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
.current-user {
    color: var(--muted);
    margin-right: 8px;
    font-weight: 600;
}

/* ----------------------------- Filters ----------------------------- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.filter { display: flex; flex-direction: column; gap: 4px; }
.filter > label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.filter-row { display: flex; gap: 6px; }
.filter-actions { justify-content: flex-end; }
.filter input, .filter select,
.modal input, .modal select, .modal textarea {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 7px;
    padding: 7px 9px;
    font-size: 13px;
    outline: none;
}
.filter input { width: 130px; }
.filter input[type=number] { width: 110px; }
.filter select { width: 140px; }
.filter-row select { width: 60px; }
/* Period filter: year stays compact, month is wide enough for the longest
   month name ("Сентябрь"). */
#f-year { width: 78px; }
#f-month { width: 116px; }
.filter input:focus, .filter select:focus { border-color: var(--primary); }

/* ----------------------------- Table ----------------------------- */
main { padding: 18px 20px; }
.orders-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border-radius: 10px;
    overflow: hidden;
}
.orders-table th, .orders-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.orders-table th {
    background: var(--panel-2);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
}
.orders-table tr:hover td { background: rgba(255,255,255,.02); }
.nowrap { white-space: nowrap; }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.st-active { background: rgba(34,197,94,.15); color: var(--green); }
.st-paused { background: rgba(245,158,11,.15); color: var(--amber); }
.st-done { background: rgba(100,116,139,.2); color: var(--gray); }

.comment-cell, .actions-cell, .chart-cell { display: flex; align-items: center; gap: 6px; }
.comment-bang {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: var(--amber);
    color: #1a1a1a;
    font-weight: 800;
    cursor: help;
}
.comment-bang.muted { background: var(--gray); color: #ddd; }

.chart-cell { min-width: 120px; }
.bar {
    flex: 1;
    height: 8px;
    background: var(--panel-2);
    border-radius: 999px;
    overflow: hidden;
}
.bar-fill { height: 100%; background: var(--primary); transition: width .4s ease; }
.bar-label { font-size: 12px; color: var(--muted); min-width: 34px; text-align: right; }

.pace-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: help;
}
.pace-uniform { background: var(--green); }
.pace-accelerated { background: var(--danger); }

.empty-state { padding: 30px; text-align: center; color: var(--muted); }

/* ----------------------------- Modals ----------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 22px;
    width: 460px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.modal input, .modal select, .modal textarea { width: 100%; color: var(--text); }
.modal textarea { resize: vertical; font-family: inherit; }
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.with-hint { position: relative; }
.hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--gray);
    color: #fff;
    font-size: 11px;
    cursor: help;
    margin-left: 6px;
}
.form-error { color: var(--danger); font-size: 13px; min-height: 16px; }

/* ----------------------------- Login ----------------------------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 32px;
    width: 340px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.login-logo { font-size: 30px; font-weight: 800; text-align: center; letter-spacing: 1px; }
.login-logo span { color: var(--primary); }
.login-card h1 { font-size: 18px; text-align: center; margin: 0 0 6px; font-weight: 600; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 10px;
    font-size: 14px;
}

/* ----------------------------- Toast ----------------------------- */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--green);
    color: #06210f;
    padding: 12px 18px;
    border-radius: 10px;
    font-weight: 600;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast-error { background: var(--danger); color: #2a0a0a; }
