/* ==========================================================
   Ttrafik Ads OS — Mobile-First Design System
   Base styles target phones; larger screens are additive.
   ========================================================== */

:root {
    /* Brand theme */
    --primary: #05005B;
    --primary-light: #0A0A7A;
    --accent: #F5B42A;
    --accent-hover: #ffc34d;
    --bg: #F4F4F4;
    --card: #FFFFFF;
    --text: #1A1A1A;
    --text-muted: #6B6B7A;
    --border: #E2E2EA;
    --success: #1FA76A;
    --error: #E0453F;
    --warning: #E0A93F;

    /* Sidebar (kept dark for contrast against the light theme) */
    --sidebar-bg: var(--primary);
    --sidebar-text: rgba(255,255,255,0.75);
    --sidebar-text-active: #fff;
    --sidebar-active-bg: rgba(255,255,255,0.08);

    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 2px 10px rgba(5,5,91,0.06);
    --shadow-lg: 0 8px 30px rgba(5,5,91,0.18);

    --space-mobile: 16px;
    --space-tablet: 20px;
    --space-desktop: 28px;

    --font: 'Syne', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --sidebar-width-mobile: min(85vw, 320px);
    --sidebar-width-desktop: 280px;

    --topnav-height: 60px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 16px;
}

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

img { max-width: 100%; height: auto; display: block; }

/* ---------------- Typography (mobile-first, scales up) ---------------- */
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 16px; font-weight: 700; }
h2 { font-size: 18px; margin: 24px 0 12px; font-weight: 700; }
p, label, input, select, textarea, button { font-size: 16px; }

@media (min-width: 768px) {
    h1 { font-size: 28px; }
}
@media (min-width: 1024px) {
    h1 { font-size: 32px; }
}

/* ---------------- Focus visibility (accessibility) ---------------- */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* ==========================================================
   Auth / Onboarding pages
   ========================================================== */
.auth-page, .onboarding-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-mobile);
    background: var(--bg);
}

.auth-card, .onboarding-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    width: 100%;
    max-width: 440px;
}
.onboarding-card { max-width: 560px; }

@media (min-width: 480px) {
    .auth-card, .onboarding-card { padding: 32px; }
}

.subtitle { color: var(--text-muted); margin-top: -8px; margin-bottom: 20px; }

/* ==========================================================
   Forms — single column, large tap-friendly fields
   ========================================================== */
label { display: block; margin: 14px 0 6px; font-size: 14px; font-weight: 600; color: var(--text-muted); }

input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=url], input[type=number], input[type=date], input[type=file],
select, textarea {
    width: 100%;
    min-height: 50px;
    padding: 12px 14px;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 16px; /* prevents iOS auto-zoom on focus */
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
}
textarea { resize: vertical; min-height: 90px; }

.checkbox { display: flex; align-items: center; gap: 10px; font-size: 15px; min-height: 44px; }
.checkbox input { width: 20px; height: 20px; flex-shrink: 0; }

/* Two columns on wider screens for paired fields, still stacked on mobile */
.form-row { display: flex; flex-direction: column; }
@media (min-width: 600px) {
    .form-row-pair { display: flex; gap: 16px; }
    .form-row-pair > * { flex: 1; }
}

/* ==========================================================
   Buttons — min 48px height, generous tap area
   ========================================================== */
.btn-primary, .btn-secondary, .btn-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 20px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: inherit;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    margin-top: 14px;
    margin-right: 8px;
    transition: background-color 150ms ease, transform 150ms ease;
    text-decoration: none;
}
.btn-primary:active, .btn-secondary:active, .btn-small:active { transform: scale(0.98); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); color: #fff; }
.btn-secondary { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-small { min-height: 40px; padding: 0 14px; font-size: 13px; margin-top: 0; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--error); color: #fff; }
.btn-warning { background: var(--warning); color: #1A1A1A; }

/* Full-width primary buttons on small screens where it makes sense */
.btn-block { width: 100%; }
@media (max-width: 480px) {
    form > .btn-primary:last-child,
    .results-submit-btn { width: 100%; }
}

.alert { padding: 14px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.alert-error { background: rgba(224,69,63,0.1); border: 1px solid var(--error); color: #a7231e; }
.alert-success { background: rgba(31,167,106,0.1); border: 1px solid var(--success); color: #147a4c; }

.auth-links { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-muted); }

/* Onboarding steps */
.step-dots { display: flex; justify-content: center; gap: 8px; margin-bottom: 20px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--border); }
.dot.active { background: var(--accent); }
.radio-group { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.radio-group label { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 16px; font-weight: 400; min-height: 44px; margin: 0; }
.radio-group input { width: 20px; height: 20px; }

/* ==========================================================
   App Shell — top nav + off-canvas sidebar (mobile-first)
   ========================================================== */
.app-shell { min-height: 100vh; background: var(--bg); }

/* Top nav: sticky, always visible */
.topnav {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topnav-height);
    padding: 0 var(--space-mobile);
    background: var(--card);
    border-bottom: 1px solid var(--border);
}
.topnav-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topnav-title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 20px;
    color: var(--text);
}
.icon-btn:hover { background: var(--bg); }

.notif-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--error);
    border: 2px solid var(--card);
}

