/* ═══════════════════════════════════════════════════════════════════════════
   ChilicoM Newsletter Platform — Dark Theme
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #0A0E17;
    --bg-card: #111827;
    --bg-card-hover: #1a2332;
    --bg-input: #1E293B;
    --bg-sidebar: #0D1117;
    --accent: #00D4AA;
    --accent-dim: #00A88A;
    --orange: #FF6B35;
    --orange-dim: #CC5529;
    --red: #EF4444;
    --yellow: #F59E0B;
    --green: #10B981;
    --blue: #3B82F6;
    --purple: #8B5CF6;
    --text-primary: #E8ECF1;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    --border: #1E293B;
    --border-light: #334155;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    font-size: 15px;
}

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

/* ─── Layout ─────────────────────────────────────────────────────────────── */

.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s;
}

.sidebar-brand {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
}

.sidebar-brand p {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    list-style: none;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-secondary);
    font-size: 14px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    color: var(--text-primary);
    background: var(--bg-card);
    border-left-color: var(--accent);
    text-decoration: none;
}

.sidebar-nav li a .nav-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.main-content {
    flex: 1;
    margin-left: 220px;
    padding: 24px 32px;
    max-width: 1400px;
}

/* Mobile hamburger */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 22px;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    cursor: pointer;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

/* ─── Page Header ────────────────────────────────────────────────────────── */

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

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.page-header .subtitle {
    font-size: 14px;
    color: var(--text-muted);
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */

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

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: border-color 0.2s;
}

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

.card-stat {
    text-align: center;
}

.card-stat .stat-value {
    font-size: 36px;
    font-weight: 800;
    color: var(--accent);
    line-height: 1.1;
}

.card-stat .stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.card-stat.orange .stat-value { color: var(--orange); }
.card-stat.blue .stat-value { color: var(--blue); }
.card-stat.purple .stat-value { color: var(--purple); }

/* ─── Tables ─────────────────────────────────────────────────────────────── */

.table-wrapper {
    overflow-x: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    color: var(--text-secondary);
}

tr:hover td {
    background: var(--bg-card-hover);
}

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

/* ─── Badges ─────────────────────────────────────────────────────────────── */

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-critical { background: rgba(239, 68, 68, 0.2); color: var(--red); }
.badge-high { background: rgba(255, 107, 53, 0.2); color: var(--orange); }
.badge-medium { background: rgba(245, 158, 11, 0.2); color: var(--yellow); }
.badge-low { background: rgba(16, 185, 129, 0.2); color: var(--green); }

.badge-status {
    background: rgba(0, 212, 170, 0.15);
    color: var(--accent);
}

.badge-tier {
    color: var(--yellow);
    font-size: 14px;
    letter-spacing: 2px;
}

.badge-relationship {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
}

.rel-active { background: rgba(16, 185, 129, 0.2); color: var(--green); }
.rel-prospect { background: rgba(59, 130, 246, 0.2); color: var(--blue); }
.rel-paused { background: rgba(245, 158, 11, 0.2); color: var(--yellow); }
.rel-churned { background: rgba(239, 68, 68, 0.2); color: var(--red); }

/* ─── Tags ───────────────────────────────────────────────────────────────── */

.tag {
    display: inline-block;
    padding: 2px 8px;
    margin: 2px;
    border-radius: 4px;
    font-size: 12px;
    background: rgba(0, 212, 170, 0.1);
    color: var(--accent);
    border: 1px solid rgba(0, 212, 170, 0.2);
}

.tag-orange {
    background: rgba(255, 107, 53, 0.1);
    color: var(--orange);
    border-color: rgba(255, 107, 53, 0.2);
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-primary);
}
.btn-primary:hover {
    background: var(--accent-dim);
    color: var(--bg-primary);
    text-decoration: none;
}

.btn-orange {
    background: var(--orange);
    color: white;
}
.btn-orange:hover {
    background: var(--orange-dim);
    text-decoration: none;
    color: white;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-ghost:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    text-decoration: none;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
    text-decoration: none;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 16px;
}

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

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

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 212, 170, 0.1);
}

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

