/* ============================================================
   ClientTrack — Estilos principales (estilo Apple)
   ============================================================ */

/* --- Variables --- */
:root {
    --bg-primary:     #F5F5F7;
    --bg-surface:     #FFFFFF;
    --bg-sidebar:     #1D1D1F;
    --accent:         #0071E3;
    --accent-hover:   #0077ED;
    --text-primary:   #1D1D1F;
    --text-secondary: #6E6E73;
    --text-muted:     #AEAEB2;
    --border:         #D2D2D7;
    --red:            #FF3B30;
    --orange:         #FF9500;
    --blue:           #007AFF;
    --green:          #34C759;
    --red-bg:         #FFF2F0;
    --orange-bg:      #FFF8EC;
    --blue-bg:        #EBF3FF;
    --green-bg:       #F0FFF4;

    --sidebar-width:  240px;
    --radius-sm:      10px;
    --radius-md:      14px;
    --radius-lg:      18px;
    --radius-pill:    980px;
    --shadow-sm:      0 2px 8px rgba(0,0,0,0.06);
    --shadow-md:      0 4px 20px rgba(0,0,0,0.10);
    --transition:     200ms ease;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    display: flex;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    padding: 32px 0;
    z-index: 100;
}

.sidebar-header {
    padding: 0 24px 32px;
}

.sidebar-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.sidebar-title {
    font-size: 22px;
    font-weight: 700;
    color: #FFFFFF;
    letter-spacing: -0.02em;
    margin-top: 4px;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 12px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 400;
    color: rgba(255,255,255,0.55);
    transition: all var(--transition);
    position: relative;
}

.sidebar-link:hover {
    color: rgba(255,255,255,0.8);
    background: rgba(255,255,255,0.06);
}

.sidebar-link.active {
    color: #FFFFFF;
    background: rgba(255,255,255,0.12);
    font-weight: 500;
}

.sidebar-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-badge {
    margin-left: auto;
    background: var(--red);
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    min-width: 20px;
    text-align: center;
}

.sidebar-footer {
    padding: 24px 24px 0;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: auto;
}

.sidebar-footer-text {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ============================================================
   CONTENIDO PRINCIPAL
   ============================================================ */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 40px;
    max-width: 1200px;
}

/* ============================================================
   TIPOGRAFÍA
   ============================================================ */
.page-header {
    margin-bottom: 32px;
}

.page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.page-title {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1.15;
}

.page-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.page-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.back-link {
    display: inline-block;
    font-size: 14px;
    color: var(--accent);
    margin-bottom: 8px;
    transition: opacity var(--transition);
}

.back-link:hover {
    opacity: 0.7;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 32px 0 16px;
}

.section-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.font-medium {
    font-weight: 500;
}

.text-muted {
    color: var(--text-muted);
}

.link {
    color: var(--accent);
    transition: opacity var(--transition);
}

.link:hover {
    opacity: 0.7;
}

/* ============================================================
   TARJETAS
   ============================================================ */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    margin-bottom: 20px;
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* ============================================================
   STATS GRID (Dashboard)
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: box-shadow var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
}

.stat-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.stat-card--danger .stat-value { color: var(--red); }
.stat-card--warning .stat-value { color: var(--orange); }
.stat-card--info .stat-value { color: var(--blue); }
.stat-card--success .stat-value { color: var(--green); }

/* ============================================================
   TABLAS
   ============================================================ */
.table-wrapper {
    overflow-x: auto;
}

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

.table th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 14px 16px;
    font-size: 14px;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    vertical-align: middle;
}

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

.table tbody tr:hover {
    background: rgba(0,0,0,0.02);
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    white-space: nowrap;
}

.badge--danger {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid #FFCCC7;
}

.badge--warning {
    background: var(--orange-bg);
    color: var(--orange);
    border: 1px solid #FFD591;
}

.badge--info {
    background: var(--blue-bg);
    color: var(--blue);
    border: 1px solid #9EC5FE;
}

.badge--success {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid #A7F3C4;
}

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: #FFFFFF;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: rgba(0,0,0,0.05);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(0,0,0,0.08);
}

.btn-danger {
    background: var(--red-bg);
    color: var(--red);
}

.btn-danger:hover {
    background: var(--red);
    color: #FFFFFF;
}

.btn-small {
    font-size: 12px;
    padding: 5px 12px;
}

/* ============================================================
   FORMULARIOS
   ============================================================ */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group--full {
    grid-column: 1 / -1;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.input {
    font-family: inherit;
    font-size: 15px;
    background: rgba(0,0,0,0.04);
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    transition: all var(--transition);
    width: 100%;
}

.input:focus {
    outline: none;
    border-color: var(--accent);
    background: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(0,113,227,0.12);
}

.input-error {
    border-color: var(--red) !important;
}

.textarea {
    resize: vertical;
    min-height: 80px;
}

select.input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%236E6E73' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.form-error {
    font-size: 12px;
    color: var(--red);
    font-weight: 500;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
}

.form-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.inline-form {
    display: inline;
}

/* ============================================================
   BUSCADOR
   ============================================================ */
