/* ============================================
   MagnetRaffic Design System
   Shared CSS variables, utilities, components
   ============================================ */

/* --- CSS Variables (Theme) --- */
:root {
    /* Backgrounds */
    --bg-base: #0f172a;
    --bg-card: #1e293b;
    --bg-elevated: #334155;
    --bg-input: #0f172a;

    /* Text */
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Borders */
    --border: #334155;
    --border-light: #1e293b;

    /* Accents */
    --blue: #3b82f6;
    --blue-hover: #2563eb;
    --blue-bg: #3b82f622;
    --purple: #8b5cf6;
    --purple-hover: #7c3aed;
    --purple-bg: #8b5cf622;
    --green: #22c55e;
    --green-dark: #16a34a;
    --green-bg: #16a34a22;
    --red: #ef4444;
    --red-bg: #ef444422;
    --yellow: #eab308;
    --yellow-bg: #eab30822;
    --orange: #f97316;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 20px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 20px;
    --space-2xl: 30px;

    /* Fonts */
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0,0,0,.15);
    --shadow-md: 0 4px 20px rgba(0,0,0,.25);
    --shadow-lg: 0 8px 40px rgba(0,0,0,.35);
    --shadow-xl: 0 20px 60px rgba(0,0,0,.5);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
}

/* --- Base Reset --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font-sans); background: var(--bg-base); color: var(--text-primary); line-height: 1.5; -webkit-font-smoothing: antialiased; }

/* --- Utility Classes --- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-start { display: flex; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

/* Text utilities */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-blue { color: var(--blue); }
.text-green { color: var(--green); }
.text-purple { color: var(--purple); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uppercase { text-transform: uppercase; letter-spacing: 0.5px; }

/* Spacing utilities */
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.p-xl { padding: var(--space-xl); }

/* --- Component: Card --- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
}
.card-sm {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
}
.card-inner {
    background: var(--bg-base);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}
.card-gradient {
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-base) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
}

/* --- Component: Badge --- */
.badge { padding: 4px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600; display: inline-block; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-gray { background: var(--bg-elevated); color: var(--text-muted); }

/* --- Component: Button --- */
.btn {
    padding: 8px 16px; border: none; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px; font-weight: 600;
    transition: transform var(--transition-fast), opacity var(--transition-fast), box-shadow var(--transition-fast);
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-purple { background: var(--purple); color: #fff; }
.btn-gray { background: var(--bg-elevated); color: var(--text-secondary); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--text-muted); color: var(--text-primary); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon { padding: 6px 8px; min-width: 32px; }
.btn-group { display: flex; gap: 6px; }

/* --- Component: Table --- */
table { width: 100%; border-collapse: collapse; background: var(--bg-card); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: var(--space-xl); }
thead th { background: var(--bg-elevated); padding: 12px 15px; text-align: left; font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; white-space: nowrap; }
tbody td { padding: 12px 15px; border-bottom: 1px solid var(--bg-base); font-size: 14px; }
tbody tr { transition: background var(--transition-fast); }
tbody tr:hover { background: var(--bg-elevated); }
tbody tr:last-child td { border-bottom: none; }

/* --- Component: Form Inputs --- */
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-md);
    background: var(--bg-input); color: var(--text-primary);
    font-size: 14px; font-family: var(--font-sans);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.form-input.error, .form-select.error { border-color: var(--red); box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15); }
.form-textarea { height: 80px; resize: vertical; }
.form-label { display: block; color: var(--text-secondary); font-size: 13px; margin-bottom: 4px; margin-top: 12px; font-weight: 500; }
.form-label .required { color: var(--red); margin-left: 2px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-error-msg { font-size: 12px; color: var(--red); margin-top: 4px; display: none; }
.form-group { margin-bottom: 12px; }

/* --- Component: Modal --- */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.7); z-index: 100;
    align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; }
.modal {
    background: var(--bg-card); padding: var(--space-2xl);
    border-radius: var(--radius-xl); width: 500px; max-width: 90vw;
    max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.2s ease-out;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal h2 { margin-bottom: var(--space-xl); color: var(--blue); font-size: 18px; }
.modal label { display: block; color: var(--text-secondary); font-size: 13px; margin-bottom: 4px; margin-top: 12px; font-weight: 500; }
.modal input, .modal select, .modal textarea {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-md);
    background: var(--bg-input); color: var(--text-primary); font-size: 14px;
    transition: border-color var(--transition-fast);
}
.modal input:focus, .modal select:focus, .modal textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }
.modal textarea { height: 80px; resize: vertical; }
.modal-actions { display: flex; gap: 10px; margin-top: var(--space-xl); }
.modal-actions button { flex: 1; }

