/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
    color-scheme: light;
    --font-ui:   'Outfit', sans-serif;
    --font-mono: 'DM Mono', monospace;

    /* Palette — warm paper */
    --bg:               #fdf9f5;
    --bg-subtle:        #f7f3ee;
    --bg-hover:         #f0ebe4;
    --sidebar-bg:       #f2ede7;
    --sidebar-border:   #e6e0d8;
    --border:           #e6e0d8;
    --border-strong:    #cdc6bc;
    --text:             #1a1815;
    --text-secondary:   #6b645c;
    --text-muted:       #a09890;
    --cell-rn-bg:       #f0ebe4;
    --cell-new-bg:      #fdf8f2;
    --row-hover:        #faf5ef;
    --focus-ring:       inset 0 0 0 1.5px #1a1815;
    --focus-bg:         #fff;

    /* Accents */
    --accent:           #1a1815;
    --accent-fg:        #fdf9f5;
    --green:            #3d8c5e;
    --red:              #b54a4a;

    /* Layout */
    --sidebar-w:        192px;
    --sidebar-collapsed-w: 48px;
    --header-h:         52px;
}

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

body {
    font-family: var(--font-ui);
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ── App shell ──────────────────────────────────────────────────────────────── */
.app-shell {
    min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 10;
}

.sidebar-logo {
    padding: 14px 14px 14px 20px;
    font-family: var(--font-ui);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.04em;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-toggle {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, color 0.1s;
    padding: 0;
}
.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.sidebar-logo-icon {
    display: none;
    cursor: pointer;
    border-radius: 7px;
    flex-shrink: 0;
}

.sidebar-logo-text > span {
    display: inline-block;
    width: 7px; height: 7px;
    background: var(--accent);
    border-radius: 50%;
    margin-left: 2px;
    vertical-align: middle;
    position: relative;
    top: -1px;
}

.nav-section {
    padding: 16px 12px 8px;
}

.nav-label {
    display: block;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0 8px;
    margin-bottom: 6px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 8px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 400;
    color: var(--text-secondary);
    transition: background 0.1s, color 0.1s;
    margin-bottom: 1px;
}

.sidebar-nav a:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.sidebar-nav a.is-active {
    background: var(--accent);
    color: var(--accent-fg);
    font-weight: 500;
}

.sidebar-nav a.is-active .nav-icon { opacity: 1; }

.nav-icon {
    font-size: 14px;
    opacity: 0.5;
    flex-shrink: 0;
    line-height: 1;
}

.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    font-size: 11px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    letter-spacing: 0.01em;
}

/* ── Main content ───────────────────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}

/* ── Page header ────────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 28px 0;
    flex-shrink: 0;
}

.page-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.03em;
    color: var(--text);
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── Month navigation (tab style) ───────────────────────────────────────────── */
.month-nav {
    display: flex;
    gap: 0;
    padding: 14px 28px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.month-tab {
    padding: 7px 12px;
    font-family: var(--font-ui);
    font-size: 12.5px;
    font-weight: 400;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    margin-bottom: -1px;
    transition: color 0.1s, background 0.1s;
    white-space: nowrap;
}

.month-tab:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.month-tab.month-empty {
    opacity: 0.35;
}

.month-tab.active {
    color: var(--text);
    font-weight: 500;
    background: var(--bg);
    border-color: var(--border);
    border-bottom-color: var(--bg);
    position: relative;
    z-index: 1;
}

/* ── Sheet wrapper ──────────────────────────────────────────────────────────── */
.sheet-wrap {
    padding: 0 28px 32px;
}

/* ── Compras table (spreadsheet) ────────────────────────────────────────────── */
.compras-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 12.5px;
}

/* Sticky header */
.compras-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--cell-rn-bg);
    border: 1px solid var(--border);
    border-top: none;
    padding: 6px 10px;
    font-family: var(--font-ui);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    white-space: nowrap;
    text-align: left;
}

.compras-table thead th.cell-number { text-align: right; }

/* Row number column */
.col-rn {
    width: 38px;
    text-align: center !important;
    padding: 0 !important;
    border-right: 1px solid var(--border-strong) !important;
}

/* All cells */
.compras-table td {
    border: 1px solid var(--border);
    padding: 0;
    vertical-align: middle;
}

/* Row number cells */
.cell-rn {
    background: var(--cell-rn-bg);
    text-align: center;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 400;
    padding: 6px 0;
    width: 38px;
    min-width: 38px;
    border-right: 1px solid var(--border-strong) !important;
    user-select: none;
}

