:root {
    --bg: #000000;
    --bg-soft: rgba(28, 28, 30, 0.72);
    --surface: rgba(30, 30, 32, 0.65);
    --surface-border: rgba(255, 255, 255, 0.1);
    --text: #f5f5f7;
    --muted: #86868b;
    --primary: #007aff;
    --primary-strong: #005bb5;
    --danger: #ff3b30;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --radius: 16px;
}

html[data-theme="light"] {
    --bg: #f5f5f7;
    --surface: rgba(255, 255, 255, 0.75);
    --surface-border: rgba(0, 0, 0, 0.08);
    --text: #1d1d1f;
    --muted: #86868b;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background-color: var(--bg);
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

/* SHELL & SIDEBAR */
.app-shell { display: flex; min-height: 100vh; overflow: hidden; position: relative; }

.sidebar {
    width: 260px;
    padding: 24px 16px;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: var(--surface);
    border-right: 1px solid var(--surface-border);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.brand { margin-bottom: 32px; padding: 0 12px; }
.logo { max-width: 150px; height: auto; }
html[data-theme="dark"] .logo-light, html[data-theme="light"] .logo-dark { display: none; }

.nav-links { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: var(--text); transition: all 0.2s ease; font-size: 14px; font-weight: 500;
}
.nav-link:hover { background: rgba(134, 134, 139, 0.1); }
.nav-link.is-active { background: var(--primary); color: #fff; }
.nav-link.is-active i { color: #fff; }

/* MAIN CONTENT */
.main-shell {
    flex: 1; padding: 24px; margin-left: 260px;
    transition: margin-left 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    width: calc(100% - 260px);
}

/* TOPBAR */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 32px;
}
.menu-toggle {
    display: none; width: 40px; height: 40px; border-radius: 10px; border: 0;
    background: transparent; color: var(--text); font-size: 20px; cursor: pointer;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }

.topbar h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.1em; font-size: 11px; font-weight: 700; color: var(--muted); margin: 0 0 4px; }

.topbar-actions { display: flex; align-items: center; gap: 16px; }

.theme-toggle {
    width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--surface-border);
    color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* USER PROFILE DROPDOWN */
.user-profile-wrapper { position: relative; }
.user-chip {
    display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 6px;
    border-radius: 20px; background: rgba(134, 134, 139, 0.08); border: 1px solid var(--surface-border);
    cursor: pointer; transition: background 0.2s;
}
.user-chip:hover { background: rgba(134, 134, 139, 0.15); }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), #00c6ff);
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.user-chip strong { font-size: 13px; font-weight: 600; }
.user-chip span { display: none; }

.dropdown-menu {
    position: absolute; top: calc(100% + 8px); right: 0; width: 220px;
    background: var(--surface); border: 1px solid var(--surface-border);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-radius: 14px; box-shadow: var(--shadow);
    padding: 8px; opacity: 0; pointer-events: none; transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1); z-index: 200;
}
.user-profile-wrapper.open .dropdown-menu { opacity: 1; pointer-events: auto; transform: translateY(0); }
.dropdown-menu .user-info { padding: 12px 8px; border-bottom: 1px solid var(--surface-border); margin-bottom: 8px; }
.dropdown-menu .user-info strong { display: block; font-size: 14px; }
.dropdown-menu .user-info span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.dropdown-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; width: 100%; border: 0;
    background: transparent; color: var(--text); border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; text-align: left;
}
.dropdown-item:hover { background: rgba(134, 134, 139, 0.1); }
.dropdown-item.danger:hover { background: rgba(255, 59, 48, 0.1); color: var(--danger); }

