/* ========== Reset & Base ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f6fa;
    color: #2d3436;
    line-height: 1.6;
}

a { color: #0984e3; text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #dfe6e9; padding: 2px 6px; border-radius: 3px; font-size: 0.9em; }
pre { background: #2d3436; color: #dfe6e9; padding: 16px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
pre code { background: none; padding: 0; }

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

.sidebar {
    width: 240px;
    background: #2d3436;
    color: #fff;
    padding: 24px 0;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    box-sizing: border-box;
}

.sidebar-brand { padding: 0 24px 24px; border-bottom: 1px solid #636e72; }
.sidebar-brand h2 { font-size: 1.5em; }
.sidebar-brand .subtitle { color: #b2bec3; font-size: 0.85em; }

.nav-links { list-style: none; padding: 16px 0; }
.nav-links li a {
    display: block;
    padding: 10px 24px;
    color: #b2bec3;
    transition: all 0.2s;
}
.nav-links li a:hover,
.nav-links li a.active {
    background: #636e72;
    color: #fff;
    text-decoration: none;
}
.nav-divider { border-top: 1px solid #636e72; margin: 8px 0; }

.content { flex: 1; padding: 32px; max-width: 1200px; }
.content h1 { margin-bottom: 24px; font-size: 1.8em; }

/* ========== Status Cards ========== */
.status-card {
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 16px;
}
.status-card h3 { margin-bottom: 8px; }
.status-card.success { background: #d4edda; border-left: 4px solid #28a745; }
.status-card.warning { background: #fff3cd; border-left: 4px solid #ffc107; }
.status-card.error { background: #f8d7da; border-left: 4px solid #dc3545; }
.status-card.info { background: #d1ecf1; border-left: 4px solid #17a2b8; }

/* ========== Metrics ========== */
.metrics { display: flex; gap: 32px; margin-top: 12px; }
.metric-label { display: block; font-size: 0.8em; color: #636e72; text-transform: uppercase; }
.metric-value { font-size: 1.2em; font-weight: 600; }

/* ========== Nav Cards ========== */
.nav-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 24px; }
.nav-card {
    background: #fff;
    padding: 24px;
    border-radius: 8px;
    border: 1px solid #dfe6e9;
    transition: box-shadow 0.2s;
}
.nav-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); text-decoration: none; }
.nav-card h3 { color: #2d3436; margin-bottom: 8px; }
.nav-card p { color: #636e72; font-size: 0.9em; }

/* ========== Filters ========== */
.filters {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #dfe6e9;
}
.filters label { font-weight: 600; font-size: 0.9em; }
.filters select {
    padding: 6px 12px;
    border: 1px solid #dfe6e9;
    border-radius: 4px;
    font-size: 0.9em;
}
.count { margin-left: auto; color: #636e72; font-size: 0.9em; }

/* ========== Data Table ========== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #dfe6e9;
}
.data-table th {
    background: #f8f9fa;
    padding: 12px 16px;
    text-align: left;
    font-size: 0.85em;
    text-transform: uppercase;
    color: #636e72;
    border-bottom: 2px solid #dfe6e9;
}
.data-table td {
    padding: 10px 16px;
    border-bottom: 1px solid #f1f2f6;
    font-size: 0.9em;
}
.data-table tr:hover { background: #f8f9fa; }

/* ========== Badges ========== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 600;
}
.badge-active { background: #d4edda; color: #155724; }
.badge-inactive { background: #fff3cd; color: #856404; }
.badge-archived { background: #f8d7da; color: #721c24; }

/* ========== Buttons ========== */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    transition: background 0.2s;
}
.btn-primary { background: #0984e3; color: #fff; }
.btn-primary:hover { background: #0873c4; }
.btn-primary:disabled { background: #b2bec3; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 0.8em; }
.btn-block { display: block; width: 100%; text-align: center; margin-top: 16px; }
.btn-close {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: #636e72;
}

/* ========== Modal ========== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: #fff;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #dfe6e9;
}
.modal-body { padding: 24px; }

/* ========== Forms ========== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9em; }
.form-group input[type="text"],
.form-group input[type="date"],
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #dfe6e9;
    border-radius: 6px;
    font-size: 0.95em;
}
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }
.hint { font-weight: normal; font-size: 0.8em; color: #636e72; }
.geo-type-row { margin-bottom: 8px; }
.geo-type-row select { width: auto; min-width: 200px; }
.advertiser-toggle { display: flex; gap: 6px; margin-bottom: 8px; }

/* Selected Tags */
.selected-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.selected-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #0984e3;
    color: #fff;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 0.85em;
}
.selected-tag .remove-tag {
    cursor: pointer;
    font-weight: bold;
    font-size: 1.1em;
    line-height: 1;
    opacity: 0.8;
}
.selected-tag .remove-tag:hover { opacity: 1; }

/* ========== Brand Preview ========== */
.brand-info {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 16px;
}
.brand-logo { width: 64px; height: 64px; object-fit: contain; border-radius: 8px; }
.color-swatches { display: flex; gap: 6px; margin-top: 8px; }
.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid #dfe6e9;
}

/* ========== Ad Grid ========== */
.ad-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.ad-preview {
    background: #f8f9fa;
    border: 1px solid #dfe6e9;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
}
.ad-preview img { max-width: 100%; height: auto; border-radius: 4px; }
.ad-preview .ad-label { font-size: 0.8em; color: #636e72; margin-top: 8px; }

/* ========== Loading ========== */
.loading { text-align: center; padding: 32px; }
.spinner {
    width: 40px; height: 40px;
    border: 4px solid #dfe6e9;
    border-top-color: #0984e3;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Setup Steps ========== */
.setup-steps .step {
    background: #fff;
    padding: 24px;
    border-radius: 8px;
    border: 1px solid #dfe6e9;
    margin-bottom: 16px;
}
.setup-steps .step h2 { font-size: 1.2em; margin-bottom: 12px; }
.setup-steps .step ol, .setup-steps .step ul { padding-left: 20px; }
.setup-steps .step li { margin-bottom: 6px; }

/* ========== Availability ========== */
.avail-form {
    background: #fff;
    padding: 24px;
    border-radius: 8px;
    border: 1px solid #dfe6e9;
    margin-bottom: 24px;
}
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 180px; }
.month-presets label { font-weight: 600; font-size: 0.9em; display: block; margin-bottom: 6px; }
.preset-buttons { display: flex; gap: 6px; }
.btn-outline {
    background: #fff;
    border: 1px solid #0984e3;
    color: #0984e3;
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.8em;
}
.btn-outline:hover { background: #0984e3; color: #fff; }
.size-options { margin-top: 4px; }
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 8px;
}
.checkbox-grid label {
    font-weight: normal;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Result Cards */
.result-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.result-card {
    padding: 20px;
    border-radius: 8px;
    text-align: center;
}
.result-card.available { background: #d4edda; border-left: 4px solid #28a745; }
.result-card.matched { background: #d1ecf1; border-left: 4px solid #17a2b8; }
.result-card.possible { background: #fff3cd; border-left: 4px solid #ffc107; }
.result-card.contending { background: #f8d7da; border-left: 4px solid #dc3545; }
.result-label { display: block; font-size: 0.8em; text-transform: uppercase; font-weight: 600; color: #636e72; }
.result-value { display: block; font-size: 2em; font-weight: 700; margin: 8px 0; }
.result-sub { display: block; font-size: 0.8em; color: #636e72; }

/* Spec Ad from Availability */
.spec-ad-section { margin-top: 24px; }
.spec-ad-panel {
    background: #fff;
    padding: 24px;
    border-radius: 8px;
    border: 1px solid #dfe6e9;
    margin-top: 16px;
}
.spec-ad-panel h3 { margin-bottom: 16px; }
/* Ad Copy Preview */
.ad-copy-preview {
    background: #f8f9fa;
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid #dfe6e9;
}
.ad-copy-preview h4 { margin-bottom: 10px; font-size: 0.95em; }
.copy-fields { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; }
.copy-field { font-size: 0.9em; }
.copy-colors { display: flex; gap: 6px; }

/* Creative Cards */
.creative-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.creative-card {
    padding: 10px 14px;
    border: 2px solid #dfe6e9;
    border-radius: 8px;
    cursor: pointer;
    background: #fff;
    transition: all 0.2s;
}
.creative-card:hover { border-color: #0984e3; }
.creative-card.selected { border-color: #0984e3; background: #d1ecf1; }
.creative-preview {
    width: 100%;
    height: 120px;
    border: none;
    border-radius: 4px;
    margin-bottom: 8px;
    pointer-events: none;
    overflow: hidden;
}
.creative-name { font-size: 0.85em; font-weight: 600; }
.creative-size { font-size: 0.75em; color: #636e72; }

/* Upload Grid */
.upload-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-top: 8px; }
.upload-slot {
    border: 2px dashed #dfe6e9;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    position: relative;
}
.upload-slot.filled { border-color: #28a745; border-style: solid; }
.upload-slot .slot-label { font-weight: 600; font-size: 0.9em; margin-bottom: 8px; }
.upload-slot .slot-size { font-size: 0.75em; color: #636e72; }
.upload-slot input[type="file"] { width: 100%; font-size: 0.8em; }
.upload-slot .upload-preview { max-width: 100%; max-height: 80px; margin-top: 8px; border-radius: 4px; }
.upload-slot .remove-upload { position: absolute; top: 4px; right: 8px; cursor: pointer; color: #dc3545; font-weight: bold; }

/* Campaign Type Selector */
.campaign-type-selector { margin-bottom: 24px; }
.campaign-type-selector h3 { margin-bottom: 12px; }
.campaign-type-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.campaign-type-card {
    padding: 20px;
    border: 2px solid #dfe6e9;
    border-radius: 8px;
    cursor: pointer;
    background: #fff;
    transition: all 0.2s;
}
.campaign-type-card:hover { border-color: #0984e3; }
.campaign-type-card.selected { border-color: #0984e3; background: #d1ecf1; }
.campaign-type-card h4 { margin-bottom: 6px; font-size: 1em; }
.campaign-type-card p { font-size: 0.8em; color: #636e72; margin: 0; }

/* Extended Network Type Cards */
.extended-type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.ext-type-card {
    padding: 12px;
    border: 2px solid #dfe6e9;
    border-radius: 8px;
    cursor: pointer;
    background: #fff;
    text-align: center;
    transition: all 0.2s;
}
.ext-type-card:hover { border-color: #0984e3; }
.ext-type-card.selected { border-color: #0984e3; background: #d1ecf1; }
.ext-type-card strong { display: block; font-size: 0.85em; margin-bottom: 4px; }
.ext-format { font-size: 0.7em; color: #636e72; }

/* Report Page */
.report-header { margin-bottom: 16px; }
.report-header h2 { margin-bottom: 12px; }
.drilldown-header { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.drilldown-header h2 { margin: 0; }
.data-table tr[style*="cursor"] td:first-child { color: #0984e3; }
.data-table tr[style*="cursor"]:hover { background: #d1ecf1; }

/* Proposal Builder Product Cards */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.product-card { border: 2px solid #dfe6e9; border-radius: 8px; transition: all 0.2s; }
.product-card:has(input:checked) { border-color: #0984e3; background: #d1ecf1; }
.product-card-inner { display: flex; gap: 12px; padding: 16px; cursor: pointer; align-items: flex-start; }
.product-card-inner input[type="checkbox"] { margin-top: 4px; }
.product-card-content { flex: 1; }
.product-card-content strong { display: block; margin-bottom: 4px; font-size: 0.95em; }
.product-card-content p { font-size: 0.8em; color: #636e72; margin: 0 0 6px 0; }
.product-budget { font-size: 0.75em; color: #0984e3; font-weight: 600; }

/* SEM Loading Facts */
.sem-loading-container { text-align: center; padding: 32px; }
.sem-fact-card {
    background: #fff;
    border-left: 4px solid #0984e3;
    border-radius: 8px;
    padding: 20px 24px;
    max-width: 600px;
    margin: 16px auto;
    text-align: left;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    min-height: 80px;
    transition: opacity 0.3s ease;
}
.sem-fact-label {
    font-size: 0.75em;
    text-transform: uppercase;
    color: #0984e3;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.sem-fact-text {
    font-size: 1.05em;
    color: #2d3436;
    margin-top: 8px;
    line-height: 1.5;
}

/* SEM Proposal */
.sem-section { margin-top: 24px; }
.sem-script-box {
    background: #fff;
    padding: 24px;
    border-radius: 8px;
    border: 1px solid #dfe6e9;
    line-height: 1.7;
    font-size: 0.95em;
}
.sem-estimate-box {
    background: #f8f9fa;
    padding: 24px;
    border-radius: 8px;
    border: 1px solid #dfe6e9;
    margin-top: 12px;
    line-height: 1.6;
    font-size: 0.9em;
    overflow-x: auto;
}

/* SEO Grid */
.ranking-grid {
    display: grid;
    gap: 4px;
    max-width: 500px;
}
.grid-cell {
    width: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9em;
    border-radius: 4px;
    color: #fff;
}
.grid-cell.rank-top3 { background: #28a745; }
.grid-cell.rank-top10 { background: #ffc107; color: #2d3436; }
.grid-cell.rank-low { background: #dc3545; }
.grid-cell.rank-none { background: #dfe6e9; color: #636e72; }

/* DV360 Tabs */
.dv360-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid #dfe6e9; padding-bottom: 0; }
.tab-btn {
    padding: 8px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    color: #636e72;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.tab-btn:hover { color: #0984e3; }
.tab-btn.active { color: #0984e3; border-bottom-color: #0984e3; }

/* ============================================================
   Rob-bot Chat
   ============================================================ */
.robbot-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px);
    max-width: 820px;
    margin: 0 auto;
}

.robbot-header { margin-bottom: 1rem; }
.robbot-header h1 { margin: 0 0 0.2rem; }
.robbot-subtitle { color: #636e72; margin: 0; font-size: 0.95rem; }

.chat-window {
    flex: 1;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #dfe6e9;
    border-radius: 8px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 200px;
}

.chat-message { display: flex; flex-direction: column; max-width: 80%; }
.chat-message.user { align-self: flex-end; align-items: flex-end; }
.chat-message.bot { align-self: flex-start; align-items: flex-start; }

.chat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #636e72;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chat-bubble {
    padding: 0.65rem 1rem;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.chat-message.user .chat-bubble {
    background: #0984e3;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.bot .chat-bubble {
    background: #f1f3f5;
    color: #2d3436;
    border-bottom-left-radius: 4px;
}

.chat-bubble.typing { color: #b2bec3; font-style: italic; }

.chat-input-bar {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.chat-input-bar input {
    flex: 1;
    padding: 0.65rem 1rem;
    border: 1px solid #dfe6e9;
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
}

.chat-input-bar input:focus { border-color: #0984e3; }

/* Sheets panel */
.sheets-panel { margin-top: 1.25rem; }

.sheets-toggle {
    width: 100%;
    text-align: left;
    font-size: 0.85rem;
}

#sheets-body {
    background: #fff;
    border: 1px solid #dfe6e9;
    border-radius: 8px;
    padding: 1rem;
    margin-top: 0.5rem;
}

.sheets-list {
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.sheet-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 0.9rem;
}

.sheet-name { flex: 1; font-weight: 500; }
.sheet-date { color: #b2bec3; font-size: 0.8rem; }

.sheets-upload h4 { margin: 0 0 0.75rem; font-size: 0.95rem; }

.btn-danger {
    background: #d63031;
    color: #fff;
    border: none;
}
.btn-danger:hover { background: #b71c1c; }

/* Order Section */
.order-section { margin-top: 24px; }

.brand-domain-info {
    background: #f8f9fa;
    padding: 10px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.9em;
}

/* Logged-in user + logout (added with auth) */
.sidebar-user {
    margin-top: auto;
    padding: 16px 18px;
    border-top: 1px solid rgba(255,255,255,0.12);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.sidebar-user-email {
    font-size: 12px;
    color: rgba(255,255,255,0.7);
    word-break: break-all;
}
.sidebar-logout {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    text-decoration: none;
    opacity: 0.85;
}
.sidebar-logout:hover { opacity: 1; text-decoration: underline; }
