/* =====================================================================
   GR_ADS Intelligence - Apple Design System (Day & Night)
   "Museum gallery in soft daylight & deep darkroom studio"
   ===================================================================== */

:root {
    /* Dynamic Theme Defaults (Overrides come via DB settings in layout) */
    --primary: #0071e3;
    --primary-rgb: 0, 113, 227;
    --primary-hover: #0077ed;
    --primary-light: rgba(0, 113, 227, 0.1);

    --secondary: #0066cc;
    --secondary-rgb: 0, 102, 204;
    --accent: #16ca2e;
    --accent-rgb: 22, 202, 46;
    --danger: #ff3b30;
    --warning: #ff9500;
    
    --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;

    --sidebar-width: 250px;
    --sidebar-collapsed-width: 80px;
    --header-height: 52px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-full: 980px;

    --transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

/* =====================================================================
   Modo Dia (Light Mode) — Apple Soft Gallery
   ===================================================================== */
:root, [data-theme="light"] {
    --bg-body: #f5f5f7;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #fbfbfd;
    --border-color: #d6d6d6;
    --border-hover: #b0b0b5;
    --divider-color: #f0f0f2;

    --text-primary: #1d1d1f;
    --text-secondary: #707070;
    --text-muted: #858585;

    --sidebar-bg: #f5f5f7;
    --header-bg: rgba(255, 255, 255, 0.85);
    --input-bg: #ffffff;
    --table-header-bg: #f5f5f7;
    --table-row-hover: #fbfbfd;
    --badge-bg: #f5f5f7;
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* =====================================================================
   Modo Noite (Dark Mode) — Apple Deep Dark Studio
   ===================================================================== */
[data-theme="dark"] {
    --bg-body: #000000;
    --bg-surface: #1c1c1e;
    --bg-card: #1c1c1e;
    --bg-card-hover: #262629;
    --border-color: #2c2c2e;
    --border-hover: #3a3a3c;
    --divider-color: #28282b;

    --text-primary: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-muted: #86868b;

    --sidebar-bg: #121214;
    --header-bg: rgba(18, 18, 20, 0.85);
    --input-bg: #161618;
    --table-header-bg: #161618;
    --table-row-hover: #242428;
    --badge-bg: #2c2c2e;
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.45);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.47;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.2s ease, color 0.2s ease;
}

a {
    color: var(--secondary);
    text-decoration: none;
    transition: var(--transition);
}

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

/* Layout Estrutural */
.app-container {
    display: flex;
    min-height: 100vh;
    position: relative;
    background-color: var(--bg-body);
    transition: background-color 0.2s ease;
}

/* Sidebar Estilo Apple */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    transition: var(--transition);
}

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

.brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
    text-decoration: none;
}

.brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--text-primary);
    color: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-name {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.brand-sub {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

/* Sidebar Menu Apple (Pills 980px) */
.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    color: var(--text-muted);
    padding: 14px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 400;
    transition: var(--transition);
    text-decoration: none;
}

.nav-item:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-item.active {
    background: var(--bg-card);
    color: var(--primary) !important;
    font-weight: 500;
    border-left: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    text-decoration: none;
}

.nav-item.active svg {
    color: var(--primary) !important;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid var(--border-color);
}

.user-profile-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--bg-card);
    font-size: 0.82rem;
}

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-name {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* Área Principal */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    width: calc(100% - var(--sidebar-width));
}