/* Inputs inside cells */
.compras-table input[type="text"]:not([inputmode]),
.compras-table input[type="text"]:not([inputmode])::placeholder {
    text-transform: uppercase;
}
.compras-table input[type="text"],
.compras-table input[type="date"] {
    width: 100%;
    border: none;
    outline: none;
    padding: 7px 10px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: #1a1815;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
}

/* Money cell wrapper */
.money-wrap {
    display: flex;
    align-items: center;
}
.compras-table .money-wrap input {
    flex: 1;
    min-width: 0;
}
.euro-sym {
    padding: 0 8px 0 0;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    pointer-events: none;
    user-select: none;
    flex-shrink: 0;
}
/* Static money value (tfoot, cell-total) */
.money-static {
    flex: 1;
    text-align: right;
    padding: 0 10px 0 10px;
    font-variant-numeric: tabular-nums;
}

/* Select inside cells */
.compras-table select.cell-select {
    width: 100%;
    border: none;
    outline: none;
    padding: 7px 10px;
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: #1a1815;
    background: transparent;
    appearance: none;
    cursor: pointer;
}

.compras-table select.cell-select:focus {
    background: var(--focus-bg);
    box-shadow: var(--focus-ring);
    position: relative;
    z-index: 1;
}

.compras-table input:focus {
    background: var(--focus-bg);
    box-shadow: var(--focus-ring);
    position: relative;
    z-index: 1;
}

.compras-table input[data-saving] { opacity: 0.4; }
.compras-table input.cell-error   { box-shadow: inset 0 0 0 1.5px var(--red); }

/* Number-aligned columns */
.cell-number {
    text-align: right;
}
.cell-number input {
    text-align: right;
}

/* Non-input total cell */
.cell-total {
    padding: 0;
    font-weight: 500;
    color: var(--text);
}

/* Row hover */
.compras-table tbody tr.data-row:hover td {
    background: var(--row-hover);
}
.compras-table tbody tr.data-row:hover .cell-rn {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

/* CSS counter for row numbers */
.compras-table tbody {
    counter-reset: rownum;
}
.compras-table tbody tr.data-row {
    counter-increment: rownum;
}
.compras-table tbody tr.data-row .cell-rn::before {
    content: counter(rownum);
}

/* ── New row ────────────────────────────────────────────────────────────────── */
.new-row td {
    background: var(--cell-new-bg);
    border-style: dashed;
    border-color: var(--border);
}

.new-row .cell-rn {
    background: var(--cell-new-bg);
    color: var(--text-muted);
    font-size: 16px;
    line-height: var(--row-h);
    border-style: dashed;
}


/* ── Totals footer ──────────────────────────────────────────────────────────── */
.totals-row td {
    background: var(--bg-subtle);
    border-top: 1.5px solid var(--border-strong);
    padding: 7px 10px;
    font-family: var(--font-ui);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
}

.totals-row .cell-number {
    padding-left: 0;
    padding-right: 0;
}

.totals-row .cell-rn {
    background: var(--cell-rn-bg);
}

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-notice {
    padding: 28px 16px;
    text-align: center;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 13px;
    font-style: italic;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.cell-actions {
    width: 38px;
    text-align: center;
    padding: 0 !important;
}

.btn-add {
    width: 22px; height: 22px;
    border: 1.5px solid var(--border-strong);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.btn-add:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-fg);
}

.btn-delete {
    width: 22px; height: 22px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: transparent;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s, color 0.1s;
}
.data-row:hover .btn-delete {
    color: var(--text-muted);
}
.btn-delete:hover {
    background: #f9eded;
    color: var(--red) !important;
}

/* ── Year select ────────────────────────────────────────────────────────────── */
.year-form select {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-family: var(--font-ui);
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    appearance: none;
    padding-right: 24px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23a09890' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}
.year-form select:focus { outline: none; box-shadow: 0 0 0 1.5px var(--accent); }

.btn-secondary {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--bg);
    color: var(--text-secondary);
    text-decoration: none;
    font-family: var(--font-ui);
    font-size: 12.5px;
    font-weight: 400;
    transition: background 0.1s, color 0.1s;
    white-space: nowrap;
}
.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text);
}

/* ── Column widths ──────────────────────────────────────────────────────────── */
.col-rn      { width: 38px; }
.col-amount  { width: 100px; }
.col-fecha   { width: 120px; }
.col-total   { width: 100px; }
.col-actions { width: 36px; }

