:root {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --surface2: #242424;
    --border: #2e2e2e;
    --text: #e8e8e8;
    --text-muted: #888;
    --accent: #7c6af7;
    --accent-hover: #9182f8;
    --danger: #e05252;
    --success: #52c97a;
    --warning: #e0a652;
    --radius: 10px;
    --radius-sm: 6px;
    --surface-2: #242424;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

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

/* Navbar */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
    letter-spacing: -0.3px;
}

.nav-links { display: flex; gap: 20px; align-items: center; }
.nav-links a { color: var(--text-muted); font-size: 13px; transition: color .2s; }
.nav-links a:hover { color: var(--text); }
.nav-links a.nav-secondary { font-size: 12px; opacity: .55; }
.nav-links a.nav-secondary:hover { opacity: .85; }

.drive-badge {
    background: var(--surface2);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    font-size: 12px !important;
}
.drive-badge.connected { border-color: var(--success); color: var(--success) !important; }

/* Container */
.container { max-width: 1100px; margin: 0 auto; padding: 32px 24px; }

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}
.page-header h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.4px; }

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

/* Clients grid */
.clients-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.client-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: border-color .2s, transform .15s;
    display: block;
    color: var(--text);
}
.client-card:hover {
    border-color: var(--accent);
    color: var(--text);
    transform: translateY(-2px);
}

.client-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.client-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
}
.client-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.client-name { font-weight: 600; font-size: 15px; }
.client-meta { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.color-dots { display: flex; gap: 4px; margin-top: 10px; }
.color-dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255,255,255,.1); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: all .15s;
    text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #000; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Forms */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }

input[type="text"],
input[type="date"],
input[type="color"],
input[type="file"],
select,
textarea {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    transition: border-color .15s;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
input[type="color"] { height: 36px; padding: 2px 4px; cursor: pointer; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Client detail */
.client-detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
    min-width: 0;
}
.client-detail-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 22px;
}

.tabs { display: flex; gap: 2px; margin-bottom: 24px; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.tab {
    padding: 10px 18px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    border: none;
    background: transparent;
    font-family: inherit;
    transition: color .15s;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Calendar */
.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}
.calendar-day-header {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    padding: 8px 0;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.calendar-cell {
    min-height: 90px;
    max-height: 180px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
    cursor: pointer;
    transition: border-color .15s;
    position: relative;
}
.calendar-cell:hover { border-color: var(--accent); }
.calendar-cell.empty { background: transparent; border-color: transparent; cursor: default; }
.calendar-cell.today { border-color: var(--accent); }

.day-number {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}
.today .day-number { color: var(--accent); }

.post-chip {
    display: block;
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 3px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}
.post-chip.idea { background: rgba(124,106,247,.2); color: var(--accent); }
.post-chip.draft { background: rgba(224,166,82,.2); color: var(--warning); }
.post-chip.approved { background: rgba(82,201,122,.2); color: var(--success); }
.post-chip.published { background: rgba(82,201,122,.1); color: var(--text-muted); }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; }

/* Post detail */
.post-section { margin-bottom: 24px; }
.post-section h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 10px; }

.ideas-list { display: flex; flex-direction: column; gap: 8px; }
.idea-option {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    cursor: pointer;
    transition: border-color .15s;
    font-size: 13px;
    text-align: left;
    color: var(--text);
    font-family: inherit;
}
.idea-option:hover { border-color: var(--accent); }
.idea-option.selected { border-color: var(--accent); background: rgba(124,106,247,.1); }