/* --- Component: Confirm Dialog --- */
.confirm-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.7); z-index: 200;
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px); animation: modalIn 0.15s ease-out;
}
.confirm-box {
    background: var(--bg-card); padding: 24px; border-radius: var(--radius-xl);
    width: 400px; max-width: 90vw; box-shadow: var(--shadow-xl);
    text-align: center;
}
.confirm-box .confirm-icon { font-size: 36px; margin-bottom: 12px; }
.confirm-box h3 { color: var(--text-primary); margin-bottom: 8px; font-size: 16px; }
.confirm-box p { color: var(--text-secondary); font-size: 14px; margin-bottom: 20px; line-height: 1.5; }
.confirm-box .confirm-actions { display: flex; gap: 10px; }
.confirm-box .confirm-actions button { flex: 1; padding: 10px; border: none; border-radius: var(--radius-md); font-size: 14px; font-weight: 600; cursor: pointer; }

/* --- Component: Pagination --- */
.pagination {
    display: flex; align-items: center; justify-content: center;
    gap: 6px; padding: 16px 0;
}
.pagination button {
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-secondary); padding: 8px 14px; border-radius: var(--radius-md);
    font-size: 13px; cursor: pointer; transition: all var(--transition-fast);
}
.pagination button:hover:not(:disabled) { background: var(--bg-elevated); color: var(--text-primary); }
.pagination button.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }
.pagination .page-info { color: var(--text-muted); font-size: 13px; padding: 0 8px; }

/* --- Component: Empty State --- */
.empty-state { text-align: center; padding: 50px 20px; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3 { color: var(--text-primary); margin-bottom: 6px; font-size: 16px; font-weight: 600; }
.empty-state p { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }

/* --- Component: Stats Grid --- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 15px; margin-bottom: var(--space-2xl); }
.stat-card { background: var(--bg-card); padding: var(--space-xl); border-radius: var(--radius-lg); transition: transform 0.2s ease, box-shadow 0.2s ease; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card .label { color: var(--text-muted); font-size: 12px; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 1.8em; font-weight: 700; }
.stat-card .value.blue { color: var(--blue); }
.stat-card .value.green { color: var(--green); }
.stat-card .value.purple { color: var(--purple); }
.stat-card .value.yellow { color: var(--yellow); }
.stat-card .value.red { color: var(--red); }
.stat-card .change { font-size: 12px; margin-top: 4px; }
.stat-card .change.up { color: var(--green); }
.stat-card .change.down { color: var(--red); }

/* --- Component: Code Block --- */
.code-block {
    background: var(--bg-base); padding: 15px; border-radius: var(--radius-md);
    font-family: var(--font-mono); font-size: 12px; white-space: pre-wrap;
    word-break: break-all; color: var(--green); margin: 10px 0;
    max-height: 200px; overflow-y: auto; border: 1px solid var(--border);
}

/* --- Component: Status Dot --- */
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-dot.online { background: var(--green); }
.status-dot.pending { background: var(--yellow); }
.status-dot.offline { background: var(--red); }

/* --- Component: Tab Nav --- */
.tab-nav { display: flex; border-bottom: 1px solid var(--border); margin-bottom: var(--space-xl); gap: 0; }
.tab-nav button {
    padding: 10px 20px; background: none; border: none; border-bottom: 2px solid transparent;
    color: var(--text-muted); font-size: 14px; cursor: pointer; transition: all var(--transition-fast);
}
.tab-nav button:hover { color: var(--text-secondary); }
.tab-nav button.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

/* --- Component: Top Bar --- */
.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px; flex-wrap: wrap; gap: 10px; }
.top-bar h1 { font-size: 1.5em; font-weight: 700; }

/* --- Component: Filter Bar --- */
.filter-bar { display: flex; gap: 10px; margin-bottom: var(--space-lg); flex-wrap: wrap; align-items: center; }
.filter-bar select, .filter-bar input {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
    background: var(--bg-card); color: var(--text-primary); font-size: 13px;
}
.filter-bar select:focus, .filter-bar input:focus { outline: none; border-color: var(--blue); }

/* --- Component: Inline Tag --- */
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 500; }
.tag-blue { background: var(--blue-bg); color: var(--blue); }
.tag-green { background: var(--green-bg); color: var(--green); }
.tag-red { background: var(--red-bg); color: var(--red); }
.tag-purple { background: var(--purple-bg); color: var(--purple); }
.tag-yellow { background: var(--yellow-bg); color: var(--yellow); }

/* --- Skeleton Animation --- */
.skeleton-line {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 50%, var(--bg-card) 75%);
    background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: 4px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* --- Section Animation --- */
.section { display: none; animation: sectionIn 0.25s ease-out; }
.section.active { display: block; }
@keyframes sectionIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* --- Chart Container --- */
.chart-container { background: var(--bg-card); border-radius: var(--radius-lg); padding: var(--space-xl); margin-bottom: var(--space-2xl); max-height: 350px; }

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

/* --- Focus Visible (Accessibility) --- */
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* --- Responsive: Mobile First Helpers --- */
@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .modal { padding: var(--space-xl); width: 95vw; }
    .top-bar { flex-direction: column; align-items: flex-start; }
    .filter-bar { flex-direction: column; }
    .filter-bar select, .filter-bar input { width: 100%; }
    table { font-size: 13px; }
    thead th, tbody td { padding: 10px 12px; }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .btn-group { flex-direction: column; }
    .pagination { flex-wrap: wrap; }
}