/* ── Collapsed sidebar ──────────────────────────────────────────────────────── */
.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-w);
}
.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-w);
}
.sidebar-collapsed .nav-text,
.sidebar-collapsed .nav-label,
.sidebar-collapsed .sidebar-logo-text,
.sidebar-collapsed .sidebar-toggle {
    display: none;
}
.sidebar-collapsed .sidebar-logo-icon {
    display: block;
}
.sidebar-collapsed .sidebar-logo {
    justify-content: center;
    padding: 14px 0;
}
.sidebar-collapsed .nav-section {
    padding: 16px 6px 8px;
}
.sidebar-collapsed .sidebar-nav a {
    justify-content: center;
    padding: 8px;
    gap: 0;
}
.sidebar-collapsed .nav-icon {
    opacity: 0.7;
    font-size: 15px;
}
.sidebar-collapsed .sidebar-nav a.is-active .nav-icon {
    opacity: 1;
}
.sidebar-collapsed .sidebar-footer {
    padding: 16px 0;
    text-align: center;
}

/* Animate width transition */
.sidebar       { transition: width 0.2s ease; }
.main-content  { transition: margin-left 0.2s ease; }

/* ── Chart dashboard ────────────────────────────────────────────────────────── */
.chart-dashboard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 24px 28px 40px;
}

.chart-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chart-card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.chart-card-title {
    font-family: var(--font-ui);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
}

.chart-card-year {
    font-family: var(--font-ui);
    font-size: 12px;
    color: var(--text-muted);
}

.chart-canvas-wrap {
    height: 200px;
    position: relative;
}

.chart-stats {
    display: flex;
    align-items: center;
    gap: 20px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
}

.chart-stat {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.chart-stat-label {
    font-family: var(--font-ui);
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.chart-stat-value {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: -0.02em;
}

.chart-stat-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    flex-shrink: 0;
}

.chart-card--wide {
    grid-column: 1 / -1;
}

.chart-canvas-wrap--tall {
    height: 240px;
}

.chart-row-3 {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.mini-donut-wrap {
    height: 140px;
    position: relative;
}

.mini-legend {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    max-height: 180px;
    margin-right: -24px;
    padding-right: 24px;
}

.mini-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-ui);
    font-size: 12px;
    color: var(--text);
}

.mini-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.mini-legend-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
}

.mini-legend-pct {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 28px;
    text-align: right;
}

.mini-legend-val {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
    min-width: 60px;
    text-align: right;
}

/* ── Donut ──────────────────────────────────────────────────────────────────── */
.donut-wrap {
    height: 180px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.donut-center {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    pointer-events: none;
}

.donut-center-label {
    font-family: var(--font-ui);
    font-size: 10.5px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.donut-center-value {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

/* ── Concepto list ──────────────────────────────────────────────────────────── */
.concepto-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    max-height: 260px;
    margin-right: -24px;
    padding-right: 24px;
}

.concepto-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: 12.5px;
}

.concepto-item:last-child { border-bottom: none; }

.concepto-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.concepto-name {
    flex: 1;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.concepto-pct {
    color: var(--text-muted);
    font-size: 11.5px;
    width: 32px;
    text-align: right;
    flex-shrink: 0;
}

.concepto-total {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text);
    text-align: right;
    flex-shrink: 0;
    min-width: 80px;
}

/* ── Confirm modal ──────────────────────────────────────────────────────────── */
#confirm-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.10);
}
#confirm-modal.is-open {
    display: block;
}
.modal-dialog {
    /* Default: centered (no anchor). JS overrides position when anchor is given. */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border: 1.5px solid var(--text);
    border-radius: 8px;
    padding: 22px 24px 18px;
    width: 270px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
}
.modal-message {
    font-family: var(--font-ui);
    font-size: 13.5px;
    color: var(--text);
    line-height: 1.55;
    text-align: center;
}
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.modal-btn {
    padding: 7px 18px;
    border: 1.5px solid var(--text);
    border-radius: 5px;
    font-family: var(--font-ui);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.modal-btn-cancel {
    background: #fff;
    color: var(--text);
}
.modal-btn-cancel:hover  { background: var(--bg-subtle); }
.modal-btn-confirm {
    background: var(--text);
    color: #fff;
}
.modal-btn-confirm:hover { background: #333; }

/* ── Home ── */
.module-grid {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.module-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 28px 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.1s, border-color 0.1s;
    min-width: 120px;
}

.module-card:hover {
    background: var(--bg-subtle);
    border-color: var(--border-strong);
}

.module-card-icon { font-size: 28px; line-height: 1; }
.module-card-name { color: var(--text-secondary); }
