/* ==========================================================================
   Fincers dashboard stylesheet
   Self-contained, no external CDN dependencies.
   ========================================================================== */

:root {
    --bg: #0f1420;
    --bg-soft: #161d2e;
    --surface: #1b2335;
    --surface-2: #212a40;
    --border: #2a3550;
    --text: #e7ebf4;
    --text-dim: #93a0bd;
    --accent: #5b8cff;
    --accent-soft: rgba(91, 140, 255, 0.14);
    --green: #34d399;
    --red: #f87171;
    --amber: #fbbf24;
    --blue: #60a5fa;
    --violet: #a78bfa;
    --radius: 12px;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

.layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --------------------------------------------------------- */
.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--bg-soft);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 20px;
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
}

.brand-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.2px;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-dim);
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-item:hover {
    background: var(--surface);
    color: var(--text);
}

.nav-item.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-footer {
    padding: 10px 8px 0;
    border-top: 1px solid var(--border);
}

.version {
    color: var(--text-dim);
    font-size: 12px;
}

/* --- Main area ------------------------------------------------------- */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 5;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content {
    padding: 24px 28px 40px;
    max-width: 1200px;
    width: 100%;
}

/* --- Cards & grids --------------------------------------------------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 22px;
}

.card-header {
    margin-bottom: 14px;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.card-sub {
    color: var(--text-dim);
    font-size: 13px;
    margin-top: 4px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 0;
}

.stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 12px;
    flex-shrink: 0;
}

.stat-icon svg {
    width: 22px;
    height: 22px;
}

.stat-icon-blue { background: rgba(96, 165, 250, 0.15); color: var(--blue); }
.stat-icon-green { background: rgba(52, 211, 153, 0.15); color: var(--green); }
.stat-icon-red { background: rgba(248, 113, 113, 0.15); color: var(--red); }
.stat-icon-amber { background: rgba(251, 191, 36, 0.15); color: var(--amber); }
.stat-icon-violet { background: rgba(167, 139, 250, 0.15); color: var(--violet); }
.stat-icon-gray { background: rgba(147, 160, 189, 0.16); color: var(--text-dim); }

.stat-value {
    font-size: 26px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    color: var(--text-dim);
    font-size: 13px;
}

/* --- Tables ---------------------------------------------------------- */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-dim);
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.table tr:last-child td {
    border-bottom: none;
}

.table .empty {
    color: var(--text-dim);
    text-align: center;
    padding: 24px 0;
}

