/* ========== CSS Variables ========== */
:root {
    --bg-body: #0f1219;
    --bg-sidebar: #151922;
    --bg-card: #1a1f2e;
    --bg-input: #1e2435;
    --bg-hover: #242a3d;
    --bg-table-row: #1e2435;
    --border: #2a3042;
    --border-light: #343a52;
    --text-primary: #e4e8f1;
    --text-secondary: #8b95ad;
    --text-muted: #5f6880;
    --accent: #4a9eff;
    --accent-hover: #3a8eef;
    --accent-glow: rgba(74, 158, 255, 0.15);
    --green: #4CAF50;
    --green-bg: rgba(76, 175, 80, 0.12);
    --red: #ef5350;
    --red-bg: rgba(239, 83, 80, 0.12);
    --orange: #ff9800;
    --orange-bg: rgba(255, 152, 0, 0.12);
    --purple: #ab47bc;
    --purple-bg: rgba(171, 71, 188, 0.12);
    --blue-bg: rgba(74, 158, 255, 0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --transition: 0.2s ease;
    --sidebar-w: 220px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* ========== Layout ========== */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-logo {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
}

.nav-list {
    list-style: none;
    padding: 12px 8px;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: all var(--transition);
    font-size: 13.5px;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-glow);
    color: var(--accent);
}

.nav-link.active svg { stroke: var(--accent); }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.admin-name {
    font-size: 12px;
    color: var(--text-muted);
}

.logout-link {
    font-size: 12px;
    color: var(--red) !important;
}

.content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 28px 32px;
    min-width: 0;
}

/* ========== Page Header ========== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h2 {
    font-size: 22px;
    font-weight: 600;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-left: 12px;
}

/* ========== Cards ========== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    animation: fadeSlideUp 0.3s ease;
}

.card-header {
    padding: 14px 20px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-body {
    padding: 16px 20px;
}

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

.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon.blue { background: var(--blue-bg); color: var(--accent); }
.stat-icon.blue svg { stroke: var(--accent); }
.stat-icon.green { background: var(--green-bg); color: var(--green); }
.stat-icon.green svg { stroke: var(--green); }
.stat-icon.purple { background: var(--purple-bg); color: var(--purple); }
.stat-icon.purple svg { stroke: var(--purple); }
.stat-icon.orange { background: var(--orange-bg); color: var(--orange); }
.stat-icon.orange svg { stroke: var(--orange); }

.stat-value {
    font-size: 22px;
    font-weight: 700;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.cards-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 24px;
}

/* ========== Tables ========== */
.table-responsive {
    overflow-x: auto;
}

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

.table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

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

.table tbody tr {
    transition: background var(--transition);
}

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

.table-compact td,
.table-compact th {
    padding: 7px 12px;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 16px var(--accent-glow);
}

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

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

.btn-icon {
    background: none;
    border: none;
    padding: 6px;
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-icon.btn-danger:hover {
    background: var(--red-bg);
    color: var(--red);
}

.actions {
    display: flex;
    gap: 2px;
}

/* ========== Badges & Chips ========== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}

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

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

.badge-dim {
    background: rgba(255,255,255,0.05);
    color: var(--text-muted);
}

.chip {
    display: inline-block;
    padding: 4px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
}

.chip-sm { padding: 2px 8px; font-size: 11px; }

.user-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ========== Forms ========== */
.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.field input,
.field textarea,
.field select {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.filters {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.filters select,
.filters input[type="text"],
.filters input[type="date"] {
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 12px;
    font-family: var(--font);
    outline: none;
}

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

/* ========== Input with button ========== */
.input-with-btn {
    display: flex;
    align-items: stretch;
}

.input-with-btn input {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
    flex: 1 1 auto;
    width: 0;
    min-width: 0;
}

.btn-input-action {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-input-action:hover {
    background: var(--accent-glow);
    color: var(--accent);
}

/* ========== Modals ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.modal-overlay.show {
    opacity: 1;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 420px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px) scale(0.95);
    transition: transform 0.25s ease;
}

.modal-overlay.show .modal {
    transform: translateY(0) scale(1);
}

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

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

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color var(--transition);
}

.modal-close:hover { color: var(--text-primary); }

.modal form { padding: 20px; }

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

/* ========== Pagination ========== */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 20px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.page-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.page-link.active {
    background: var(--accent);
    color: #fff;
}

/* ========== Tabs ========== */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}

.tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-bottom: none;
    transition: all var(--transition);
    text-decoration: none;
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tab.active {
    color: var(--accent);
    background: var(--bg-card);
    border-color: var(--border);
}

.tab svg { stroke: currentColor; }

/* ========== Visit title ========== */
.visit-title {
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: default;
}

/* ========== Alerts ========== */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

.alert-error {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid rgba(239, 83, 80, 0.25);
}

/* ========== Toast ========== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    color: var(--text-primary);
    min-width: 280px;
    max-width: 400px;
    animation: toastIn 0.35s ease;
    transition: all 0.3s ease;
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

.toast-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
}

.toast-success .toast-icon { background: var(--green-bg); color: var(--green); }
.toast-error .toast-icon { background: var(--red-bg); color: var(--red); }
.toast-info .toast-icon { background: var(--blue-bg); color: var(--accent); }

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    border-radius: 0 0 var(--radius) var(--radius);
    animation: toastProgress 3s linear forwards;
}

.toast-success .toast-progress { background: var(--green); }
.toast-error .toast-progress { background: var(--red); }
.toast-info .toast-progress { background: var(--accent); }

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

.login-container {
    width: 360px;
    max-width: 90vw;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
    animation: fadeSlideUp 0.4s ease;
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo h1 {
    font-size: 20px;
    margin-top: 12px;
}

.login-logo p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.login-form .btn { margin-top: 8px; }

/* ========== Utilities ========== */
.text-muted { color: var(--text-muted); }
.text-mono { font-family: var(--font-mono); font-size: 12px; }
.text-nowrap { white-space: nowrap; }
.text-center { text-align: center; }

/* ========== Confirm Dialog ========== */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.confirm-overlay.show { opacity: 1; }

.confirm-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 380px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.2s ease;
}

.confirm-overlay.show .confirm-box { transform: scale(1); }

.confirm-box p {
    font-size: 14px;
    margin-bottom: 20px;
    color: var(--text-secondary);
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ========== Animations ========== */
@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

@keyframes toastProgress {
    from { width: 100%; }
    to { width: 0%; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
        overflow: hidden;
    }
    .sidebar-logo span,
    .nav-link span,
    .sidebar-footer .admin-name { display: none; }
    .sidebar-logo { justify-content: center; padding: 16px 8px; }
    .nav-link { justify-content: center; padding: 10px; }
    .sidebar-footer { justify-content: center; }
    .content { margin-left: 60px; padding: 16px; }
    .cards-row { grid-template-columns: 1fr; }
    .filters { flex-direction: column; align-items: stretch; }
}

/* ========== Settings Page ========== */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.settings-card .card-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.log-stats {
    margin-bottom: 16px;
}

.log-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.log-stat-row + .log-stat-row {
    border-top: 1px solid var(--border);
}

.settings-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-danger-text {
    color: var(--red) !important;
    border-color: rgba(239, 83, 80, 0.3) !important;
}

.btn-danger-text:hover {
    background: var(--red-bg) !important;
}

.field-row {
    display: flex;
    gap: 12px;
}

.field-row .field {
    flex: 1;
}

@media (max-width: 768px) {
    .settings-grid { grid-template-columns: 1fr; }
    .field-row { flex-direction: column; gap: 0; }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