/* Hamburger — animates into an X */
.hamburger-btn {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
}
.hamburger-btn:hover { background: var(--bg); }
.hamburger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 300ms ease, opacity 200ms ease;
}
.hamburger-btn span + span { margin-top: 5px; }
.hamburger-btn[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger-btn[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.hamburger-btn[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Sidebar overlay (mobile off-canvas) */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5,5,91,0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 45;
    opacity: 0;
    pointer-events: none;
    transition: opacity 300ms ease;
}
.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width-mobile);
    background: var(--sidebar-bg);
    padding: 20px 16px;
    z-index: 50;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 300ms ease-in-out;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.sidebar.nav-open { transform: translateX(0); }

.sidebar-brand {
    font-weight: 700;
    margin-bottom: 24px;
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--sidebar-text-active);
}
.sidebar-brand small { color: var(--sidebar-text); font-weight: 400; }

.sidebar-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    color: var(--sidebar-text-active);
    font-size: 22px;
    cursor: pointer;
    border-radius: 50%;
}
.sidebar-close-btn:hover { background: rgba(255,255,255,0.08); }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
    display: flex;
    align-items: center;
    min-height: 48px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 600;
    font-size: 15px;
    border-left: 3px solid transparent;
}
.sidebar nav a.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
    border-left-color: var(--accent);
    font-weight: 700;
}
.sidebar nav a:hover { background: var(--sidebar-active-bg); color: var(--sidebar-text-active); }
.sidebar nav a.logout-link { margin-top: 20px; color: #ff9d99; }

.main-content {
    padding: var(--space-mobile);
    max-width: 1100px;
    min-width: 0;
    padding-bottom: calc(var(--space-mobile) + env(safe-area-inset-bottom));
}

/* ---- Desktop: permanent sidebar, no overlay/hamburger, no close button ---- */
@media (min-width: 1024px) {
    .app-shell { display: flex; }
    .topnav { display: none; }
    .hamburger-btn, .sidebar-close-btn, .sidebar-overlay { display: none !important; }
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        width: var(--sidebar-width-desktop);
        transform: none;
        flex-shrink: 0;
        padding: 24px 16px;
    }
    .main-content { flex: 1; padding: var(--space-desktop); }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .main-content { padding: var(--space-tablet); }
}

/* ==========================================================
   Notification drawer & profile bottom sheet
   ========================================================== */
.notif-drawer, .profile-sheet {
    position: fixed;
    z-index: 60;
    background: var(--card);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms ease, transform 250ms ease;
}
/* Mobile: slide-down drawer / bottom sheet */
.notif-drawer {
    top: var(--topnav-height);
    left: 0;
    right: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 16px;
    transform: translateY(-12px);
    max-height: 70vh;
    overflow-y: auto;
}
.notif-drawer.open { opacity: 1; pointer-events: auto; transform: translateY(0); }

.profile-sheet {
    left: 0; right: 0; bottom: 0;
    border-radius: 20px 20px 0 0;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
    transform: translateY(20px);
}
.profile-sheet.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
.profile-sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 4px; margin: 4px auto 14px; }
.profile-sheet a, .profile-sheet button {
    display: flex; align-items: center; width: 100%;
    min-height: 48px; padding: 0 8px; background: none; border: none;
    font-size: 16px; color: var(--text); text-align: left; cursor: pointer; border-radius: var(--radius-sm);
}
.profile-sheet a:hover, .profile-sheet button:hover { background: var(--bg); }

@media (min-width: 1024px) {
    .notif-drawer { top: 52px; right: 16px; left: auto; width: 320px; border-radius: var(--radius); }
    .profile-sheet {
        left: auto; right: 16px; bottom: auto; top: 52px;
        width: 220px; border-radius: var(--radius);
        transform: translateY(-8px);
    }
    .profile-sheet.open { transform: translateY(0); }
}

.notif-item { padding: 10px 4px; border-bottom: 1px solid var(--border); font-size: 14px; }
.notif-item:last-child { border-bottom: none; }
.notif-empty { color: var(--text-muted); font-size: 14px; padding: 12px 4px; }

/* ==========================================================
   Cards, stats
   ========================================================== */
.stat-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 24px; }
@media (min-width: 480px) { .stat-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .stat-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); } }

