/* SectorFlow SMTP Relay — Admin UI */

:root {
    /* Primary Colors */
    --sf-primary: #1A6FC4;
    --sf-primary-light: #2EA0E0;
    --sf-primary-dark: #0B1628;

    /* Neutral Colors */
    --sf-text: #3A4A5C;
    --sf-text-light: #6B7A8C;
    --sf-bg: #FFFFFF;
    --sf-bg-alt: #F2F4F7;
    --sf-border: #E1E5EB;

    /* State Colors */
    --sf-success: #10B981;
    --sf-warning: #F59E0B;
    --sf-error: #EF4444;

    /* Shadows */
    --sf-shadow-sm: 0 1px 2px rgba(11, 22, 40, 0.05);
    --sf-shadow-md: 0 4px 6px rgba(11, 22, 40, 0.07);
    --sf-shadow-lg: 0 10px 15px rgba(11, 22, 40, 0.1);

    /* Aliases for brevity */
    --primary: var(--sf-primary);
    --primary-light: var(--sf-primary-light);
    --dark: var(--sf-primary-dark);
    --text: var(--sf-text);
    --text-light: var(--sf-text-light);
    --bg: var(--sf-bg);
    --bg-alt: var(--sf-bg-alt);
    --border: var(--sf-border);
    --success: var(--sf-success);
    --warning: var(--sf-warning);
    --error: var(--sf-error);
    --success-bg: rgba(16, 185, 129, 0.1);
    --error-bg: rgba(239, 68, 68, 0.1);
    --warning-bg: rgba(245, 158, 11, 0.1);
    --radius: 8px;
    --shadow: var(--sf-shadow-sm);
    --shadow-md: var(--sf-shadow-md);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg-alt);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Typography ────────────────────────────────────────── */

h1 { font-size: 1.75rem; font-weight: 700; color: var(--primary); }
h2 { font-size: 1.5rem; font-weight: 600; color: var(--primary); }
h3 { font-size: 1.25rem; font-weight: 600; color: var(--primary); }
h4 { font-size: 1.125rem; font-weight: 500; color: var(--text); }

/* ── Layout ────────────────────────────────────────────── */

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.page-header p {
    color: var(--text-light);
    margin-top: 2px;
    font-size: 0.875rem;
}

/* ── Navbar ────────────────────────────────────────────── */

.navbar {
    background: var(--dark);
    color: #fff;
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
}

.navbar .container {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
}

.navbar-logo {
    height: 32px;
    width: auto;
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 40px;
    list-style: none;
}

.navbar-nav a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.15s, background 0.15s;
}

.navbar-nav a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.navbar-nav a.active {
    color: #fff;
    background: rgba(26, 111, 196, 0.5);
}

.navbar-end {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar-user {
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
}

.instance-badge {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.8);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    font-family: 'SF Mono', 'Consolas', monospace;
}

/* ── Content ───────────────────────────────────────────── */

.content {
    padding: 28px 24px;
}

.content .container {
    padding: 0;
}

/* ── Cards & Stats ─────────────────────────────────────── */

.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.stat-card .label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--dark);
    line-height: 1.2;
    margin-top: 4px;
}

.stat-card .sub {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 4px;
}

.stat-card.accent-primary { border-top: 3px solid var(--primary); }
.stat-card.accent-success { border-top: 3px solid var(--success); }
.stat-card.accent-warning { border-top: 3px solid var(--warning); }
.stat-card.accent-error   { border-top: 3px solid var(--error); }

/* ── Panel ─────────────────────────────────────────────── */

.panel {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 24px;
}

.panel-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--dark);
}

.panel-body {
    padding: 0;
}

.panel-body.padded {
    padding: 1.25rem;
}

/* ── Tables ────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
}

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

thead th {
    background: var(--primary);
    color: #FFFFFF;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem;
    text-align: left;
    white-space: nowrap;
}

thead th:first-child {
    border-radius: var(--radius) 0 0 0;
}

thead th:last-child {
    border-radius: 0 var(--radius) 0 0;
}

.panel thead th:first-child,
.panel thead th:last-child {
    border-radius: 0;
}

tbody td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

tbody tr:nth-child(even) {
    background: var(--bg-alt);
}

tbody tr:hover {
    background: rgba(26, 111, 196, 0.04);
}

td.numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 12px;
}

td.truncate {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

td.muted, .muted {
    color: var(--text-light);
}

/* ── Badges ────────────────────────────────────────────── */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}

.badge-success {
    background: var(--success-bg);
    color: #065F46;
}

.badge-error {
    background: var(--error-bg);
    color: #991B1B;
}

.badge-warning {
    background: var(--warning-bg);
    color: #92400E;
}

.badge-muted {
    background: var(--bg-alt);
    color: var(--text-light);
}

.badge-primary {
    background: rgba(26, 111, 196, 0.1);
    color: var(--primary);
}

/* ── Progress / Rate bar ───────────────────────────────── */

.rate-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rate-bar-track {
    width: 60px;
    height: 6px;
    background: var(--bg-alt);
    border-radius: 3px;
    overflow: hidden;
}

.rate-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--success);
    transition: width 0.3s;
}

.rate-bar-fill.low { background: var(--error); }
.rate-bar-fill.mid { background: var(--warning); }

