/* === Design System === */
:root {
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-border-hover: #cbd5e1;
    --color-text: #1e293b;
    --color-text-secondary: #475569;
    --color-text-muted: #94a3b8;
    --color-primary: #6366f1;
    --color-primary-hover: #4f46e5;
    --color-primary-light: #eef2ff;
    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --color-danger-light: #fef2f2;
    --color-success: #22c55e;
    --color-success-light: #f0fdf4;
    --color-warning: #f59e0b;
    --color-warning-light: #fffbeb;
    --color-indigo-light: #eef2ff;
    --color-emerald-light: #ecfdf5;
    --color-amber-light: #fffbeb;
    --color-rose-light: #fff1f2;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.05);
    --transition: 150ms ease;
    --transition-slow: 250ms ease;
    --sidebar-width: 240px;
    --sidebar-collapsed: 64px;
}

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

html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
}

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

[x-cloak] { display: none !important; }

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transition: width var(--transition-slow);
}

.sidebar--collapsed { width: var(--sidebar-collapsed); }

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

.sidebar__logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
}

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

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

.sidebar__nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    text-decoration: none;
}

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

.sidebar__link--active {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.sidebar__link--active:hover {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.sidebar__link svg { flex-shrink: 0; }

.sidebar__footer {
    padding: 12px 8px;
    border-top: 1px solid var(--color-border);
}

.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    transition: margin-left var(--transition-slow);
    min-height: 100vh;
}

.main--expanded { margin-left: var(--sidebar-collapsed); }

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

/* === Typography === */
.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-header__left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: 0.8125rem; }
.mb-24 { margin-bottom: 24px; }
.link { color: var(--color-primary); }
.link:hover { text-decoration: underline; }

/* === Cards === */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 20px 24px;
    gap: 16px;
}

.card__title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-text);
    padding: 16px 24px 0;
}

.card__body { padding: 16px 24px 24px; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 20px;
}

.site-card { padding: 0; }
.site-card .card__header { border-bottom: 1px solid var(--color-border); }

/* === Stat Cards === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stats-grid--single { grid-template-columns: 220px; }

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.stat-card__icon--indigo { background: var(--color-indigo-light); color: var(--color-primary); }
.stat-card__icon--emerald { background: var(--color-emerald-light); color: #059669; }
.stat-card__icon--amber { background: var(--color-amber-light); color: #d97706; }
.stat-card__icon--rose { background: var(--color-rose-light); color: #e11d48; }

.stat-card__value {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.stat-card__label {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

/* === Charts === */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

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

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

.table td {
    padding: 14px 24px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

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

.table tbody tr:hover { background: #fafbfd; }

.table__actions-col { width: 160px; text-align: right; }
.table__num-col { width: 100px; text-align: right; }

.actions-cell {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.url-cell { max-width: 400px; }
.url-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.date-cell { white-space: nowrap; color: var(--color-text-muted); font-size: 0.8125rem; }

.slug {
    background: var(--color-primary-light);
    color: var(--color-primary);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 500;
}

.empty-state {
    text-align: center;
    padding: 48px 24px !important;
    color: var(--color-text-muted);
}

.empty-state-card {
    background: var(--color-surface);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    padding: 64px;
    text-align: center;
    color: var(--color-text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-family);
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    line-height: 1.4;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}
.btn--primary:hover:not(:disabled) { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }

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

.btn--danger-ghost {
    background: transparent;
    color: var(--color-danger);
    border-color: transparent;
}
.btn--danger-ghost:hover { background: var(--color-danger-light); }

.btn--sm { padding: 5px 10px; font-size: 0.8125rem; }
.btn--full { width: 100%; }

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

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

.form-hint { font-weight: 400; color: var(--color-text-muted); }

.form-hint-block {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: 16px;
    padding: 12px;
    background: var(--color-bg);
    border-radius: var(--radius);
}

.form-input {
    width: 100%;
    padding: 9px 12px;
    font-size: 0.875rem;
    font-family: var(--font-family);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-input:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.form-input::placeholder { color: var(--color-text-muted); }

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 8px center;
    background-repeat: no-repeat;
    background-size: 20px;
    padding-right: 32px;
}

.form-error {
    color: var(--color-danger);
    font-size: 0.8125rem;
    margin-bottom: 12px;
}

/* === Modals === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: 32px;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-xl);
}

.modal__title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 24px;
}

.modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 24px;
}

/* === Badges === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 100px;
}

.badge--success { background: var(--color-success-light); color: #15803d; }
.badge--warning { background: var(--color-warning-light); color: #92400e; }
.badge--indigo { background: var(--color-indigo-light); color: var(--color-primary); }
.badge--slate { background: var(--color-bg); color: var(--color-text-muted); }

/* === Upload Zone === */
.upload-zone {
    margin: 16px 24px 24px;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    color: var(--color-text-muted);
    transition: all var(--transition);
    cursor: default;
}

.upload-zone--active {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.upload-zone--uploading { border-style: solid; border-color: var(--color-primary); }

.upload-zone__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.upload-zone__icon { opacity: 0.5; }
.upload-zone__drop-text { font-weight: 600; color: var(--color-primary); }

/* === Spinner === */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

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

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    animation: slideIn 0.2s ease;
}

.toast--success { background: #15803d; color: white; }
.toast--error { background: var(--color-danger); color: white; }
.toast--info { background: var(--color-text); color: white; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

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

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-card__logo { margin-bottom: 24px; }

.login-card__title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.login-card__subtitle {
    color: var(--color-text-muted);
    font-size: 0.9375rem;
    margin-bottom: 32px;
}

.login-card .form-group { text-align: left; }
.login-card .btn { margin-top: 8px; }

/* === Responsive === */
@media (max-width: 1024px) {
    .sidebar { width: var(--sidebar-collapsed); }
    .sidebar .sidebar__logo { display: none; }
    .sidebar .sidebar__link span { display: none; }
    .main { margin-left: var(--sidebar-collapsed); }
    .container { padding: 24px 16px; }
    .charts-grid { grid-template-columns: 1fr; }
    .card-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .sidebar { display: none; }
    .main { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .table th, .table td { padding: 10px 12px; }
}
