/* ===== CSS Variables ===== */
:root {
    --bg: #0f1117;
    --sidebar-bg: #161923;
    --card-bg: #1c1f2e;
    --surface2: #252836;
    --border: #2d3148;
    --primary: #6366f1;
    --primary-hover: #5558e6;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #f59e0b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --sidebar-width: 240px;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-hover);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1.5rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand a {
    color: var(--text);
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sidebar-brand a:hover {
    color: var(--primary);
}

.sidebar-nav {
    padding: 0.75rem 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1.25rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.nav-link:hover {
    color: var(--text);
    background: rgba(99, 102, 241, 0.06);
}

.nav-link.active {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
    border-left-color: var(--primary);
}

.nav-link-logout {
    margin-top: auto;
    border-top: 1px solid var(--border);
}

.nav-link-logout:hover {
    color: var(--red);
    background: rgba(239, 68, 68, 0.06);
}

.nav-icon {
    font-size: 1.1rem;
    width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

/* ===== Sidebar Toggle & Overlay ===== */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 200;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.25rem;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.sidebar-toggle:hover {
    background: var(--surface2);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

/* ===== Main Content ===== */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 2rem 2.5rem;
    min-height: 100vh;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    letter-spacing: -0.02em;
}

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.card + .card {
    margin-top: 1rem;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

/* ===== Stats Cards ===== */
.stats-row,
.stats {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    flex: 1;
    min-width: 180px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border-left: 4px solid var(--border);
}

.stat-card .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.stat-card .value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-card.green {
    border-left-color: var(--green);
}

.stat-card.green .value {
    color: var(--green);
}

.stat-card.red {
    border-left-color: var(--red);
}

.stat-card.red .value {
    color: var(--red);
}

.stat-card.yellow {
    border-left-color: var(--yellow);
}

.stat-card.yellow .value {
    color: var(--yellow);
}

/* ===== Tables ===== */
.table-wrap {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.table-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    padding: 0.85rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 0.8rem 1rem;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:nth-child(even) {
    background: rgba(37, 40, 54, 0.4);
}

tbody tr:hover {
    background: rgba(99, 102, 241, 0.04);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="url"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.65rem 0.85rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

textarea {
    min-height: 100px;
    resize: vertical;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8.5L1 3.5h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #fff;
}

.btn-danger {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

.btn-outline {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

.btn-outline:hover:not(:disabled) {
    background: var(--surface2);
    border-color: var(--text-muted);
    color: var(--text);
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
    line-height: 1.4;
    background: var(--surface2);
    color: var(--text-muted);
}

.badge-green {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
}

.badge-red {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
}

.badge-yellow {
    background: rgba(245, 158, 11, 0.15);
    color: var(--yellow);
}

/* ===== Alerts ===== */
.alert {
    padding: 0.85rem 1.15rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 1.25rem;
    border: 1px solid;
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border-color: rgba(34, 197, 94, 0.25);
    color: var(--green);
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.25);
    color: var(--red);
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 1.25rem;
    padding: 0.75rem 1rem;
    justify-content: center;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.2rem;
    height: 2.2rem;
    padding: 0 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.pagination a:hover {
    background: var(--surface2);
    color: var(--text);
    border-color: var(--text-muted);
}

.pagination .active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.pagination .disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ===== Filters ===== */
.filters {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.filters .form-group {
    margin-bottom: 0;
}

.filters input,
.filters select {
    width: auto;
    min-width: 160px;
}

/* ===== URL Box ===== */
.url-box {
    width: 100%;
    padding: 0.65rem 0.85rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--primary);
    font-size: 0.85rem;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    outline: none;
    cursor: text;
    user-select: all;
}

.url-box:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* ===== Reason Text (Truncated) ===== */
.reason-text {
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: middle;
}

/* ===== Toggle Switch ===== */
.toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: all var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    left: 3px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition);
}

.toggle input:checked + .toggle-slider {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
    left: calc(100% - 19px);
    background: #fff;
}

.toggle input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* ===== Utility ===== */
.text-muted {
    color: var(--text-muted);
}

.text-green {
    color: var(--green);
}

.text-red {
    color: var(--red);
}

.text-yellow {
    color: var(--yellow);
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-sm {
    font-size: 0.85rem;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-3 {
    margin-top: 1.5rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-1 {
    gap: 0.5rem;
}

.gap-2 {
    gap: 1rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 0.95rem;
}

/* ===== Mobile Responsive ===== */

@media (max-width: 992px) {
    .main-content {
        padding: 2rem 1.5rem;
    }

    .stat-card {
        min-width: 140px;
    }

    .stat-card .value {
        font-size: 1.4rem;
    }
}

@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem 0.75rem;
        padding-top: 4rem;
    }

    .page-title {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }

    /* Stats */
    .stats-row,
    .stats {
        flex-direction: column;
    }

    .stat-card {
        min-width: 100%;
        padding: 1rem 1.15rem;
    }

    .stat-card .value {
        font-size: 1.5rem;
    }

    /* Filters */
    .filters {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .filters .form-group {
        margin-bottom: 0;
        width: 100%;
    }

    .filters input,
    .filters select {
        width: 100%;
        min-width: 0;
    }

    /* Tables */
    table {
        font-size: 0.8rem;
        min-width: 600px;
    }

    thead th,
    tbody td {
        padding: 0.5rem 0.5rem;
        white-space: nowrap;
    }

    .reason-text {
        max-width: 120px;
    }

    /* Cards */
    .card {
        padding: 1rem;
    }

    .table-wrap {
        border-radius: var(--radius-sm);
    }

    .table-header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }

    /* Modal */
    .modal {
        width: 96%;
        padding: 1.15rem;
        max-height: 90vh;
    }

    .modal-title {
        font-size: 1.05rem;
    }

    /* Detail rows */
    tr[id^="detail-"] td {
        padding: 0.5rem;
    }

    tr[id^="detail-"] pre {
        max-width: 100%;
        overflow-x: auto;
        white-space: pre-wrap;
        word-break: break-all;
        font-size: 0.75rem;
    }

    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .pagination a,
    .pagination span {
        min-width: 1.8rem;
        height: 1.8rem;
        font-size: 0.78rem;
    }

    /* Buttons */
    .btn {
        padding: 0.5rem 0.9rem;
        font-size: 0.85rem;
    }

    .btn-sm {
        padding: 0.3rem 0.55rem;
        font-size: 0.75rem;
    }

    .btn-group {
        flex-direction: column;
    }

    /* Settings cards */
    .table-wrap[style*="padding:24px"],
    .table-wrap[style*="padding: 24px"] {
        padding: 1rem !important;
    }

    /* URL box */
    .url-box {
        font-size: 0.78rem;
    }

    /* Alert */
    .alert {
        font-size: 0.85rem;
        padding: 0.7rem 0.9rem;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 0.75rem 0.5rem;
        padding-top: 3.5rem;
    }

    .page-title {
        font-size: 1.1rem;
    }

    .stat-card {
        padding: 0.85rem 1rem;
    }

    .stat-card .label {
        font-size: 0.7rem;
    }

    .stat-card .value {
        font-size: 1.25rem;
    }

    table {
        font-size: 0.75rem;
    }

    thead th,
    tbody td {
        padding: 0.4rem 0.35rem;
    }

    .badge {
        font-size: 0.65rem;
        padding: 0.15rem 0.4rem;
    }

    .filters input,
    .filters select {
        font-size: 0.85rem;
        padding: 0.55rem 0.7rem;
    }

    .form-group label {
        font-size: 0.78rem;
    }

    .modal {
        width: 98%;
        padding: 0.85rem;
        margin: 0.5rem;
    }
}
