:root {
    --bg: #0f1419;
    --surface: #1a222c;
    --border: #2a3542;
    --text: #e7eef7;
    --muted: #9aabc0;
    --accent: #3d8bfd;
    --ok: #3ecf8e;
    --bad: #f07178;
    --warn: #e6b450;
    --font: "IBM Plex Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: radial-gradient(1200px 600px at 10% -10%, #1b2a40 0%, var(--bg) 55%);
    color: var(--text);
    min-height: 100vh;
}

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

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.9rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 20, 25, 0.85);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand { font-weight: 700; letter-spacing: 0.02em; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: var(--muted); }
.topbar nav a:hover { color: var(--text); text-decoration: none; }

.logout-form { margin: 0; }
.logout-form button,
button,
.btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.45rem 0.9rem;
    cursor: pointer;
}
a.btn {
    display: inline-block;
    color: var(--text);
    text-decoration: none;
}
a.btn:hover { text-decoration: none; color: var(--text); }
.btn-primary {
    background: var(--accent);
    border-color: transparent;
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.page-head h1 { margin-bottom: 0.2rem; }
.page-head .subtitle { margin-bottom: 0; }

.container { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }
.container-wide { max-width: none; width: 100%; padding-left: 1.25rem; padding-right: 1.25rem; }

h1 { margin: 0 0 0.35rem; font-size: 1.6rem; }
.subtitle { color: var(--muted); margin-bottom: 1.25rem; }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1.25rem;
}

.filters-row {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    width: 100%;
    margin-bottom: 1.25rem;
}
.filters-row .filters {
    margin-bottom: 0;
    flex: 1 1 auto;
    min-width: 0;
}
.filters-row .filters input[type="date"] {
    min-width: 9.25rem;
}
.filters-action {
    flex: 0 0 auto;
    white-space: nowrap;
    margin-left: auto;
}
.filters-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex: 0 0 auto;
    margin-left: auto;
}

label { display: grid; gap: 0.3rem; color: var(--muted); font-size: 0.85rem; }
input[type="date"],
input[type="text"],
input[type="password"],
input[type="number"] {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.5rem 0.7rem;
    min-width: 10rem;
}

.topup-amount {
    font-size: 1.55rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    text-align: right;
    min-width: 0;
    width: 100%;
    border: none;
    background: transparent;
    padding: 0.15rem 0 0.15rem 0.4rem;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
}

.kpi .label { color: var(--muted); font-size: 0.8rem; }
.kpi .value { font-size: 1.6rem; font-weight: 700; margin-top: 0.25rem; }
.kpi.ok .value { color: var(--ok); }
.kpi.bad .value { color: var(--bad); }
.kpi.warn .value { color: var(--warn); }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.panel-wide { width: 100%; }

.panel h2 { margin: 0 0 0.75rem; font-size: 1.05rem; }

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.logs-table {
    table-layout: fixed;
}

.logs-table .col-when { width: 11rem; white-space: nowrap; }
.logs-table .col-level { width: 6.5rem; }
.logs-table .col-client { width: 8rem; }
.logs-table .col-source { width: 14rem; word-break: break-word; }
.logs-table .log-message {
    word-break: break-word;
    white-space: pre-wrap;
    line-height: 1.4;
}
.logs-table .log-exception {
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--muted);
    white-space: pre-wrap;
    word-break: break-word;
}

th, td {
    text-align: left;
    padding: 0.55rem 0.4rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th { color: var(--muted); font-weight: 600; }
th.num, td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.sort-link {
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
}
.sort-link:hover { color: var(--text); text-decoration: none; }

.row-warning td { background: rgba(230, 180, 80, 0.12); }
.row-error td { background: rgba(240, 113, 120, 0.14); }
tr.row-warning:hover td { background: rgba(230, 180, 80, 0.18); }
tr.row-error:hover td { background: rgba(240, 113, 120, 0.2); }

.login-wrap {
    min-height: 80vh;
    display: grid;
    place-items: center;
}

.login-card {
    width: min(380px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.5rem;
}

.login-card h1 { margin-bottom: 1rem; }
.login-card .field { margin-bottom: 0.85rem; }
.login-card button { width: 100%; margin-top: 0.5rem; background: var(--accent); border-color: transparent; }
.error { color: var(--bad); margin-bottom: 0.75rem; font-size: 0.9rem; }
.muted { color: var(--muted); }
.chart-wrap { height: 300px; }

select {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.5rem 0.7rem;
    min-width: 10rem;
}

.status {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
}
.status-sent, .status-information { color: var(--ok); background: rgba(62, 207, 142, 0.12); }
.status-failed, .status-error, .status-fatal { color: var(--bad); background: rgba(240, 113, 120, 0.12); }
.status-process, .status-warning, .status-warn { color: var(--warn); background: rgba(230, 180, 80, 0.12); }
.status-unsent { color: var(--muted); background: rgba(154, 171, 192, 0.12); }
.msg-cell { max-width: 28rem; }

.pager {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.pager-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
}
.pager-size { margin: 0; }
.pager-size label { margin: 0; }
.btn-disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

dialog.modal {
    background: #151c25;
    color: var(--text);
    border: 1px solid #3a4a5c;
    border-radius: 16px;
    padding: 0;
    max-width: calc(100vw - 2rem);
    width: min(400px, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    overflow: auto;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}
dialog.modal.modal-wide {
    width: min(640px, calc(100vw - 2rem));
}
dialog.modal::backdrop {
    background: rgba(6, 10, 16, 0.7);
}
.modal-form {
    display: grid;
    gap: 1rem;
    padding: 1.15rem 1.25rem 1.25rem;
}
.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}
.modal-kicker {
    margin: 0 0 0.15rem;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}
.modal-form h2 { margin: 0; font-size: 1.25rem; }
.modal-close {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 8px;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--muted);
}
.modal-close:hover { color: var(--text); }
.amount-field { min-width: 0; }
.amount-input {
    display: flex;
    align-items: center;
    background: #0f1419;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.55rem 0.8rem;
}
.amount-prefix {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}
.modal-form input[type="text"],
.modal-form input[type="email"],
.modal-form input[type="number"],
.modal-form textarea {
    min-width: 0;
    width: 100%;
}
.modal-form textarea {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.5rem 0.7rem;
    resize: vertical;
    font: inherit;
}
.modal-form input:disabled,
.modal-form textarea:disabled {
    opacity: 0.75;
    cursor: not-allowed;
    color: var(--muted);
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
}
.form-grid .span-2 { grid-column: 1 / -1; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    padding-top: 0.25rem;
}
.modal-actions .btn-primary {
    min-width: 8.5rem;
}

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: auto; }
}
