/* ═══════════════════════════════════════════════════
   Promo Tracker — Design System & Main Styles
   Light theme, print-friendly, professional
   ═══════════════════════════════════════════════════ */

:root {
    /* Colors */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --primary-50: #dbeafe;
    --secondary: #64748b;
    --success: #059669;
    --success-light: #ecfdf5;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #0891b2;
    --info-light: #ecfeff;

    /* Neutrals */
    --bg: #f0f2f5;
    --bg-card: #ffffff;
    --bg-sidebar: #1a1a2e;
    --bg-sidebar-hover: #252547;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --text-sidebar: #c7c7d4;
    --text-sidebar-active: #ffffff;
    --border: #e5e7eb;
    --border-light: #f3f4f6;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);

    /* Radius */
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    /* Spacing */
    --sidebar-width: 240px;
    --header-height: 60px;

    /* Transitions */
    --transition: 0.2s ease;

    /* Channel Colors */
    --color-gads: #4285f4;
    --color-meta-fb: #1877f2;
    --color-meta-insta: #e4405f;
    --color-meta-both: #7c3aed;
    --color-custom: #64748b;
}

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    padding: 1.2rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand i {
    font-size: 1.4rem;
    color: var(--primary);
    background: var(--primary-light);
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
}

.sidebar-brand span {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-sidebar-active);
    letter-spacing: -0.02em;
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    color: var(--text-sidebar);
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
    text-decoration: none;
}

.sidebar-nav a.active {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
    border-left-color: var(--primary);
}

.sidebar-nav a i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
    opacity: 0.7;
}

.sidebar-nav a.active i,
.sidebar-nav a:hover i { opacity: 1; }

.sidebar-nav .nav-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 0.5rem 1.25rem;
}

.sidebar-nav .nav-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.3);
    padding: 0.75rem 1.25rem 0.4rem;
}

.sidebar-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.06);
    font-size: 0.78rem;
}

.sidebar-footer .user-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.sidebar-footer .user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.sidebar-footer .user-name {
    font-weight: 600;
    color: var(--text-sidebar-active);
    font-size: 0.85rem;
}

.sidebar-footer .user-role {
    font-size: 0.7rem;
    color: var(--text-sidebar);
}

/* ─── Main Content ───────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
}

.top-bar {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.top-bar-left h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

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

.content-area {
    padding: 1.5rem;
}

/* ─── Client Selector ────────────────────────── */
.client-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.client-selector select {
    padding: 0.4rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    background: #fff;
    cursor: pointer;
    min-width: 180px;
    transition: border-color var(--transition);
}

.client-selector select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-50);
}