/* --- Status badges --------------------------------------------------- */
.status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.status-valid, .status-completed { background: rgba(52, 211, 153, 0.16); color: var(--green); }
.status-invalid, .status-failed { background: rgba(248, 113, 113, 0.16); color: var(--red); }
.status-risky { background: rgba(167, 139, 250, 0.16); color: var(--violet); }
.status-running { background: rgba(96, 165, 250, 0.16); color: var(--blue, #60a5fa); }
.status-paused { background: rgba(96, 165, 250, 0.16); color: var(--blue, #60a5fa); }
.status-pending { background: rgba(251, 191, 36, 0.16); color: var(--amber); }
.status-unknown { background: rgba(147, 160, 189, 0.18); color: var(--text-dim); }
.status-cancelled { background: rgba(147, 160, 189, 0.18); color: var(--text-dim); }

.badge {
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-loading { background: var(--surface-2); color: var(--text-dim); }
.badge-ok { background: rgba(52, 211, 153, 0.16); color: var(--green); }
.badge-error { background: rgba(248, 113, 113, 0.16); color: var(--red); }

/* --- Forms & buttons ------------------------------------------------- */
.input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease;
}

.input:focus {
    border-color: var(--accent);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s ease, background 0.15s ease;
}

.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-danger {
    background: rgba(248, 113, 113, 0.14);
    color: var(--red);
}

.verify-form {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

.form-error {
    color: var(--red);
    font-size: 13px;
    margin-top: 8px;
}

.form-error.success { color: var(--green); }

.hidden { display: none; }

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.field-label {
    font-size: 13px;
    color: var(--text-dim);
}

.form-actions {
    margin-top: 8px;
}

.export-form {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 4px;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

.checkbox-label em {
    font-style: normal;
    color: var(--text-dim);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.page-info {
    font-size: 13px;
    color: var(--text-dim);
}

.smtp-log {
    margin-top: 10px;
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-dim);
    max-height: 220px;
    overflow: auto;
}

/* --- Verification result -------------------------------------------- */
#verify-result { margin-top: 4px; }

.result-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.result-email { font-weight: 600; font-size: 15px; }

.result-confidence { color: var(--text-dim); font-size: 13px; }

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.detail-card h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.detail-card p {
    font-size: 13px;
    word-break: break-word;
}

/* --- File upload ----------------------------------------------------- */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    color: var(--text-dim);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.drop-zone.dragging {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.drop-zone p {
    margin: 10px 0 14px;
}

.file-hint {
    font-size: 12px;
    color: var(--text-dim);
}

/* Upload progress bar on the import page */
.upload-progress {
    margin-top: 20px;
}

.progress-track {
    height: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 0.15s ease;
}

/* --- Import page: tabs + paste textarea ------------------------------ */
.import-tabs {
    display: flex;
    gap: 4px;
    margin: 4px 0 18px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    padding: 9px 16px;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    color: var(--accent);
    background: var(--surface-2);
    border-color: var(--border);
    font-weight: 600;
}

.paste-text {
    width: 100%;
    min-height: 180px;
    padding: 12px;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: vertical;
}

.paste-text:focus {
    outline: none;
    border-color: var(--accent);
}

/* Bigger console on the validation page */
.console-box-lg {
    height: 520px;
}

/* Idle status panel on the validation console */
.idle-panel {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    background: var(--accent-soft);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 13px;
    margin-bottom: 10px;
}

/* --- Topbar user info ------------------------------------------------ */
.user-chip {
    padding: 6px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

/* --- Login page ------------------------------------------------------ */
.login-body {
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-wrap {
    width: 100%;
    max-width: 380px;
    padding: 24px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.login-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-sub {
    color: var(--text-dim);
    font-size: 13px;
    margin-bottom: 20px;
}

.login-footer {
    text-align: center;
    color: var(--text-dim);
    font-size: 12px;
    margin-top: 16px;
}

/* --- User management ------------------------------------------------- */
.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.user-table td {
    vertical-align: middle;
}

.actions-cell {
    white-space: nowrap;
    display: flex;
    gap: 8px;
    align-items: center;
}

.key-table td {
    vertical-align: middle;
}

.key-cell {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    color: var(--text-dim);
}

.key-result-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 10px;
}

.key-result-code {
    flex: 1;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    word-break: break-all;
}

/* --- Modal ----------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 13, 20, 0.66);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 20;
}

/* Must outrank the generic `.hidden` utility (defined earlier). */
.modal-overlay.hidden {
    display: none;
}

.modal {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 700;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
}

.field-hint {
    font-size: 12px;
    color: var(--text-dim);
}

/* --- Bulk console & impersonation ------------------------------------- */
.impersonate-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--accent-soft);
    border-bottom: 1px solid var(--border);
    padding: 10px 24px;
    font-size: 13px;
    flex-wrap: wrap;
}

.impersonate-banner strong {
    color: var(--accent);
}

.console-box {
    background: #0a0e17;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-dim);
    height: 360px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin-top: 4px;
}

.console-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.api-key-card {
    margin-bottom: 20px;
}

/* --- Console log line colours ------------------------------------------- */
.log-line {
    display: block;
    white-space: pre-wrap;
}

.log-valid { color: var(--green); }
.log-invalid { color: var(--red); }
.log-risky { color: var(--amber); }
.log-unknown { color: #22d3ee; }
.log-system { color: var(--blue); }
.log-ok { color: var(--green); font-weight: 600; }
.log-warn { color: var(--amber); }
.log-muted { color: var(--text-dim); }

/* --- Filter bar & record details ---------------------------------------- */
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
}

.filter-bar .input {
    width: 260px;
}

.select-auto {
    width: auto;
}

.row-actions {
    white-space: nowrap;
}

.row-actions .btn {
    margin-right: 6px;
}

.btn-danger-ghost {
    background: transparent;
    border: 1px solid rgba(248, 113, 113, 0.4);
    color: var(--red);
}

.btn-danger-ghost:hover { background: rgba(248, 113, 113, 0.12); }

.expand-row > td {
    background: var(--bg-soft);
}

.record-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 6px 18px;
    font-size: 13px;
    color: var(--text-dim);
    padding-bottom: 8px;
}

.record-detail-grid strong {
    color: var(--text);
    font-weight: 600;
}

.smtp-log {
    background: #0a0e17;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-dim);
    max-height: 220px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 8px 0 0;
}

/* --- Responsive ------------------------------------------------------ */
@media (max-width: 820px) {
    .layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
        padding: 10px;
        gap: 6px;
    }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .nav-item { padding: 8px 10px; }
    .sidebar-footer { display: none; }
    .brand { padding: 4px 8px; }
    .content { padding: 18px 16px 32px; }
    .user-chip { display: none; }
}