.search-box {
    margin-bottom: 24px;
}

.search-input {
    max-width: 400px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none'%3E%3Ccircle cx='7' cy='7' r='5.5' stroke='%23AEAEB2' stroke-width='1.5'/%3E%3Cpath d='M11 11l3.5 3.5' stroke='%23AEAEB2' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 14px center;
    padding-left: 40px;
}

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

.client-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
    cursor: pointer;
}

.client-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.client-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.client-card-name {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.client-card-company {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
    display: block;
}

.client-card-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
}

.client-card-detail {
    font-size: 13px;
    color: var(--text-secondary);
}

.client-card-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid rgba(0,0,0,0.04);
}

.client-card-services {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Status dot */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 6px;
}

.status-dot--expired  { background: var(--red); box-shadow: 0 0 6px rgba(255,59,48,0.4); }
.status-dot--urgent   { background: var(--orange); box-shadow: 0 0 6px rgba(255,149,0,0.4); }
.status-dot--upcoming { background: var(--blue); }
.status-dot--ok       { background: var(--green); }

/* ============================================================
   DETALLE CLIENTE
   ============================================================ */
.client-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.detail-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}

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

/* ============================================================
   SERVICIOS LISTA
   ============================================================ */
.services-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.service-row {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 16px 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}

.service-row:hover {
    box-shadow: var(--shadow-md);
}

.service-row-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.service-type-icon {
    font-size: 22px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.03);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.service-row-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.service-row-name {
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.service-row-type {
    font-size: 12px;
    color: var(--text-secondary);
}

.service-row-center {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.service-row-date {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.service-row-right {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

.service-row-price {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    min-width: 70px;
    text-align: right;
}

/* Toggle pagado */
.btn-toggle-paid {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background var(--transition);
    line-height: 1;
}

.btn-toggle-paid:hover {
    background: rgba(0,0,0,0.05);
}

/* ============================================================
   ALERTAS
   ============================================================ */
.alert-section {
    margin-bottom: 32px;
}

.alert-section-header {
    margin-bottom: 12px;
}

.alert-section-title {
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
    font-size: 15px;
}

.empty-state .btn {
    margin-top: 16px;
}

.empty-state-small {
    padding: 16px 24px;
    color: var(--text-muted);
    font-size: 14px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

/* ============================================================
   LOGIN
   ============================================================ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.login-container {
    width: 100%;
    max-width: 400px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 40px;
    box-shadow: var(--shadow-md);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-top: 4px;
}

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

.login-error {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid #FFCCC7;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 20px;
    text-align: center;
}

.login-btn {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    margin-top: 8px;
}

/* User menu en sidebar */
.sidebar-user {
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-user-name {
    font-size: 13px;
    color: rgba(255,255,255,0.55);
}

.sidebar-logout {
    font-size: 12px;
    color: rgba(255,255,255,0.35);
    transition: color var(--transition);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
}

.sidebar-logout:hover {
    color: #FFFFFF;
}

/* ============================================================
   FACTURACIÓN ANUAL
   ============================================================ */

.stats-grid--billing {
    grid-template-columns: repeat(2, 1fr);
    margin-bottom: 32px;
}

.stat-card--success {
    border-left: 4px solid #34C759;
}

/* ============================================================
   ANIMACIONES
   ============================================================ */
.fade-in {
    animation: fadeInUp 0.3s ease both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Delay escalonado para listas */
.fade-in:nth-child(1) { animation-delay: 0s; }
.fade-in:nth-child(2) { animation-delay: 0.03s; }
.fade-in:nth-child(3) { animation-delay: 0.06s; }
.fade-in:nth-child(4) { animation-delay: 0.09s; }
.fade-in:nth-child(5) { animation-delay: 0.12s; }
.fade-in:nth-child(6) { animation-delay: 0.15s; }
.fade-in:nth-child(7) { animation-delay: 0.18s; }
.fade-in:nth-child(8) { animation-delay: 0.21s; }
.fade-in:nth-child(9) { animation-delay: 0.24s; }
.fade-in:nth-child(10) { animation-delay: 0.27s; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
    .main-content {
        padding: 24px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        padding: 0;
        bottom: 0;
        top: auto;
        z-index: 100;
    }

    .sidebar-header,
    .sidebar-footer {
        display: none;
    }

    .sidebar-nav {
        flex-direction: row;
        justify-content: space-around;
        width: 100%;
        padding: 8px 0;
        gap: 0;
    }

    .sidebar-link {
        flex-direction: column;
        font-size: 11px;
        padding: 8px 16px;
        gap: 4px;
    }

    .main-content {
        margin-left: 0;
        padding: 20px 16px 80px;
    }

    .page-title {
        font-size: 28px;
    }

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

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

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

    .service-row {
        flex-wrap: wrap;
    }

    .service-row-right {
        width: 100%;
        justify-content: flex-end;
        padding-top: 8px;
        border-top: 1px solid rgba(0,0,0,0.04);
        margin-top: 4px;
    }

    .page-header-row {
        flex-direction: column;
    }

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

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