/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --sidebar-w: 240px;
    --primary:   #1a3a2a;
    --primary-l: #254d36;
    --accent:    #2d9e5f;
    --accent-h:  #258a52;
    --danger:    #e74c3c;
    --warning:   #f39c12;
    --success:   #27ae60;
    --bg:        #e4e9ef;
    --card:      #ffffff;
    --border:    #d8dfe8;
    --text:      #2c3e50;
    --muted:     #6b7a8d;
    --radius:    10px;
    --shadow:    0 1px 4px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.07);
}

body { font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { text-decoration: none; color: inherit; }

/* ===== LAYOUT ===== */
.layout { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, #172e20 0%, #1e3a2a 100%);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 2px 0 16px rgba(0,0,0,.18);
}

.sidebar-logo {
    padding: 22px 18px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    color: #fff;
    font-size: 17px;
    letter-spacing: .3px;
}
.logo-icon { font-size: 20px; color: var(--accent); }
.logo-text strong { color: var(--accent); }

.sidebar-nav { flex: 1; padding: 10px 0 16px; }

.nav-section {
    padding: 16px 18px 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: rgba(255,255,255,.28);
    font-weight: 700;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    color: rgba(255,255,255,.68);
    font-size: 13.5px;
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
    margin: 1px 8px 1px 0;
    border-radius: 0 6px 6px 0;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active {
    background: rgba(45,158,95,.18);
    color: #5ecf8c;
    border-left-color: var(--accent);
    font-weight: 600;
}
.nav-icon { font-size: 10px; opacity: .55; }

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,.12);
}
.user-info { flex: 1; min-width: 0; }
.user-name { color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: rgba(255,255,255,.38); font-size: 11px; margin-top: 1px; }
.btn-logout { color: rgba(255,255,255,.35); font-size: 16px; padding: 4px; transition: color .15s; }
.btn-logout:hover { color: var(--danger); }

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 28px 32px;
    min-height: 100vh;
}

.page-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--border);
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
}
.page-header h1 {
    font-size: 21px;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-header h1::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 22px;
    background: var(--accent);
    border-radius: 2px;
}
.page-subtitle { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ===== CARDS ===== */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: none;
    padding: 20px 22px;
    margin-bottom: 20px;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 22px;
    background: linear-gradient(to right, #f5f9f7, #f9fbfa);
    border-bottom: 1px solid #e8ede9;
    /* Break out of card padding */
    margin: -20px -22px 18px;
    border-radius: var(--radius) var(--radius) 0 0;
}
.card-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-title::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 15px;
    background: var(--accent);
    border-radius: 2px;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all .15s;
    letter-spacing: .1px;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,.12); }