.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-label { display: block; color: var(--text-muted); font-size: 13px; }
.stat-value { display: block; font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat-link { display: inline-block; margin-top: 8px; font-size: 13px; }

.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.filter-bar a { flex-shrink: 0; min-height: 40px; display: inline-flex; align-items: center; padding: 0 16px; border-radius: 20px; background: var(--card); border: 1px solid var(--border); color: var(--text-muted); font-size: 14px; }
.filter-bar a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ==========================================================
   Tables → cards on mobile (data-label technique)
   ========================================================== */
.data-table-wrap { width: 100%; }
.data-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th, .data-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.data-table th { background: var(--bg); color: var(--text-muted); font-weight: 700; }
.data-table .actions { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 767px) {
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr {
        margin-bottom: 12px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 4px 0;
        background: var(--card);
    }
    .data-table td {
        border-bottom: none;
        padding: 8px 16px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        text-align: right;
    }
    .data-table td[data-label]::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--text-muted);
        font-size: 12px;
        text-align: left;
        flex-shrink: 0;
    }
    .data-table td.actions { justify-content: flex-start; }
    .data-table td.actions::before { display: none; }
}

.badge { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; text-transform: capitalize; }
.badge-active, .badge-paid, .badge-approved { background: rgba(31,167,106,0.12); color: #147a4c; }
.badge-lead { background: rgba(245,180,42,0.18); color: #8a6110; }
.badge-pending, .badge-draft { background: rgba(224,169,63,0.15); color: #8a6110; }
.badge-suspended, .badge-rejected, .badge-cancelled, .badge-overdue { background: rgba(224,69,63,0.1); color: #a7231e; }
.badge-completed, .badge-paused { background: rgba(107,107,122,0.12); color: var(--text-muted); }

.panel-form { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; max-width: 100%; margin-bottom: 20px; }
@media (min-width: 480px) { .panel-form { padding: 24px; max-width: 500px; } }

.message-thread { margin-bottom: 20px; }
.message { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin-bottom: 10px; }
.message-admin { border-left: 3px solid var(--accent); }
.message-client { border-left: 3px solid var(--text-muted); }

.file-list { list-style: none; padding: 0; }
.file-list li { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; margin-bottom: 8px; font-size: 14px; }

/* ==========================================================
   Empty states
   ========================================================== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
    background: var(--card);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }

/* ==========================================================
   Kanban board (task board)
   ========================================================== */
.kanban-board { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 600px) { .kanban-board { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .kanban-board { grid-template-columns: repeat(4, 1fr); } }

.kanban-column { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-height: 100px; box-shadow: var(--shadow); }
.kanban-column h3 { margin: 0 0 12px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.kanban-count { background: var(--bg); color: var(--text-muted); font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.kanban-empty { color: var(--text-muted); font-size: 14px; }
.kanban-card { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; font-size: 14px; border-left: 3px solid var(--border); }
.kanban-card.priority-urgent { border-left-color: var(--error); }
.kanban-card.priority-high { border-left-color: var(--warning); }
.kanban-card.priority-normal { border-left-color: var(--primary); }
.kanban-card.priority-low { border-left-color: var(--text-muted); }
.kanban-meta { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.kanban-desc { margin: 6px 0; color: var(--text-muted); font-size: 13px; }
.kanban-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; flex-wrap: wrap; }
.kanban-actions select { width: auto; min-height: 40px; padding: 4px 8px; font-size: 13px; }

/* ==========================================================
   Results logging (campaign performance)
   ========================================================== */
.results-form-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    max-width: 480px;
    margin-bottom: 28px;
}
.results-submit-btn { width: 100%; font-size: 16px; }
.results-history { display: flex; flex-direction: column; gap: 12px; max-width: 480px; }
.results-entry { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.results-entry-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.results-entry-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 480px) { .results-entry-grid { grid-template-columns: repeat(3, 1fr); } }
.results-label { display: block; color: var(--text-muted); font-size: 12px; }
.results-value { display: block; font-size: 16px; font-weight: 700; margin-top: 2px; }
.results-notes { margin: 8px 0 0; color: var(--text-muted); font-size: 13px; font-style: italic; }

/* ==========================================================
   Floating action button
   ========================================================== */
.fab {
    position: fixed;
    right: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    z-index: 35;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 52px;
    padding: 0 20px;
    background: var(--accent);
    color: #1A1A1A;
    border-radius: 30px;
    font-weight: 700;
    font-size: 15px;
    box-shadow: var(--shadow-lg);
    border: none;
    cursor: pointer;
    text-decoration: none;
}
.fab:hover { background: var(--accent-hover); color: #1A1A1A; }
.fab-icon { font-size: 20px; line-height: 1; }

@media (min-width: 1024px) {
    .fab { right: 32px; bottom: 32px; }
}

/* Skeleton loading placeholders (available for any AJAX-driven widgets) */
.skeleton { background: linear-gradient(90deg, var(--border) 25%, #eee 37%, var(--border) 63%); background-size: 400% 100%; animation: skeleton-loading 1.4s ease infinite; border-radius: 8px; }
.skeleton-line { height: 14px; margin-bottom: 8px; }
@keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Page transition fade (applied via JS on load if desired) */
.page-fade-in { animation: page-fade 200ms ease; }
@keyframes page-fade { from { opacity: 0; } to { opacity: 1; } }