.rate-bar-label {
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 36px;
}

/* ── Buttons ───────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0.625rem 1.25rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease;
    text-decoration: none;
    line-height: 1.4;
}

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

.btn-primary:hover {
    background: var(--primary-light);
    border-color: var(--primary-light);
}

.btn-secondary {
    background: var(--bg-alt);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--error);
    color: #fff;
}

.btn-danger:hover {
    background: #DC2626;
}

.btn-ghost {
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-ghost:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.4);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-icon {
    padding: 4px 6px;
    line-height: 1;
}

.btn-group {
    display: inline-flex;
    gap: 4px;
}

/* ── Alerts ────────────────────────────────────────────── */

.alert {
    padding: 0.875rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 16px;
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #065F46;
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #92400E;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #991B1B;
}

.alert-info {
    background: rgba(26, 111, 196, 0.1);
    border: 1px solid rgba(26, 111, 196, 0.3);
    color: #1E40AF;
}

/* ── Forms ──────────────────────────────────────────────── */

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 111, 196, 0.1);
}

.form-group input::placeholder {
    color: var(--text-light);
}

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

/* ── Toggle Switch ─────────────────────────────────────── */

.toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    cursor: pointer;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #CBD5E1;
    border-radius: 20px;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 2px;
    bottom: 2px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.toggle input:checked + .toggle-slider {
    background: var(--success);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

/* ── Filter Bar ────────────────────────────────────────── */

.filter-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-alt);
    border-radius: var(--radius) var(--radius) 0 0;
    flex-wrap: wrap;
}

.filter-bar .form-group {
    min-width: 140px;
}

.filter-bar .form-group label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-light);
}

.filter-bar .form-group select,
.filter-bar .form-group input {
    padding: 5px 8px;
    font-size: 12px;
}

/* ── Priority Arrows ───────────────────────────────────── */

.priority-controls {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.priority-controls button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-light);
    font-size: 10px;
    padding: 0 4px;
    line-height: 1.2;
    transition: color 0.15s;
}

.priority-controls button:hover {
    color: var(--primary);
}

/* ── Test Pattern Section ──────────────────────────────── */

.test-section {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.test-section .form-group {
    flex: 1;
}

.test-results {
    margin-top: 12px;
}

.test-results .match-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
}

.test-results .match-item.matched {
    background: var(--success-bg);
}

.test-results .match-item.not-matched {
    background: var(--bg-alt);
    color: var(--text-light);
}

.test-results .no-matches {
    color: var(--text-light);
    font-style: italic;
    padding: 8px 0;
}

/* ── Empty State ───────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

.empty-state p {
    margin-top: 4px;
    font-size: 13px;
}

/* ── Inline edit form ──────────────────────────────────── */

.edit-form-row td {
    padding: 12px 16px;
    background: rgba(26, 111, 196, 0.04);
}

.edit-form-row .form-row {
    margin-bottom: 12px;
}

/* ── Footer ────────────────────────────────────────────── */

.footer {
    text-align: center;
    padding: 20px;
    font-size: 0.75rem;
    color: var(--text-light);
}

/* ── Login Page ────────────────────────────────────────── */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: var(--sf-shadow-md);
    border: 1px solid var(--border);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.login-logo-img {
    height: 40px;
    width: auto;
}

.login-card h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 4px;
}

.login-card p {
    color: var(--text-light);
    font-size: 0.875rem;
    margin-bottom: 28px;
}

.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 0.625rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    margin-bottom: 12px;
}

.login-btn:hover {
    background: var(--bg-alt);
    border-color: #ccd1d9;
    box-shadow: var(--shadow);
}

.login-btn svg {
    flex-shrink: 0;
}

.login-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 4px 0 16px;
    color: var(--text-light);
    font-size: 12px;
}

.login-divider::before, .login-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── HTMX Transitions ─────────────────────────────────── */

.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-swapping {
    opacity: 0.6;
    transition: opacity 0.2s;
}

/* ── Confirm dialog ────────────────────────────────────── */

.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 22, 40, 0.45);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: confirmFadeIn 0.15s ease;
}

@keyframes confirmFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes confirmSlideIn {
    from { opacity: 0; transform: translateY(-12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.confirm-dialog {
    background: var(--bg);
    border-radius: 12px;
    padding: 28px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 40px rgba(11, 22, 40, 0.2), 0 0 0 1px rgba(11, 22, 40, 0.05);
    animation: confirmSlideIn 0.2s ease;
}

.confirm-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--error-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.confirm-icon::after {
    content: '!';
    font-size: 20px;
    font-weight: 700;
    color: var(--error);
    line-height: 1;
}

.confirm-dialog h3 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 8px;
}

.confirm-dialog p {
    color: var(--text-light);
    margin-bottom: 24px;
    font-size: 0.875rem;
    line-height: 1.55;
}

.confirm-dialog .form-actions {
    justify-content: flex-end;
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 900px) {
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar .form-group {
        min-width: auto;
    }
}

@media (max-width: 600px) {
    .stats-row {
        grid-template-columns: 1fr;
    }

    .navbar .container {
        flex-wrap: wrap;
        gap: 8px;
    }

    .navbar-nav {
        margin-left: 0;
    }

    .content {
        padding: 16px 12px;
    }
}
