@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #4F46E5;
    --primary-dark: #4338CA;
    --primary-light: #EEF2FF;
    --bg: #F9FAFB;
    --surface: #FFFFFF;
    --border: #E5E7EB;
    --text: #111827;
    --muted: #6B7280;
    --success: #059669;
    --success-bg: #ECFDF5;
    --warning: #D97706;
    --warning-bg: #FFFBEB;
    --danger: #DC2626;
    --danger-bg: #FEF2F2;
    --sidebar-bg: #111827;
    --sidebar-text: #9CA3AF;
    --sidebar-border: #1F2937;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: 'Inter', sans-serif; letter-spacing: -0.02em; }

/* --- Login --- */
.login-page {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 15% 20%, #1e2347 0%, #0b0d1a 60%);
}

.login-box {
    background: var(--surface);
    padding: 2.75rem 2.5rem;
    border-radius: 16px;
    width: 340px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.4);
}

.login-box h1 {
    margin: 0 0 0.25rem;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text);
}

.login-box .subtitle {
    margin: 0 0 1.75rem;
    color: var(--muted);
    font-size: 0.88rem;
}

.login-box label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    margin: 1rem 0 0.35rem;
    color: var(--muted);
}

.login-box input {
    width: 100%;
    padding: 0.65rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.login-box button {
    width: 100%;
    margin-top: 1.75rem;
    padding: 0.75rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.login-box button:hover { background: var(--primary-dark); }
.login-box button:active { transform: scale(0.98); }

.error {
    background: var(--danger-bg);
    color: var(--danger);
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
}

/* --- Sidebar --- */
.sidebar {
    width: 244px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    color: #fff;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    padding: 0 0.6rem 1.75rem;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.87rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }

.nav-item.active { background: var(--primary); color: #fff; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding-top: 1rem;
    border-top: 1px solid var(--sidebar-border);
    margin-top: 1rem;
}

.user-avatar, .avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.avatar-sm { width: 26px; height: 26px; font-size: 0.62rem; }

.user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.user-name {
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role { color: var(--sidebar-text); font-size: 0.7rem; text-transform: capitalize; }

.logout-btn { color: var(--sidebar-text); display: flex; transition: color 0.15s ease; }
.logout-btn svg { width: 18px; height: 18px; }
.logout-btn:hover { color: #f87171; }

/* --- Layout --- */
.container {
    flex: 1;
    max-width: 1240px;
    padding: 2.25rem 2.5rem 3rem;
    min-width: 0;
}

h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 0.3rem; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 2rem 0 0.9rem; }

.muted { color: var(--muted); font-size: 0.85rem; }

/* --- Page head --- */
.page-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.page-head h1 { margin: 0; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
}
.back-link:hover { color: var(--primary); }

.section-label {
    margin-top: 2.25rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
}

/* --- KPI cards --- */
.kpis { display: flex; gap: 1rem; flex-wrap: wrap; margin: 1.5rem 0 1.75rem; }

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.35rem;
    min-width: 170px;
    flex: 1;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.kpi:hover { box-shadow: 0 8px 20px rgba(17,24,39,0.06); transform: translateY(-1px); }

.kpi-value { display: block; font-size: 1.7rem; font-weight: 800; color: var(--text); line-height: 1.15; }

.kpi-label {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-top: 0.3rem;
    font-weight: 600;
}

/* --- Chart cards --- */
.chart-row { display: flex; gap: 1.25rem; flex-wrap: wrap; margin: 1.5rem 0 2rem; }

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    flex: 1;
    min-width: 300px;
}

.chart-card h3 { margin: 0 0 1rem; font-size: 0.9rem; font-weight: 700; }

.chart-card canvas { max-height: 260px; }

/* --- Toolbar (clientes) --- */
.toolbar { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }

.search-form { display: flex; gap: 0.5rem; align-items: center; }

.search-form input {
    padding: 0.55rem 0.8rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    min-width: 240px;
}

.search-form input:focus { outline: none; border-color: var(--primary); }

.search-form button {
    padding: 0.55rem 1.1rem;
    background: var(--text);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
}

.clear-link { font-size: 0.8rem; color: var(--muted); text-decoration: none; align-self: center; }
.clear-link:hover { color: var(--primary); }

/* --- Client link / avatars --- */
.client-link {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.88rem;
}
.client-link:hover { color: var(--primary); }
.client-link:hover .avatar-sm { box-shadow: 0 0 0 2px var(--primary-light); }

/* --- Date navigation (operaciones) --- */
.date-nav { display: flex; align-items: center; gap: 1.2rem; margin-bottom: 0.75rem; flex-wrap: wrap; }

.date-nav a { color: var(--primary); text-decoration: none; font-size: 0.85rem; font-weight: 600; }
.date-nav a:hover { text-decoration: underline; }

.date-form input { padding: 0.45rem 0.7rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: 0.88rem; }

.date-today { background: var(--primary-light); color: var(--primary-dark); padding: 0.3rem 0.8rem; border-radius: 20px; font-weight: 600; font-size: 0.8rem; text-decoration: none; }

.obs-cell {
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}
.obs-cell.expanded { white-space: normal; max-width: 320px; }

/* --- Cards (dashboard) --- */
.cards { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1.5rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    flex: 1;
    min-width: 200px;
    text-decoration: none;
    color: var(--text);
    transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.card:hover { box-shadow: 0 10px 24px rgba(17,24,39,0.08); transform: translateY(-2px); border-color: var(--primary); }

.card h2 { margin: 0 0 0.4rem; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.85rem; }

/* --- Forms --- */
.inline-form, .op-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.inline-form input, .op-form input, .op-form select {
    padding: 0.55rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.87rem;
    transition: border-color 0.15s ease;
}

.inline-form input:focus, .op-form input:focus, .op-form select:focus {
    outline: none;
    border-color: var(--primary);
}

.inline-form button, .op-form button {
    padding: 0.55rem 1.25rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.87rem;
    font-weight: 600;
    transition: background 0.15s ease, transform 0.1s ease;
}

.inline-form button:hover, .op-form button:hover { background: var(--primary-dark); }
.inline-form button:active, .op-form button:active { transform: scale(0.98); }

form.inline { display: inline; }

.btn-small {
    padding: 0.32rem 0.7rem;
    font-size: 0.78rem;
    background: var(--success);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s ease;
}
.btn-small:hover { background: #047857; }

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 2rem;
    font-variant-numeric: tabular-nums;
}

th, td {
    text-align: left;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.84rem;
    white-space: nowrap;
}

th {
    background: #F9FAFB;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.7rem;
    position: sticky;
    top: 0;
}

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

tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: var(--primary-light); }

.container > table, main > table { overflow-x: auto; display: block; }

.badge {
    padding: 0.22rem 0.6rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
}

.badge-pendiente { background: var(--warning-bg); color: var(--warning); }
.badge-confirmada { background: var(--success-bg); color: var(--success); }

@media (max-width: 900px) {
    body { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; align-items: center; padding: 0.75rem 1rem; }
    .sidebar-brand { display: none; }
    .sidebar-nav { flex-direction: row; flex: 1; overflow-x: auto; }
    .nav-item span { display: none; }
    .sidebar-user { border: none; margin: 0; padding: 0; }
    .user-meta { display: none; }
    .container { padding: 1.5rem; }
}
