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

:root {
    --bg:       #F7F6F3;
    --surface:  #FFFFFF;
    --border:   rgba(0,0,0,0.09);
    --border-md:rgba(0,0,0,0.16);
    --text:     #1A1917;
    --muted:    #6B6A66;
    --hint:     #9E9C97;
    --accent:   #1B5E9C;
    --accent-bg:#E8F0FA;
    --accent-tx:#0C3D6E;
    --success:  #1A6B3A;
    --success-bg:#E6F4EC;
    --warn:     #7A4C00;
    --warn-bg:  #FEF3DB;
    --danger:   #8B1A1A;
    --danger-bg:#FDECEC;
    --radius-sm:6px;
    --radius:   10px;
    --radius-lg:14px;
    --shadow:   0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    font-size: 16px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:       #111110;
        --surface:  #1C1C1B;
        --border:   rgba(255,255,255,0.09);
        --border-md:rgba(255,255,255,0.18);
        --text:     #E8E6E1;
        --muted:    #9E9C97;
        --hint:     #6B6A66;
        --accent:   #5B9BD5;
        --accent-bg:#0C2A4A;
        --accent-tx:#A8CBEE;
        --success:  #5BBF84;
        --success-bg:#0A2B1A;
        --warn:     #E0A030;
        --warn-bg:  #2A1A00;
        --danger:   #E07070;
        --danger-bg:#2A0A0A;
        --shadow:   0 1px 3px rgba(0,0,0,0.3);
    }
}

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

/* ── Layout ───────────────────────────────────────────────── */
#login-screen {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1rem;
}
#app { display: none; max-width: 680px; margin: 0 auto; padding: 1rem 1rem 4rem; }
#app.visible { display: block; }

/* ── Login card ───────────────────────────────────────────── */
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem 1.75rem;
    width: 100%; max-width: 360px;
    box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.1rem; font-weight: 600; margin-bottom: .25rem; }
.login-card p  { font-size: .85rem; color: var(--muted); margin-bottom: 1.5rem; }

/* ── Header ───────────────────────────────────────────────── */
.app-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.25rem; padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.app-header h1 { font-size: 1.15rem; font-weight: 600; }
.app-header p  { font-size: .8rem; color: var(--muted); margin-top: 1px; }

/* ── Nav ──────────────────────────────────────────────────── */
.nav {
    display: flex; gap: 2px; margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    overflow-x: auto; scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav-btn {
    padding: 8px 12px; border: none; background: none;
    font-size: .8rem; color: var(--muted); cursor: pointer;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
    white-space: nowrap; font-weight: 500; transition: color .15s;
}
.nav-btn.active { color: var(--text); border-bottom-color: var(--text); }
.nav-btn:hover:not(.active) { color: var(--text); }

/* ── Cards ────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.125rem;
    margin-bottom: .875rem;
    box-shadow: var(--shadow);
}
.card-title {
    font-size: .7rem; font-weight: 600; color: var(--muted);
    text-transform: uppercase; letter-spacing: .06em; margin-bottom: .875rem;
}

/* ── Metrics ──────────────────────────────────────────────── */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 8px; margin-bottom: 1.25rem;
}
.metric {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}
.metric-label { font-size: .7rem; color: var(--muted); margin-bottom: 3px; }
.metric-value { font-size: 1.25rem; font-weight: 600; }
.metric-value.accent { color: var(--accent); }

/* ── Forms ────────────────────────────────────────────────── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: .75rem; color: var(--muted); font-weight: 500; }
input, select, textarea {
    width: 100%; padding: 7px 10px;
    border: 1px solid var(--border-md); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text);
    font-size: .875rem; font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(27,94,156,.15);
}
textarea { resize: vertical; min-height: 32px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: var(--radius-sm);
    font-size: .825rem; font-weight: 500; cursor: pointer;
    border: 1px solid transparent; font-family: inherit;
    transition: opacity .15s, background .15s;
}
.btn:active { opacity: .85; }
.btn-primary   { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-ghost     { background: none; border-color: var(--border-md); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-md); }
.btn-success   { background: var(--success-bg); color: var(--success); border-color: transparent; }
.btn-danger-sm { background: none; border-color: var(--border); color: var(--danger); padding: 4px 8px; font-size: .75rem; border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; }

/* ── Badges ───────────────────────────────────────────────── */
.badge { display: inline-block; font-size: .7rem; padding: 2px 8px; border-radius: 99px; font-weight: 500; }
.badge-ok   { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warn-bg);    color: var(--warn); }
.badge-due  { background: var(--danger-bg);  color: var(--danger); }