.btn:active { transform: translateY(0); }
.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-warning  { background: var(--warning); color: #fff; }
.btn-outline  { background: #fff; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f4f7f5; border-color: #c8d2ca; }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }
.btn-success { background: var(--success); color: #fff; }

/* ===== FILTERS BAR ===== */
.filters {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 22px;
    background: #f8fbf9;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
/* Inside a card after card-header: break out of card padding */
.card .filters {
    margin: -18px -22px 16px;
}

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
.card .table-wrap { margin-left: -22px; margin-right: -22px; margin-bottom: -20px; }
table { width: 100%; border-collapse: collapse; }
thead { background: #edf1ee; }
th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: #4a6357;
    border-bottom: 2px solid #d5ddd7;
    white-space: nowrap;
}
/* Encabezado fijo al hacer scroll dentro de un contenedor con overflow-y
   (ej. tablas largas dentro de un modal) */
.table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #edf1ee;
}
td { padding: 11px 14px; border-bottom: 1px solid #edf0ec; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) td { background: #f9fbfa; }
tbody tr:hover td { background: #f0f8f4 !important; }

/* ===== BADGES ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .2px;
}
.badge-green  { background: #d4edda; color: #1a6e3a; }
.badge-red    { background: #fde8e6; color: #b71c1c; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-orange { background: #fef3c7; color: #92400e; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-gray   { background: #f0f0f0; color: #555; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 12px; font-weight: 700; margin-bottom: 5px; color: #4a5568; letter-spacing: .2px; text-transform: uppercase; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #d1d9e0;
    border-radius: 7px;
    font-size: 13.5px;
    color: var(--text);
    background: #fff;
    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(45,158,95,.14);
}
input:disabled, select:disabled, textarea:disabled {
    background: #f4f6f5;
    color: var(--muted);
    cursor: not-allowed;
}
.form-row   { display: grid; grid-template-columns: 1fr 1fr;         gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr;     gap: 16px; }
.form-row-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 16px; }
.form-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; line-height: 1.5; }

/* Checkbox personalizado */
.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #f8fbf9;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    user-select: none;
    width: fit-content;
}
.check-row input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.check-row span { font-size: 13px; font-weight: 600; color: var(--text); }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    width: 500px;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    transform: translateY(-14px) scale(.98);
    transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f5f9f7;
    cursor: move;
    touch-action: none;
    flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 22px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: #fafafa; flex-shrink: 0; }

/* ===== ALERT ===== */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 4px solid;
}
.alert-success { background: #ecfdf5; color: #065f46; border-color: #10b981; }
.alert-error   { background: #fef2f2; color: #991b1b; border-color: #ef4444; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #f59e0b; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: #3b82f6; }

/* ===== LOGIN PAGE ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f2318 0%, var(--primary) 50%, #1e4d32 100%);
}
.login-card {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 24px 64px rgba(0,0,0,.3);
    padding: 40px 36px;
    width: 390px;
    max-width: 95vw;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h2 { font-size: 26px; font-weight: 800; color: var(--primary); }
.login-logo h2 span { color: var(--accent); }
.login-logo p { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ===== DASHBOARD STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px 20px 18px;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--accent);
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: '';
    position: absolute;
    top: -20px; right: -20px;
    width: 80px; height: 80px;
    background: var(--accent);
    opacity: .05;
    border-radius: 50%;
}
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .6px; }
.stat-value { font-size: 26px; font-weight: 800; margin: 8px 0 4px; color: var(--primary); line-height: 1; }
.stat-sub   { font-size: 11.5px; color: var(--muted); }

/* ===== CONFIRM DIALOG ===== */
.confirm-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
    opacity: 0; pointer-events: none;
    transition: opacity .15s;
}
.confirm-overlay.open { opacity: 1; pointer-events: all; }
.confirm-box {
    background: #fff;
    border-radius: 12px;
    padding: 28px 28px 22px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    text-align: center;
}
.confirm-icon  { font-size: 40px; margin-bottom: 12px; }
.confirm-title { font-size: 17px; font-weight: 700; margin-bottom: 6px; color: var(--primary); }
.confirm-msg   { color: var(--muted); font-size: 13px; margin-bottom: 22px; line-height: 1.5; }
.confirm-actions { display: flex; justify-content: center; gap: 12px; }

/* ===== AMOUNTS ===== */
.amount-positive { color: #b71c1c; font-weight: 700; }
.amount-negative { color: #1a6e3a; font-weight: 700; }
.amount-zero     { color: var(--muted); }

/* ===== SECTION LABEL ===== */
.section-label {
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .8px; color: var(--muted);
    margin: 8px 0 14px; padding-bottom: 8px;
    border-bottom: 1px dashed var(--border);
}

/* ===== NOTICE / INFO BOX ===== */
.notice-box {
    background: #eff6ff;
    border: 1.5px solid #bfdbfe;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 13px;
    color: #1e40af;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 16px;
}
.notice-box.notice-green {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
}
.notice-box.notice-orange {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

/* ===== UTILS ===== */
.text-muted   { color: var(--muted); }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.d-flex { display: flex; }
.gap-2 { gap: 8px; }
.actions { display: flex; gap: 6px; align-items: center; }
.empty-state { text-align: center; padding: 48px; color: var(--muted); }
.empty-state p { margin-top: 10px; font-size: 13px; }

/* ===== DATEPICKER ===== */
#dp-panel button:hover { background: #f0f8f4 !important; }
#dp-panel [data-act="today"]:hover { text-decoration: underline; }
#dp-panel [data-act="clear"]:hover { color: var(--danger) !important; }

/* ===== SEARCHABLE SELECT ===== */
.ss-wrap { position: relative; display: block; }
.ss-inp  { width: 100%; }
.ss-list {
    display: none;
    position: absolute;
    top: calc(100% + 2px);
    left: 0; right: 0;
    z-index: 999;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.12);
    max-height: 220px;
    overflow-y: auto;
    margin: 0; padding: 4px 0;
    list-style: none;
}
.ss-wrap.ss-open .ss-list { display: block; }
.ss-list li {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #374151;
    line-height: 1.3;
}
.ss-list li[data-val=""] { color: #9ca3af; font-style: italic; }
.ss-list li:hover { background: #eff6ff; color: #1e40af; }
.ss-list .ss-no { color: #9ca3af; font-style: italic; cursor: default; }
.ss-list .ss-no:hover { background: none; color: #9ca3af; }
.ss-list [data-val].ss-match { background: #f0faf5; border-left: 3px solid #2a9e5f; }
.ss-list [data-val].ss-match::before { content: "\2713  "; color: #2a9e5f; font-weight: 700; }
.ss-list [data-val].ss-match:hover { background: #e4f5ea; }

/* ===== PRINT ===== */
@media print {
    .no-print, .sidebar, .page-header, .alert { display: none !important; }
    body, .main-content { margin: 0 !important; padding: 0 !important; background: #fff !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}
