/* =============================================================================
   JuiceCRM v0.1 — Paleta heredada del CRM de VitaKids como punto de partida.
   Rebrand pendiente cuando Vic encargue identidad visual propia.
   ========================================================================== */

:root {
    /* Colores base */
    --bg-app: #EEF4FB;
    --bg-card: #FFFFFF;
    --bg-sidebar: #1E293B;
    --bg-input: #FFFFFF;
    --bg-muted: #F8FAFC;
    --bg-hover: #F1F5F9;

    /* Primary */
    --primary: #7E68DB;
    --primary-hover: #6E59C7;
    --primary-light: #EDE9FB;
    --primary-text: #FFFFFF;

    /* Texto */
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-tertiary: #94A3B8;
    --text-on-dark: #E2E8F0;
    --text-on-dark-muted: #94A3B8;

    /* Bordes */
    --border: #E2E8F0;
    --border-strong: #CBD5E1;
    --border-focus: #7E68DB;

    /* Estados */
    --success: #10B981;
    --success-bg: #D1FAE5;
    --warning: #F59E0B;
    --warning-bg: #FEF3C7;
    --error: #EF4444;
    --error-bg: #FEE2E2;
    --info: #3B82F6;
    --info-bg: #DBEAFE;

    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.08), 0 1px 2px -1px rgb(0 0 0 / 0.06);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.04);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);

    /* Spacing & layout */
    --sidebar-w: 240px;
    --header-h: 64px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
}

/* =============================================================================
   Reset / base
   ========================================================================== */

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                 Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-app);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

h1, h2, h3, h4 { margin: 0 0 .5rem 0; font-weight: 600; line-height: 1.25; color: var(--text-primary); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }

p { margin: 0 0 .75rem 0; color: var(--text-secondary); }

/* =============================================================================
   Auth screens (login del tenant y del master)
   ========================================================================== */

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(circle at top left, rgba(126,104,219,.08), transparent 60%),
        radial-gradient(circle at bottom right, rgba(59,130,246,.08), transparent 60%),
        var(--bg-app);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
}

.auth-card.master {
    border-top: 4px solid var(--primary);
}

.auth-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-brand .logo {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -.02em;
    margin: 0;
}

.auth-brand .subtitle {
    margin: .25rem 0 0 0;
    color: var(--text-tertiary);
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.auth-card h2 {
    text-align: center;
    margin-bottom: 1.5rem;
}

/* =============================================================================
   Forms
   ========================================================================== */

.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    margin-bottom: .35rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: .9rem;
}

.form-group input[type=text],
.form-group input[type=email],
.form-group input[type=password],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .65rem .85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    font-family: inherit;
    font-size: .95rem;
    color: var(--text-primary);
    transition: border-color .15s, box-shadow .15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(126,104,219,.15);
}

.form-group .checkbox-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: .25rem;
}

.form-group .checkbox-row label {
    margin: 0;
    font-weight: 400;
    color: var(--text-secondary);
}

.form-error {
    display: block;
    margin-top: .25rem;
    color: var(--error);
    font-size: .85rem;
}

/* =============================================================================
   Botones
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .65rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--bg-muted);
    color: var(--text-primary);
    font-family: inherit;
    font-size: .95rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s, color .15s, transform .1s;
}

.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.btn-primary {
    background: var(--primary);
    color: var(--primary-text);
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: var(--primary-text);
}

.btn-block { width: 100%; }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); }

.btn-danger {
    background: var(--error);
    color: white;
    border-color: var(--error);
}

/* =============================================================================
   Layout app (sidebar + main)
   ========================================================================== */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--bg-sidebar);
    color: var(--text-on-dark);
    padding: 1.25rem 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar .logo {
    font-size: 1.35rem;
    font-weight: 700;
    color: white;
    margin: 0 0 .25rem 0;
    letter-spacing: -.02em;
}

.sidebar .tenant-name {
    color: var(--text-on-dark-muted);
    font-size: .8rem;
    margin: 0 0 1.5rem 0;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--text-on-dark-muted);
    text-decoration: none;
    font-size: .9rem;
    transition: background .15s, color .15s;
}

.sidebar nav a:hover {
    background: rgba(255,255,255,.05);
    color: var(--text-on-dark);
    text-decoration: none;
}

.sidebar nav a.active {
    background: rgba(126,104,219,.18);
    color: white;
}

.sidebar .sidebar-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .8rem;
    color: var(--text-on-dark-muted);
}

.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-header {
    height: var(--header-h);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.app-header .page-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.app-header .user-chip {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .75rem;
    background: var(--bg-muted);
    border-radius: 100px;
    font-size: .85rem;
    color: var(--text-secondary);
}

.app-header .user-chip a {
    color: var(--text-tertiary);
    margin-left: .5rem;
}

.content {
    padding: 1.5rem;
    max-width: 1280px;
}

/* =============================================================================
   Cards y KPIs
   ========================================================================== */

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.card-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.kpi .label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-tertiary);
    margin: 0 0 .35rem 0;
    font-weight: 500;
}

.kpi .value {
    font-size: 1.65rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.1;
}