/* ─── Cards ──────────────────────────────────── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-light);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-light);
    background: var(--bg);
}

/* ─── KPI Cards ──────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: transform var(--transition), box-shadow var(--transition);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.kpi-icon.blue    { background: var(--primary-light); color: var(--primary); }
.kpi-icon.green   { background: var(--success-light); color: var(--success); }
.kpi-icon.orange  { background: var(--warning-light); color: var(--warning); }
.kpi-icon.red     { background: var(--danger-light);  color: var(--danger); }
.kpi-icon.cyan    { background: var(--info-light);    color: var(--info); }

.kpi-content { flex: 1; }

.kpi-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.3rem;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}

.kpi-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ─── Buttons ────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1rem;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

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

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

.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }

.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-ghost     { background: transparent; color: var(--text-secondary); padding: 0.4rem 0.6rem; }
.btn-ghost:hover { color: var(--primary); background: var(--primary-light); }

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

.btn-icon {
    width: 34px; height: 34px;
    padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
}

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

/* ─── Lang Toggle ────────────────────────────── */
.lang-toggle {
    display: flex;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.lang-toggle button {
    padding: 0.3rem 0.6rem;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.lang-toggle button.active {
    background: var(--primary);
    color: #fff;
}

.lang-toggle button:hover:not(.active) {
    background: var(--primary-light);
    color: var(--primary);
}

/* ─── Forms ──────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.35rem;
}

.form-group label .required {
    color: var(--danger);
    margin-left: 2px;
}

.form-control {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text);
    background: #fff;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-50);
}

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

select.form-control { cursor: pointer; }

textarea.form-control { resize: vertical; min-height: 80px; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-help {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ─── Modal ──────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s, visibility 0.25s;
}

.modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.25s;
}

.modal-backdrop.active .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

.modal-body { padding: 1.5rem; }

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    position: sticky;
    bottom: 0;
    background: var(--bg-card);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ─── Tables ─────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table thead th {
    padding: 0.7rem 0.8rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 0.65rem 0.8rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.data-table tbody tr:hover {
    background: var(--primary-light);
}

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

/* ─── Status Badge ───────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.73rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-draft      { background: #f3f4f6; color: #6b7280; }
.badge-active     { background: #ecfdf5; color: #059669; }
.badge-paused     { background: #fffbeb; color: #d97706; }
.badge-completed  { background: #eff6ff; color: #2563eb; }
.badge-archived   { background: #f3f4f6; color: #9ca3af; }

/* ─── Channel Tag ────────────────────────────── */
.channel-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 600;
    background: #f3f4f6;
    color: #374151;
}

.channel-tag.gads         { background: #e8f0fe; color: #1a73e8; }
.channel-tag.meta_fb      { background: #e7f3ff; color: #1877f2; }
.channel-tag.meta_insta   { background: #fce4ec; color: #e4405f; }
.channel-tag.meta_both    { background: #ede9fe; color: #7c3aed; }
.channel-tag.custom       { background: #f1f5f9; color: #475569; }

/* ─── Progress Bar ───────────────────────────── */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--border-light);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar .fill {
    height: 100%;
    border-radius: 999px;
    background: var(--primary);
    transition: width 0.6s ease;
}

.progress-bar .fill.green  { background: var(--success); }
.progress-bar .fill.orange { background: var(--warning); }
.progress-bar .fill.red    { background: var(--danger); }

/* ─── Hierarchy Tree ─────────────────────────── */
.tree-node {
    margin-left: 1.5rem;
    border-left: 2px solid var(--border);
    padding-left: 1rem;
}

.tree-node:first-child { margin-top: 0.75rem; }

.tree-item {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    transition: all var(--transition);
}

.tree-item:hover {
    border-color: var(--primary-50);
    box-shadow: var(--shadow-sm);
}

.tree-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

.tree-item-title {
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tree-item-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.tree-item .toggle-icon {
    transition: transform var(--transition);
}

.tree-item.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.tree-item.collapsed + .tree-node {
    display: none;
}

/* ─── Charts Grid ────────────────────────────── */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.chart-container {
    position: relative;
    height: 280px;
}

/* ─── Toast Notifications ────────────────────── */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: 0.88rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: 400px;
    animation: slideInRight 0.3s ease;
}

.toast-success { background: #059669; color: #fff; }
.toast-error   { background: #dc2626; color: #fff; }
.toast-warning { background: #d97706; color: #fff; }
.toast-info    { background: #2563eb; color: #fff; }

@keyframes slideInRight {
    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: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 2rem;
}

.login-card {
    background: #fff;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 0.5rem;
    color: var(--text);
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 2rem;
}

.login-card .login-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-card .login-logo i {
    font-size: 2.5rem;
    color: var(--primary);
    background: var(--primary-light);
    width: 64px; height: 64px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-lg);
}

.login-error {
    background: var(--danger-light);
    color: var(--danger);
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    display: none;
}

.login-error.visible { display: block; }

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

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}

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

.empty-state p {
    font-size: 0.88rem;
    margin-bottom: 1.5rem;
}

/* ─── Utility ────────────────────────────────── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* ─── Scrollbar ──────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0a0a0; }

/* ─── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .form-row { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
}

/* ─── Print Styles ───────────────────────────── */
@media print {
    .sidebar, .top-bar, .btn, .modal-backdrop, .toast-container { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    body { background: #fff; }
    .content-area { padding: 0; }
}