.copy-output {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-size: 13px;
    white-space: pre-wrap;
    min-height: 80px;
    line-height: 1.6;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.status-badge.idea { background: rgba(124,106,247,.2); color: var(--accent); }
.status-badge.draft { background: rgba(224,166,82,.2); color: var(--warning); }
.status-badge.approved { background: rgba(82,201,122,.2); color: var(--success); }
.status-badge.published { background: rgba(82,201,122,.1); color: var(--text-muted); }

/* Script output */
.script-output {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    white-space: pre-wrap;
    line-height: 1.7;
    color: #c8e6c9;
    max-height: 400px;
    overflow-y: auto;
}

/* Image preview */
.image-preview {
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    max-width: 400px;
}
.image-preview img { width: 100%; display: block; }

/* Loader */
.loader { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state p { margin-bottom: 16px; }

/* Breadcrumb */
.breadcrumb { font-size: 12px; color: var(--text-muted); margin-bottom: 20px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb span { margin: 0 6px; }

/* Drive info */
.drive-info {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}
.drive-info.connected { border-color: rgba(82,201,122,.3); color: var(--success); }

/* Utility */
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Surface variant */
.surface-2 { background: var(--surface2); }

/* Org idea rows */
.org-idea-row:hover { border-color: var(--accent); }

/* Idea chips */
.idea-chip {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    margin-bottom: 6px;
    transition: border-color .15s;
}
.idea-chip:hover { border-color: var(--accent); }
.idea-chip.selected { border-color: var(--accent); background: rgba(124,106,247,.12); }

/* Reference image cards */
.ref-image-card:hover { border-color: var(--accent); }

/* Example post cards */
.example-post-card { transition: border-color .15s; }
.example-post-card:hover { border-color: var(--border); }

/* ── Calendario general: leyenda de clientes ── */
.client-legend { display:flex; flex-wrap:wrap; gap:12px; margin-bottom:20px; }
.legend-item { display:flex; align-items:center; gap:6px; font-size:12px; color:var(--text-muted); }
.legend-dot { width:10px; height:10px; border-radius:50%; flex-shrink:0; }

/* Badge de cliente en el chip */
.chip-client {
    display:inline-block;
    background:rgba(255,255,255,.12);
    border-radius:2px;
    padding:0 3px;
    font-size:9px;
    font-weight:700;
    letter-spacing:.4px;
    margin-right:4px;
    vertical-align:middle;
}

/* Drag-and-drop */
.calendar-cell.drag-over { border-color:var(--accent); background:rgba(124,106,247,.1); }
.post-chip[draggable="true"] { cursor:grab; user-select:none; }
.post-chip[draggable="true"]:active { cursor:grabbing; opacity:.6; }

/* Botón edición rápida dentro del chip */
.chip-edit-btn {
    float: right;
    margin-left: 4px;
    opacity: 0;
    font-size: 11px;
    line-height: 1;
    padding: 1px 3px;
    border-radius: 3px;
    background: rgba(255,255,255,.15);
    cursor: pointer;
    transition: opacity .15s;
}
.post-chip:hover .chip-edit-btn { opacity: 1; }

/* Drag handle dentro del chip */
.chip-drag-handle {
    display: inline-block;
    margin-right: 4px;
    opacity: 0.4;
    cursor: grab;
    font-size: 12px;
    line-height: 1;
    vertical-align: middle;
}
.post-chip:hover .chip-drag-handle { opacity: 0.8; }

/* Botón edición — siempre visible */
.chip-edit-btn {
    float: right;
    margin-left: 4px;
    font-size: 11px;
    padding: 1px 4px;
    border-radius: 3px;
    background: rgba(255,255,255,.18);
    cursor: pointer;
    line-height: 1.4;
    vertical-align: middle;
}
.chip-edit-btn:hover { background: rgba(255,255,255,.35); }

/* chip-wrapper: contenedor draggable */
.chip-wrapper {
    display: flex;
    align-items: center;
    border-radius: var(--radius-sm);
    margin-bottom: 3px;
    cursor: grab;
}
.chip-wrapper:active { cursor: grabbing; }
.chip-wrapper .post-chip {
    flex: 1;
    min-width: 0;
    display: block;
    margin-bottom: 0;
    text-decoration: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.chip-wrapper .chip-edit-btn {
    flex-shrink: 0;
    padding: 2px 5px;
    background: rgba(255,255,255,.12);
    border: none;
    color: var(--text);
    font-size: 11px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    cursor: pointer;
    height: 100%;
    line-height: 1.6;
}
.chip-wrapper .chip-edit-btn:hover { background: rgba(255,255,255,.28); }

/* Parche: sobreescribir opacity y user-select acumulados */
.chip-wrapper { user-select: none; }
.chip-wrapper .chip-edit-btn { opacity: 1; }

/* Badge cliente: ancho minimo para consistencia */
.chip-client { min-width: 30px; text-align: center; letter-spacing: .3px; }

/* Lista mobile calendario: oculta por defecto */
.calendar-mobile-list { display: none; }

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

/* Evitar overflow horizontal en toda la app */
html, body { overflow-x: hidden; }

/* Calendario: breakpoint 1024px para pantallas medianas */
@media (max-width: 1024px) {
    .calendar-header { flex-wrap: wrap; gap: 8px; justify-content: center; }
    .calendar-header > .flex { flex-wrap: wrap; gap: 6px; justify-content: center; }
}

@media (max-width: 768px) {

    /* Container */
    .container { padding: 20px 16px; }

    /* Navbar */
    .navbar { padding: 0 16px; }
    .nav-links { gap: 12px; }
    .nav-links a { font-size: 12px; }

    /* Page header */
    .page-header { flex-wrap: wrap; gap: 10px; }
    .page-header h1 { font-size: 18px; }

    /* Clients grid → 1 columna en mobile, 2 en tablet */
    .clients-grid { grid-template-columns: 1fr; }

    /* Client detail header → apilar */
    .client-detail-header { flex-wrap: wrap; gap: 12px; }
    .client-detail-header .flex { margin-left: 0 !important; width: 100%; }

    /* Tabs → scrollables horizontalmente */
    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; padding-bottom: 0; scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { white-space: nowrap; flex-shrink: 0; padding: 10px 14px; font-size: 12px; }

    /* Forms */
    .form-row { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr; }

    /* Cards */
    .card { padding: 14px; }

    /* Calendar header */
    .calendar-header { flex-wrap: wrap; gap: 8px; }
    .calendar-header .flex { width: 100%; }

    /* Calendario → ocultar grilla, mostrar lista de posts */
    .calendar-grid { display: none; }
    .calendar-mobile-list { display: block; }

    /* Modal */
    .modal { padding: 16px; width: 96%; }

    /* Post detail: columnas a una sola */
    .post-detail-cols { flex-direction: column; }

    /* Botones en grupos → wrap */
    .flex.gap-8 { flex-wrap: wrap; }

    /* Imagen preview */
    .image-preview { max-width: 100%; }

    /* Gen panel rows */
    .client-gen-row { flex-wrap: wrap; gap: 8px; }
    .client-gen-row label { min-width: unset !important; }

    /* Legend */
    .client-legend { gap: 8px; }
}

@media (min-width: 480px) and (max-width: 768px) {
    .clients-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {

    /* Client detail header: apilar avatar + nombre + botones */
    .client-detail-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .client-detail-header > div:last-child {
        margin-left: 0 !important;
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    /* Secciones de marca: grillas a columna */
    .form-row, .form-row-3 { grid-template-columns: 1fr !important; }

    /* Imágenes de referencia: grid más pequeño */
    [style*="grid-template-columns: repeat(auto-fill, minmax(120px"] {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)) !important;
    }

    /* Panel de posts en portal agencia: formularios inline → columna */
    [style*="display:flex;gap:6px;align-items:flex-end"] {
        flex-direction: column;
        align-items: stretch !important;
    }
    [style*="display:flex;gap:6px;align-items:flex-end"] button,
    [style*="display:flex;gap:6px;align-items:center"] button[type="submit"] {
        width: 100%;
        height: auto !important;
        justify-content: center;
    }

    /* Cabecera de post en portal agencia */
    [style*="display:flex;align-items:center;gap:8px;padding:12px 16px"] {
        flex-wrap: wrap;
    }

    /* Botones de aprobar/rechazar en portal agencia */
    [style*="display:flex;gap:8px;align-items:center;flex-wrap:wrap"] {
        gap: 6px;
    }

    /* Mensajes generales: input + botón */
    .card form.flex { flex-direction: column; }
    .card form.flex button { width: 100%; height: auto !important; justify-content: center; }

    /* Post detail: ocultar sidebar en mobile si hubiera */
    .post-detail-cols { flex-direction: column !important; }

    /* Calendar header en cliente: achicar */
    .calendar-header h2 { font-size: 15px; }

    /* Tabla de tareas: wrap */
    [style*="display:flex;justify-content:space-between"] { flex-wrap: wrap; gap: 8px; }
}