.kpi .help {
    margin: .35rem 0 0 0;
    font-size: .8rem;
    color: var(--text-tertiary);
}

/* =============================================================================
   Tablas
   ========================================================================== */

.table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}

.table th, .table td {
    text-align: left;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--bg-muted);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-hover); }

.table .empty {
    text-align: center;
    color: var(--text-tertiary);
    padding: 2rem 1rem;
    font-style: italic;
}

/* =============================================================================
   Pills / status badges
   ========================================================================== */

.pill {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 100px;
    font-size: .75rem;
    font-weight: 500;
    background: var(--bg-muted);
    color: var(--text-secondary);
}

.pill-success { background: var(--success-bg); color: var(--success); }
.pill-warning { background: var(--warning-bg); color: var(--warning); }
.pill-error   { background: var(--error-bg); color: var(--error); }
.pill-info    { background: var(--info-bg); color: var(--info); }
.pill-primary { background: var(--primary-light); color: var(--primary); }

/* =============================================================================
   Flash messages
   ========================================================================== */

.flash-stack {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 100;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.flash {
    padding: .8rem 1rem;
    border-radius: var(--radius-sm);
    background: white;
    border-left: 4px solid var(--info);
    box-shadow: var(--shadow-md);
    color: var(--text-primary);
    font-size: .9rem;
}

.flash.success { border-left-color: var(--success); }
.flash.error   { border-left-color: var(--error); }
.flash.warning { border-left-color: var(--warning); }

/* =============================================================================
   Responsive
   En 4 viewports verificados: 375 / 390 / 768 / 1280
   - 375/390 (iPhone SE / iPhone 14): sidebar fixed off-canvas, header full
   - 768  (iPad portrait): sidebar fixed off-canvas
   - 1024+ (laptop): grid normal con sidebar fija
   ========================================================================== */

@media (max-width: 1023px) {
    .app-shell {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: fixed;
        left: -260px;
        width: 240px;
        z-index: 50;
        transition: left .25s ease;
    }
    .sidebar.open { left: 0; }
    .app-header { padding: 0 1rem; }
    .content { padding: 1rem; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .auth-card { padding: 1.5rem; }
    .kpi-grid { grid-template-columns: 1fr; }
    .table th:nth-child(n+4),
    .table td:nth-child(n+4) { display: none; }
}

/* =============================================================================
   v0.2 — Adiciones para CRM (clients, pipeline, formularios complejos)
   ========================================================================== */

/* --- Sidebar: secciones y sub-items --- */
.sidebar .sidebar-section {
    margin: 1.25rem 0 .35rem 0;
    padding: 0 .75rem;
    color: var(--text-on-dark-muted);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    font-weight: 600;
}
.sidebar nav a.sub {
    padding-left: 1.5rem;
    font-size: .85rem;
}

/* --- Page actions bar --- */
.page-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.page-actions-info {
    color: var(--text-secondary);
    margin-right: auto;
}

/* --- Filters bar --- */
.filters {
    padding: 1rem 1.25rem;
}
.filter-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: end;
}
.filter {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    min-width: 140px;
    flex: 1 1 140px;
}
.filter label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-tertiary);
    font-weight: 500;
}
.filter input[type=text],
.filter select {
    padding: .45rem .7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    font-family: inherit;
    font-size: .9rem;
}
.filter-actions {
    flex-direction: row;
    align-items: center;
    gap: .5rem;
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin: 1.5rem 0 1rem 0;
}
.pagination-info {
    color: var(--text-tertiary);
    font-size: .9rem;
}
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }

/* --- Form complejo (clients/_form.html) --- */
.form-card { padding: 1.5rem; }
.form-section {
    padding: 0 0 1.25rem 0;
    margin: 0 0 1.25rem 0;
    border-bottom: 1px solid var(--border);
}
.form-section:last-of-type { border-bottom: none; }
.form-section-title {
    font-size: 1rem;
    color: var(--text-primary);
    margin: 0 0 1rem 0;
}
.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.form-row .form-col { flex: 1 1 220px; min-width: 220px; }
.form-row .form-col-wide { flex: 1 1 100%; }
.form-help {
    margin: .35rem 0 0 0;
    color: var(--text-tertiary);
    font-size: .82rem;
}

/* Toggle styled */
.toggle-group { margin-bottom: 1rem; }
.toggle {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
    user-select: none;
}
.toggle input[type=checkbox] {
    width: 16px; height: 16px;
    accent-color: var(--primary);
}

.form-details summary {
    cursor: pointer;
    color: var(--primary);
    padding: .5rem 0;
    font-size: .9rem;
    font-weight: 500;
}
.form-details summary:hover { text-decoration: underline; }
.form-details[open] summary { margin-bottom: 1rem; }