/* CARDS */
.stat-card, .content-card, .auth-panel, .modal-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
}
.hero-card {
    background: linear-gradient(135deg, var(--primary) 0%, #00c6ff 100%);
    color: #fff; padding: 32px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: space-between; overflow: hidden; position: relative;
}
.hero-card p { color: rgba(255, 255, 255, 0.8); }

.page-container, .page-grid, .stats-grid { display: grid; gap: 24px; }
.page-grid.two-columns { grid-template-columns: 350px 1fr; }
.stats-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.stat-card { padding: 24px; display: grid; gap: 8px; place-content: center; text-align: center; }
.stat-card strong { font-size: 36px; font-weight: 700; letter-spacing: -1px; }
.stat-card span { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.content-card { padding: 24px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; border-bottom: 1px solid var(--surface-border); padding-bottom: 16px; }

/* BUTTONS */
.primary-button, .ghost-button {
    padding: 12px 20px; border-radius: 12px; font-weight: 600; font-size: 14px;
    border: 0; cursor: pointer; transition: transform 0.1s, filter 0.2s;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.primary-button { background: var(--primary); color: #fff; }
.primary-button:hover { filter: brightness(1.1); transform: scale(0.98); }
.primary-button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.ghost-button { background: rgba(134, 134, 139, 0.1); color: var(--text); border: 1px solid transparent; }
.ghost-button:hover { background: rgba(134, 134, 139, 0.15); border-color: var(--surface-border); }

/* FORMS */
.panel-form { display: grid; gap: 20px; }
.panel-form label { display: grid; gap: 6px; }
.panel-form span { font-size: 13px; color: var(--text); font-weight: 600; }
.panel-form small { color: var(--muted); font-size: 12px; }
input, textarea, select {
    width: 100%; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--surface-border);
    background: rgba(134, 134, 139, 0.05); color: var(--text); outline: none; transition: all 0.2s;
    font-size: 14px;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--primary); background: rgba(134, 134, 139, 0.1);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

/* VALIDATION */
.input-error { border-color: var(--danger) !important; background: rgba(255, 59, 48, 0.05) !important; }
.error-message { color: var(--danger); font-size: 12px; font-weight: 500; margin-top: 4px; animation: slideDown 0.2s ease; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.checkbox-row { grid-template-columns: auto 1fr; align-items: center; }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--primary); }

/* TABLES */
.table-wrapper { overflow-x: auto; margin: -24px; padding: 24px; }
.data-table { width: 100%; border-collapse: collapse; min-width: 600px; }
.data-table th, .data-table td { padding: 16px; text-align: left; border-bottom: 1px solid var(--surface-border); }
.data-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; border-bottom: 2px solid var(--surface-border); }
.data-table tr:hover td { background: rgba(134, 134, 139, 0.05); }
.data-table tfoot td { font-weight: 700; color: var(--text); }

/* CREATIVES */
.creative-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.creative-card {
    border-radius: 16px; border: 1px solid var(--surface-border); background: var(--surface); display: flex; flex-direction: column; overflow: hidden; transition: transform 0.2s;
}
.creative-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.creative-thumb { height: 180px; background-size: cover; background-position: center; position: relative; }
.creative-thumb .btn-upload { position: absolute; inset: 0; background: rgba(0,0,0,0.5); color: #fff; display:flex; align-items:center; justify-content:center; opacity:0; transition: opacity 0.2s; cursor: pointer; border: 0; }
.creative-card:hover .btn-upload { opacity: 1; }
.creative-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.creative-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.creative-head strong { font-size: 16px; font-weight: 600; line-height: 1.3; }
.pill { padding: 4px 10px; border-radius: 8px; background: rgba(0, 122, 255, 0.1); color: var(--primary); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.creative-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 16px; border-top: 1px solid var(--surface-border); }
.creative-actions .ghost-button { padding: 8px 12px; font-size: 12px; border-radius: 8px; flex: 1; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden; }
.auth-panel { width: min(100%, 420px); padding: 40px 32px; display: grid; gap: 24px; border-radius: 20px; z-index: 10; text-align: center; }

/* MODALS */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(10px);
    display: grid; place-items: center; padding: 18px; z-index: 300;
}
.modal-card { width: min(100%, 500px); border-radius: 20px; padding: 32px; position: relative; animation: modalPop 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); }
@keyframes modalPop { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-close { position: absolute; right: 20px; top: 20px; width: 32px; height: 32px; border-radius: 50%; background: rgba(134,134,139,0.1); border: 0; color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* LOADING BAR */
.upload-progress-container { margin-top: 12px; display: none; }
.upload-progress-container.active { display: block; }
.upload-bar { width: 100%; height: 6px; background: rgba(134, 134, 139, 0.2); border-radius: 4px; overflow: hidden; margin-bottom: 6px; }
.upload-fill { height: 100%; background: var(--primary); width: 0%; transition: width 0.1s linear; }
.upload-text { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); font-weight: 600; }

/* INSIGHTS & REPORTS */
.insights-filters { margin-bottom: 24px; }
.filter-row {
    display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end;
    background: var(--surface); border: 1px solid var(--surface-border);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.filter-item { display: grid; gap: 6px; min-width: 160px; flex: 1; }
.filter-item span { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.insights-summary {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.insight-card.fb { border-left: 3px solid #1877F2; }
.insight-card.ig { border-left: 3px solid #c13584; }

.insights-pages {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.insight-page-card { transition: transform 0.2s; }
.insight-page-card:hover { transform: translateY(-2px); }

.insight-page-header {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--surface-border);
}
.insight-page-header strong { font-size: 16px; }

.insight-platform-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 20px;
    font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.insight-platform-badge.facebook { background: rgba(24, 119, 242, 0.1); color: #1877F2; }
.insight-platform-badge.instagram { background: rgba(193, 53, 132, 0.1); color: #c13584; }

.insight-metrics-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
}
.insight-metrics-grid div { text-align: center; }
.insight-metrics-grid span { display: block; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; }
.insight-metrics-grid strong { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }

.chart-container {
    position: relative; width: 100%; min-height: 300px;
}

.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 64px 20px; text-align: center; gap: 16px;
    background: var(--surface); border: 1px dashed var(--surface-border);
    border-radius: var(--radius); color: var(--muted);
}
.empty-state p { font-size: 14px; max-width: 400px; }

/* Checkbox list for schedule modal */
.page-check-list { display: grid; gap: 8px; max-height: 200px; overflow-y: auto; }
.page-check-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border-radius: 10px; background: rgba(134, 134, 139, 0.05);
    border: 1px solid var(--surface-border); cursor: pointer; transition: background 0.2s;
}
.page-check-item:hover { background: rgba(134, 134, 139, 0.1); }
.page-check-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }
.page-check-item .platform-tag {
    font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 2px 8px;
    border-radius: 4px; letter-spacing: 0.04em;
}
.page-check-item .platform-tag.facebook { background: rgba(24, 119, 242, 0.1); color: #1877F2; }
.page-check-item .platform-tag.instagram { background: rgba(193, 53, 132, 0.1); color: #c13584; }

/* Spinner animation */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; display: inline-block; }

/* RESPONSIVE */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 90; backdrop-filter: blur(4px); opacity: 0; transition: opacity 0.3s; }
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { display: block; pointer-events: none; }
    .main-shell { margin-left: 0; width: 100%; padding: 16px; }
    .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .page-grid.two-columns { grid-template-columns: 1fr; }
    .insight-metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .insights-pages { grid-template-columns: 1fr; }
    .filter-row { flex-direction: column; }
    .filter-item { min-width: 100%; }
}

@media (max-width: 640px) {
    .hero-card { flex-direction: column; align-items: flex-start; gap: 20px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .creative-board { grid-template-columns: 1fr; }
    .insights-summary { grid-template-columns: repeat(2, 1fr); }
}