/* Header Navbar Frosted Glass Apple */
.app-header {
    height: var(--header-height);
    background: var(--header-bg);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 40;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.page-title {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Botão Alternador Dia/Noite com Ícones Dinâmicos */
.theme-toggle-btn, .icon-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.theme-toggle-btn:hover, .icon-btn:hover {
    background: var(--bg-card-hover);
    color: var(--primary);
    border-color: var(--primary);
}

/* Regras de Exibição dos Ícones Sol e Lua */
[data-theme="light"] .theme-toggle-btn .sun-icon { display: none !important; }
[data-theme="light"] .theme-toggle-btn .moon-icon { display: block !important; }
[data-theme="dark"] .theme-toggle-btn .sun-icon { display: block !important; }
[data-theme="dark"] .theme-toggle-btn .moon-icon { display: none !important; }

/* Conteúdo da Página — Preenchimento Total 100% sem distanciamento da sidebar */
.app-content {
    padding: 24px 32px;
    flex: 1;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Cards & Pedestais Apple Gallery */
.glass-card, .card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 24px 28px;
    transition: var(--transition);
    position: relative;
    box-sizing: border-box;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.glass-card:hover, .card:hover {
    border-color: var(--border-hover);
}

.card-header-flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.card-title {
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin: 0;
}

.card-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 4px 0 0 0;
}

/* KPI Showcase Grid & Cards (Apple Pedestals) */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
    margin-bottom: 24px;
    width: 100%;
    box-sizing: border-box;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 22px 24px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-bottom: 0;
    transition: var(--transition);
}

.kpi-card:hover {
    border-color: var(--border-hover);
}

.kpi-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.kpi-label {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
}

.kpi-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

.kpi-icon.primary { background: rgba(var(--primary-rgb, 0, 113, 227), 0.12); color: var(--primary); }
.kpi-icon.success { background: rgba(var(--accent-rgb, 22, 202, 46), 0.12); color: var(--accent); }
.kpi-icon.info { background: rgba(var(--secondary-rgb, 0, 102, 204), 0.12); color: var(--secondary); }
.kpi-icon.warning { background: rgba(255, 149, 0, 0.12); color: #ff9500; }

.kpi-value {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
    font-size: 32px;
    font-weight: 600;
    letter-spacing: -0.015em;
    color: var(--text-primary);
    line-height: 1.15;
}

.kpi-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.kpi-badge-roas {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    background: rgba(var(--primary-rgb, 0, 113, 227), 0.1);
    color: var(--primary);
    border: 1px solid rgba(var(--primary-rgb, 0, 113, 227), 0.25);
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 320px;
}

/* Botões Oficiais Apple (Pill 980px) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 22px;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.4;
    border-radius: var(--radius-full);
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    text-decoration: none;
    font-family: inherit;
    box-shadow: none;
}

/* Filled Primary Button (Consome Cor Primária do Sistema) */
.btn-primary {
    background-color: var(--primary) !important;
    color: #ffffff !important;
    border: none;
}

.btn-primary:hover {
    filter: brightness(1.1);
    color: #ffffff !important;
    text-decoration: none;
}

/* Outlined Secondary Button (Consome Cor Secundária do Sistema) */
.btn-secondary, .btn-outline {
    background-color: transparent !important;
    color: var(--secondary) !important;
    border: 1px solid var(--secondary) !important;
}

.btn-secondary:hover, .btn-outline:hover {
    background-color: rgba(var(--secondary-rgb, 0, 102, 204), 0.08) !important;
    border-color: var(--primary) !important;
    color: var(--primary) !important;
    text-decoration: none;
}

.btn-danger {
    background: transparent;
    color: #ff3b30 !important;
    border: 1px solid rgba(255, 59, 48, 0.4);
}

.btn-danger:hover {
    background: #ff3b30;
    color: #ffffff !important;
    text-decoration: none;
}

.btn-sm {
    padding: 6px 16px;
    font-size: 12px;
    border-radius: var(--radius-full);
}

/* Formulários Apple */
.form-group {
    margin-bottom: 20px;
}

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

.form-control, .form-select {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    transition: var(--transition);
    outline: none;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb, 0, 113, 227), 0.2);
}

.form-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

@media (max-width: 768px) {
    .form-grid-2 {
        grid-template-columns: 1fr;
    }
}

/* Tabelas Estilo Apple Gallery */
.table-responsive {
    overflow-x: auto;
    width: 100%;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: var(--bg-card);
    color: var(--text-primary);
}

.custom-table th {
    background: var(--table-header-bg);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.02em;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.custom-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--divider-color);
    color: var(--text-primary);
    vertical-align: middle;
}

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

.custom-table tr:hover td {
    background: var(--table-row-hover);
}

/* Badges e Pílulas Apple */
.badge-platform {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 400;
}

.badge-meta {
    background: rgba(var(--primary-rgb, 0, 113, 227), 0.1);
    color: var(--primary);
    border: 1px solid rgba(var(--primary-rgb, 0, 113, 227), 0.25);
}

.badge-google {
    background: var(--badge-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 400;
    border: 1px solid var(--border-color);
    background: var(--badge-bg);
    color: var(--text-primary);
}

.status-indicator .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-active {
    background: rgba(var(--accent-rgb, 22, 202, 46), 0.1);
    color: var(--accent);
    border-color: rgba(var(--accent-rgb, 22, 202, 46), 0.3);
}
.status-active .dot { background: var(--accent); }

.status-paused {
    background: rgba(255, 149, 0, 0.12);
    color: #ff9500;
    border-color: rgba(255, 149, 0, 0.3);
}
.status-paused .dot { background: #ff9500; }

.status-inactive, .status-archived {
    background: var(--badge-bg);
    color: var(--text-muted);
    border-color: var(--border-color);
}
.status-inactive .dot, .status-archived .dot { background: var(--text-muted); }

/* Segmented Control / Abas Apple */
.nav-tabs {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--border-color);
    padding: 4px;
    border-radius: var(--radius-full);
    border-bottom: none;
    margin-bottom: 24px;
}

.tab-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 18px;
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    transition: var(--transition);
    text-decoration: none;
    border-bottom: none;
}

.tab-link:hover {
    color: var(--text-primary);
    text-decoration: none;
}

.tab-link.active {
    background: var(--bg-card);
    color: var(--text-primary);
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Toast Notifications Apple */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    min-width: 300px;
    max-width: 420px;
    padding: 14px 18px;
    border-radius: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    animation: toastSlide 0.25s ease;
}

@keyframes toastSlide {
    from { transform: translateY(-10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.toast-success { border-left: 4px solid var(--accent); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info { border-left: 4px solid var(--secondary); }

/* Responsividade Mobile */
@media (max-width: 768px) {
    .app-sidebar {
        transform: translateX(-100%);
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .app-main {
        margin-left: 0;
        width: 100%;
    }

    .app-content {
        padding: 16px;
    }

    .app-header {
        padding: 0 16px;
    }
}