.form-actions {
    display: flex;
    gap: .75rem;
    justify-content: flex-end;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* --- data-shown-when="minor": JS toggle visibility --- */
[data-shown-when="minor"] {
    display: none;
}
.is-minor [data-shown-when="minor"] {
    display: block;
}
.form-row.is-minor [data-shown-when="minor"] { display: block; }

/* --- Ficha cliente (show.html) --- */
.client-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.client-header-main { flex: 1 1 350px; }
.client-header-stage {
    text-align: right;
    min-width: 200px;
}
.client-header-stage .label {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-tertiary);
    margin: 0 0 .25rem 0;
}
.client-header-stage .value { margin: 0; }
.client-name {
    font-size: 1.5rem;
    margin: 0 0 .35rem 0;
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}
.client-meta {
    color: var(--text-secondary);
    font-size: .85rem;
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
}

.stage-changer {
    margin-top: .75rem;
    text-align: right;
}
.stage-changer summary {
    list-style: none;
    cursor: pointer;
    display: inline-block;
}
.stage-changer summary::-webkit-details-marker { display: none; }
.stage-form {
    margin-top: .5rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
    background: var(--bg-muted);
    padding: .75rem;
    border-radius: var(--radius-sm);
}
.stage-form select, .stage-form input[type=text] {
    padding: .4rem .6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: .85rem;
}

.client-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.25rem;
}
.client-col-main, .client-col-side {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}
@media (max-width: 900px) {
    .client-grid { grid-template-columns: 1fr; }
}

/* --- Definition list para datos de ficha --- */
.data-list {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: .35rem .75rem;
    margin: 0;
    font-size: .9rem;
}
.data-list dt {
    color: var(--text-tertiary);
    font-weight: 500;
}
.data-list dd { margin: 0; color: var(--text-primary); }

/* --- Tag cloud --- */
.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

/* --- Timeline (historial de cambios) --- */
.timeline {
    list-style: none;
    padding: 0;
    margin: 0;
}
.timeline-item {
    display: flex;
    gap: .75rem;
    padding-bottom: .85rem;
    margin-bottom: .85rem;
    border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.timeline-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: .5rem;
    flex-shrink: 0;
}
.timeline-body { flex: 1; font-size: .85rem; }
.timeline-line { color: var(--text-primary); }
.timeline-meta {
    color: var(--text-tertiary);
    font-size: .8rem;
    margin-top: .15rem;
}
.timeline-reason {
    margin-top: .25rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* --- Color dot (para listas de catálogo) --- */
.color-dot {
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
}

/* =============================================================================
   KANBAN
   ========================================================================== */

.kanban {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(260px, 1fr);
    gap: .75rem;
    overflow-x: auto;
    padding-bottom: 1rem;
}

.kanban-col {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    min-height: 70vh;
    box-shadow: var(--shadow-sm);
}

.kanban-col-header {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    background: var(--bg-muted);
    border-radius: var(--radius) var(--radius) 0 0;
}

.kanban-col-title {
    margin: 0;
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: .4rem;
}

.kanban-col-count {
    background: var(--bg-card);
    color: var(--text-secondary);
    padding: .1rem .5rem;
    border-radius: 100px;
    font-size: .75rem;
    font-weight: 500;
    border: 1px solid var(--border);
}

.kanban-col-body {
    flex: 1;
    padding: .65rem;
    display: flex;
    flex-direction: column;
    gap: .55rem;
    overflow-y: auto;
}

.kanban-col-body.drop-target {
    background: var(--primary-light);
    outline: 2px dashed var(--primary);
    outline-offset: -4px;
}

.kanban-col-empty {
    text-align: center;
    color: var(--text-tertiary);
    font-style: italic;
    padding: 1.5rem .5rem;
    font-size: .85rem;
}

.kanban-col-truncated {
    text-align: center;
    color: var(--text-tertiary);
    font-size: .8rem;
    padding: .5rem;
}

.kanban-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .65rem .75rem;
    cursor: grab;
    transition: box-shadow .15s, transform .1s;
    box-shadow: var(--shadow-sm);
}
.kanban-card:hover { box-shadow: var(--shadow); }
.kanban-card.dragging {
    opacity: .4;
    cursor: grabbing;
}

.kanban-card-head {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: .25rem;
}
.kanban-card-name {
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
    flex: 1;
}
.kanban-card-name:hover { color: var(--primary); text-decoration: underline; }

.kanban-card-meta {
    font-size: .75rem;
    color: var(--text-tertiary);
    margin-bottom: .15rem;
}
.kanban-card-meta code {
    color: var(--text-tertiary);
    font-size: .7rem;
}
.kanban-card-contact {
    font-size: .8rem;
    color: var(--text-secondary);
    margin-top: .15rem;
}
.kanban-card-foot {
    font-size: .7rem;
    color: var(--text-tertiary);
    margin-top: .25rem;
    text-align: right;
}

.kanban-status {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: .65rem 1rem;
    border-radius: var(--radius);
    z-index: 100;
    font-size: .85rem;
    border-left: 4px solid var(--success);
}
.kanban-status.is-error { border-left-color: var(--error); }


/* =============================================================================
   v0.2.1 — Reordenar stages (DnD en tabla)
   ========================================================================== */

tr.stage-row.dragging {
    opacity: 0.4;
    background: var(--primary-light, #EEF2FF);
}

tr.stage-row-active td.drag-handle:hover {
    color: var(--primary);
}

tr.stage-row-active:hover {
    background: var(--bg-muted);
}

