/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-hover: #222633;
    --border: #2a2e3d;
    --text: #e4e6ed;
    --text-muted: #7a7f92;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --red: #ef4444;
    --red-bg: rgba(239,68,68,0.12);
    --green: #22c55e;
    --green-bg: rgba(34,197,94,0.12);
    --yellow: #eab308;
    --radius: 8px;
    --radius-sm: 4px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* === Login === */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-icon {
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

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

.form-group input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9375rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
}

.flash-messages { margin-bottom: 1rem; }
.flash { padding: 0.625rem; border-radius: var(--radius-sm); font-size: 0.875rem; }
.flash-error { background: var(--red-bg); color: var(--red); }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    color: var(--text);
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg-hover); border-color: var(--text-muted); }
.btn-sm { padding: 0.3125rem 0.625rem; font-size: 0.8125rem; }
.btn-full { width: 100%; justify-content: center; }

/* === App Layout === */
.app-layout {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1rem 1.5rem 3rem;
}

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

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-left .logo {
    font-size: 1.5rem;
    color: var(--primary);
}

.header-left h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.server-badge {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

/* === Stats === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}

.stat-active { border-color: var(--red); background: var(--red-bg); }

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-active .stat-value { color: var(--red); }

.stat-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* === Target Stats === */
.target-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.625rem;
    margin-bottom: 1.5rem;
}

.target-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.375rem 1rem;
    font-size: 0.8125rem;
}

.target-chip-active { border-color: var(--red); }

.target-ip {
    font-family: monospace;
    font-weight: 600;
}

.target-count { color: var(--text-muted); }

.target-active-badge {
    background: var(--red-bg);
    color: var(--red);
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* === Filters === */
.filters-bar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

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

.filter-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.filter-group select,
.filter-group input[type="date"] {
    padding: 0.375rem 0.625rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.8125rem;
    outline: none;
}

.filter-group select:focus,
.filter-group input[type="date"]:focus {
    border-color: var(--primary);
}

.filter-actions, .export-actions {
    display: flex;
    gap: 0.5rem;
}

/* === Table === */
.incidents-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.table-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

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

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

.incidents-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.incidents-table td {
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.incidents-table tbody tr:hover { background: var(--bg-hover); }

.row-active { background: var(--red-bg) !important; }

.cell-id { font-weight: 600; color: var(--text-muted); font-size: 0.8125rem; }
.cell-ip code {
    background: var(--bg);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
}
.cell-time { white-space: nowrap; font-size: 0.8125rem; }
.cell-loss { font-weight: 700; text-align: center; }

.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-active { background: var(--red-bg); color: var(--red); }
.badge-resolved { background: var(--green-bg); color: var(--green); }

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

/* === MTR Output === */
.mtr-row td { padding: 0 !important; background: var(--bg) !important; }

.mtr-output {
    padding: 1rem 1.25rem;
}

.mtr-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    font-size: 0.8125rem;
}

.mtr-output pre {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    font-size: 0.75rem;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 500px;
    overflow-y: auto;
}

/* === Pagination === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
}

.page-info {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 3rem;
    color: var(--green);
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.125rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

/* === Print === */
@media print {
    body { background: #fff; color: #000; }
    .app-header, .filters-bar, .btn-mtr, .export-actions,
    .pagination, .header-right, .target-stats { display: none !important; }
    .stat-card { border: 1px solid #ccc; }
    .incidents-table th { background: #eee; }
    .mtr-row { display: table-row !important; }
    .mtr-output pre { max-height: none; border: 1px solid #ccc; }
}

/* === Responsive === */
@media (max-width: 768px) {
    .app-layout { padding: 0.75rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .filters-bar { flex-direction: column; }
    .filters-form { flex-direction: column; width: 100%; }
    .filter-group { width: 100%; }
    .filter-group select,
    .filter-group input[type="date"] { width: 100%; }
    .incidents-table { font-size: 0.8125rem; }
    .incidents-table th, .incidents-table td { padding: 0.5rem; }
}