select.form-control {
    appearance: auto;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.form-inline {
    display: flex;
    gap: 8px;
    align-items: end;
    flex-wrap: wrap;
}

.form-inline .form-group {
    margin-bottom: 0;
}

/* ─── Pipeline / Kanban ──────────────────────────────────────────────────── */

.pipeline {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.pipeline-step {
    flex: 1;
    min-width: 80px;
    text-align: center;
    padding: 12px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: relative;
}

.pipeline-step .step-count {
    font-size: 24px;
    font-weight: 800;
    color: var(--accent);
}

.pipeline-step .step-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 4px;
}

.pipeline-step.has-items {
    border-color: var(--accent);
    background: rgba(0, 212, 170, 0.05);
}

/* Kanban board */
.kanban-board {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 16px;
    margin-bottom: 24px;
}

.kanban-column {
    min-width: 200px;
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.kanban-column-header {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding-bottom: 8px;
    border-bottom: 2px solid var(--accent);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kanban-column-header .count {
    background: var(--accent);
    color: var(--bg-primary);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
}

.kanban-card {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.2s;
}

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

.kanban-card .kc-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.kanban-card .kc-meta {
    font-size: 11px;
    color: var(--text-muted);
}

/* ─── Bar Chart (CSS-only) ───────────────────────────────────────────────── */

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 0;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bar-label {
    width: 150px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: right;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    flex: 1;
    height: 24px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-dim));
    border-radius: 4px;
    min-width: 2px;
    transition: width 0.6s ease;
}

.bar-fill.orange {
    background: linear-gradient(90deg, var(--orange), var(--orange-dim));
}

.bar-value {
    width: 50px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

/* ─── Activity Feed ──────────────────────────────────────────────────────── */

.activity-feed {
    list-style: none;
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.activity-item:last-child { border-bottom: none; }

.activity-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    background: rgba(0, 212, 170, 0.1);
}

.activity-text {
    font-size: 13px;
    color: var(--text-secondary);
    flex: 1;
}

.activity-text strong { color: var(--text-primary); }

.activity-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ─── Flash Messages ─────────────────────────────────────────────────────── */

.flash-messages {
    margin-bottom: 16px;
}

.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.flash-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--green);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.flash-error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ─── Quick Actions ──────────────────────────────────────────────────────── */

.quick-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

/* ─── Section ────────────────────────────────────────────────────────────── */

.section {
    margin-bottom: 32px;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* ─── Detail Grid ────────────────────────────────────────────────────────── */

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.detail-full {
    grid-column: 1 / -1;
}

.info-block {
    margin-bottom: 16px;
}

.info-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.info-value {
    font-size: 14px;
    color: var(--text-primary);
}

/* ─── Context Notes ──────────────────────────────────────────────────────── */

.context-notes {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    white-space: pre-wrap;
    font-size: 13px;
    color: var(--text-secondary);
    max-height: 400px;
    overflow-y: auto;
    line-height: 1.8;
}

/* ─── Error Page ─────────────────────────────────────────────────────────── */

.error-page {
    text-align: center;
    padding: 80px 20px;
}

.error-page .error-code {
    font-size: 80px;
    font-weight: 900;
    color: var(--accent);
}

.error-page .error-msg {
    font-size: 18px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ─── Metrics charts ─────────────────────────────────────────────────────── */

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

.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.metric-card h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .sidebar-overlay.open {
        display: block;
    }

    .mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: 56px;
    }

    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .kanban-board {
        flex-direction: column;
    }

    .kanban-column {
        min-width: unset;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .bar-label {
        width: 100px;
        font-size: 11px;
    }

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

    .pipeline {
        flex-direction: column;
    }

    .pipeline-step {
        display: flex;
        align-items: center;
        gap: 8px;
        text-align: left;
    }

    .pipeline-step .step-count {
        font-size: 18px;
    }
}

@media (max-width: 480px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }
}

/* Processing animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