/* ── Sections ─────────────────────────────────────────────── */
.section { display: none; }
.section.active { display: block; }

/* ── Week block (asistencia) ──────────────────────────────── */
.week-block { border-bottom: 1px solid var(--border); padding: 10px 0; }
.week-block:last-child { border-bottom: none; }
.week-header { display: grid; grid-template-columns: 90px 1fr; gap: 8px; align-items: flex-start; }
.days-toggle { display: flex; gap: 4px; flex-wrap: wrap; }
.day-btn {
    width: 26px; height: 26px; border-radius: 50%;
    border: 1px solid var(--border-md); background: none;
    font-size: .65rem; font-weight: 600; cursor: pointer;
    color: var(--muted); transition: all .15s; font-family: inherit;
}
.day-btn.on { background: var(--accent-bg); color: var(--accent-tx); border-color: var(--accent); }
.obs-area { padding-left: 98px; margin-top: 8px; }
.obs-day { display: flex; align-items: flex-start; gap: 7px; margin-bottom: 5px; }
.obs-day-label { font-size: .7rem; color: var(--muted); min-width: 50px; padding-top: 7px; }

/* ── Total rows ───────────────────────────────────────────── */
.total-row { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 0; }
.total-label { font-size: .825rem; color: var(--muted); }
.total-value { font-size: .875rem; font-weight: 500; }
.total-final { font-size: 1.15rem; font-weight: 700; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

/* ── List rows ────────────────────────────────────────────── */
.list-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 0; border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row-info { font-size: .875rem; }
.list-row-sub  { font-size: .75rem; color: var(--muted); margin-top: 2px; }

/* ── Bar chart ────────────────────────────────────────────── */
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.bar-label { font-size: .7rem; color: var(--muted); width: 56px; text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; background: var(--bg); border-radius: 4px; height: 18px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill  { height: 100%; border-radius: 3px; transition: width .5s ease; }
.bar-val   { font-size: .7rem; color: var(--muted); min-width: 72px; text-align: right; flex-shrink: 0; }

/* ── Config rows ──────────────────────────────────────────── */
.config-row { display: flex; justify-content: space-between; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--border); }
.config-row:last-child { border-bottom: none; }
.config-label { font-size: .875rem; }
.config-sublabel { font-size: .72rem; color: var(--hint); margin-top: 2px; }
.config-input  { width: 130px; text-align: right; }

/* ── Month nav ────────────────────────────────────────────── */
.month-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 1rem; }
.month-nav span { font-size: .95rem; font-weight: 600; min-width: 130px; text-align: center; }

/* ── Diff chip ────────────────────────────────────────────── */
.diff-chip { display: none; font-size: .7rem; padding: 2px 7px; border-radius: 99px; background: var(--success-bg); color: var(--success); font-weight: 500; }

/* ── Toast ────────────────────────────────────────────────── */
#toast {
    position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(1rem);
    background: var(--text); color: var(--bg);
    padding: 8px 18px; border-radius: 99px; font-size: .8rem; font-weight: 500;
    opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; z-index: 100;
    white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Spinner ──────────────────────────────────────────────── */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border-md); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Historial ────────────────────────────────────────────── */
.hist-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); gap: 8px; }
.hist-row:last-child { border-bottom: none; }

/* ── Trend chip ───────────────────────────────────────────── */
.trend-chip { font-size: .7rem; padding: 2px 7px; border-radius: 99px; font-weight: 500; }
.trend-up { background: var(--success-bg); color: var(--success); }
.trend-dn { background: var(--danger-bg);  color: var(--danger); }
.trend-eq { background: var(--bg);         color: var(--muted); border: 1px solid var(--border); }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 480px) {
    .form-row { grid-template-columns: 1fr; }
    .metric-value { font-size: 1.1rem; }
    .obs-area { padding-left: 0; }
    .obs-day { flex-direction: column; gap: 3px; }
}

/* ── Empty states ─────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 2rem 1rem; }
.empty-icon  { font-size: 2rem; margin-bottom: .5rem; }
.empty-text  { font-size: .875rem; font-weight: 500; color: var(--text); margin-bottom: .25rem; }
.empty-sub   { font-size: .775rem; color: var(--muted); }
