/* ===== Reset & base ===== */
*,*::before,*::after { box-sizing: border-box; }
body, h1, h2, h3, h4, p, ul, ol, figure, table { margin: 0; padding: 0; }
ul { list-style: none; }
a { color: inherit; text-decoration: none; }

:root {
    --bg:        #f5f7fb;
    --card:      #ffffff;
    --ink:       #1a2233;
    --ink-soft:  #5b6478;
    --line:      #e4e7ee;
    --brand:     #5b3df5;
    --brand-2:   #7b5ef7;
    --green:     #16a34a;
    --red:       #dc2626;
    --amber:     #d97706;
    --blue:      #2563eb;
    --gray-50:   #f9fafb;
    --gray-100:  #f3f4f6;
    --gray-200:  #e5e7eb;
    --gray-900:  #111827;
    --shadow:    0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.45;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Topbar ===== */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    background: var(--card);
    padding: 12px 24px;
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
    flex-wrap: wrap;
}
.brand a { display: flex; flex-direction: column; align-items: flex-start; text-decoration: none; }
.brand .brand-img { height: 42px; width: auto; display: block; }
.brand .logo {
    font-weight: 800;
    font-size: 20px;
    letter-spacing: -.5px;
    color: var(--brand);
}
.brand .sub { font-size: 11px; color: var(--ink-soft); margin-top: 4px; }

.mainnav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.mainnav a {
    padding: 8px 14px;
    border-radius: 8px;
    color: var(--ink-soft);
    font-weight: 500;
    transition: all .15s;
}
.mainnav a:hover { background: var(--gray-100); color: var(--ink); }
.mainnav a.on { background: var(--brand); color: #fff; }

.user { display: flex; align-items: center; gap: 12px; }
.user span { color: var(--ink-soft); font-size: 13px; }

/* ===== Main container ===== */
.container {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
    flex: 1;
}

/* ===== Cards & sections ===== */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.card-head h2 { font-size: 18px; }

.page-title {
    font-size: 22px;
    margin-bottom: 4px;
}
.page-sub {
    color: var(--ink-soft);
    margin-bottom: 20px;
}

/* ===== KPIs ===== */
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px,1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.kpi {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 18px;
    box-shadow: var(--shadow);
}
.kpi .label { color: var(--ink-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.kpi .sub   { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.kpi.green  { border-top: 3px solid var(--green); }
.kpi.red    { border-top: 3px solid var(--red); }
.kpi.amber  { border-top: 3px solid var(--amber); }
.kpi.blue   { border-top: 3px solid var(--blue); }
.kpi.brand  { border-top: 3px solid var(--brand); }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.data th, table.data td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
table.data thead th {
    background: var(--gray-50);
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    border-bottom: 2px solid var(--line);
    white-space: nowrap;
}
table.data tbody tr:hover { background: var(--gray-50); }
table.data td.num, table.data th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;   /* evita que $ y el monto se rompan en dos líneas */
}
table.data td.center, table.data th.center { text-align: center; }

/* ----- Sortable headers ----- */
table.data thead th.sortable {
    cursor: pointer;
    user-select: none;
    padding-right: 22px;   /* espacio para el indicador */
    position: relative;
    transition: color .15s ease;
}
table.data thead th.sortable:hover {
    color: var(--brand);
    background: #eef2f7;
}
table.data thead th.sortable::after {
    content: '⇅';
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    opacity: .35;
    color: inherit;
}
table.data thead th.sort-asc::after  { content: '↑'; opacity: 1; color: var(--brand); font-size: 12px; font-weight: 700; }
table.data thead th.sort-desc::after { content: '↓'; opacity: 1; color: var(--brand); font-size: 12px; font-weight: 700; }
table.data thead th.sort-asc, table.data thead th.sort-desc { color: var(--brand); }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: var(--gray-100);
    color: var(--ink-soft);
}
.badge.green  { background: #dcfce7; color: #166534; }
.badge.red    { background: #fee2e2; color: #991b1b; }
.badge.amber  { background: #fef3c7; color: #92400e; }
.badge.blue   { background: #dbeafe; color: #1e40af; }
.badge.purple { background: #ede9fe; color: #5b21b6; }
.badge.brand  { background: #ede9fe; color: var(--brand); }
.badge.gray   { background: var(--gray-200); color: var(--ink-soft); }

/* ===== Buttons & forms ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink);
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    transition: all .15s;
    text-decoration: none;
}
.btn:hover  { background: var(--gray-50); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--gray-100); color: var(--ink); }
.btn-danger  { background: var(--red); color: #fff; border-color: var(--red); }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], input[type="file"],
select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    background: #fff;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(91,61,245,.12);
}

.form-row {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}
.form-row label { color: var(--ink-soft); font-weight: 500; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px,1fr));
    gap: 12px 16px;
}
.form-grid .field label {
    display: block;
    font-size: 12px;
    color: var(--ink-soft);
    margin-bottom: 4px;
    font-weight: 500;
}

/* ===== Login page ===== */
.login-page {
    min-height: 100vh;
    margin: 0;
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    background: #f4f5fa;
    overflow: hidden;
}
.login-hero {
    position: relative;
    background-image: linear-gradient(rgba(15, 23, 42, .35), rgba(15, 23, 42, .55)),
                      url('img/lobby.jpg');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 40px;
    color: #fff;
}
.login-hero .spaces-badge {
    background: rgba(255,255,255,.95);
    padding: 10px 18px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.login-hero .spaces-badge img { height: 22px; display: block; }
.login-hero h2 {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -.5px;
    max-width: 460px;
    line-height: 1.25;
    margin: 0 0 8px;
    text-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.login-hero p {
    font-size: 14px;
    opacity: .9;
    max-width: 420px;
    margin: 0;
    text-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.login-side {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 32px;
    background: #fff;
}
.login-box {
    width: 100%;
    max-width: 380px;
}
.login-box .brand-logo {
    text-align: center;
    margin-bottom: 28px;
}
.login-box .brand-logo img {
    max-height: 90px;
    max-width: 100%;
    display: inline-block;
}
.login-box h1 { font-size: 22px; margin-bottom: 4px; color: var(--brand); text-align: center; }
.login-box .tag { color: var(--ink-soft); margin-bottom: 26px; text-align: center; font-size: 13px; }
.login-box .form-grid { display: block; }
.login-box .field { margin-bottom: 16px; }
.login-box .field label {
    display: block; font-size: 12px; color: var(--ink-soft);
    margin-bottom: 6px; font-weight: 500;
}
.login-box button { width: 100%; padding: 12px; margin-top: 12px; }
.login-foot {
    text-align: center;
    margin-top: 28px;
    font-size: 11px;
    color: var(--ink-soft);
}

@media (max-width: 860px) {
    .login-page { grid-template-columns: 1fr; }
    .login-hero { min-height: 200px; padding: 24px; }
    .login-hero h2 { font-size: 20px; }
    .login-side { padding: 32px 20px; }
}

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    border-left: 4px solid;
    font-size: 13px;
}
.alert-error   { background: #fee2e2; color: #991b1b; border-color: var(--red); }
.alert-success { background: #dcfce7; color: #166534; border-color: var(--green); }
.alert-info    { background: #dbeafe; color: #1e40af; border-color: var(--blue); }
.alert-warning { background: #fef3c7; color: #92400e; border-color: var(--amber); }

/* ===== Filters bar ===== */
.filters {
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
}
.filters .field { min-width: 140px; }
.filters .field label { display: block; font-size: 11px; color: var(--ink-soft); margin-bottom: 4px; font-weight: 500; text-transform: uppercase; letter-spacing: .3px; }

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 16px;
    color: var(--ink-soft);
    border-top: 1px solid var(--line);
    background: var(--card);
}

/* ===== Utilities ===== */
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.tight { letter-spacing: -.3px; }
.txt-r { text-align: right; }
.txt-c { text-align: center; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex-1 { flex: 1; }
.text-soft { color: var(--ink-soft); }
.small { font-size: 12px; }

.conc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
@media (max-width: 900px) {
    .conc-grid { grid-template-columns: 1fr; }
}

.diff-pos { color: var(--green); font-weight: 600; }
.diff-neg { color: var(--red); font-weight: 600; }
.diff-zero { color: var(--ink-soft); }

/* ===== Tipos de cambio page ===== */
.page-head { margin: 8px 0 24px; }
.page-head h1 { margin: 0 0 6px; color: var(--ink); }
.page-head .muted { color: var(--ink-soft); font-size: 13px; max-width: 720px; }
.data-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13px; }
.data-table thead th {
    background: #f8fafc;
    text-align: left;
    padding: 10px 12px;
    font-weight: 600;
    color: var(--ink-soft);
    border-bottom: 2px solid #e2e8f0;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: .5px;
}
.data-table tbody td { padding: 8px 12px; border-bottom: 1px solid #f1f5f9; }
.data-table tbody tr:hover { background: #fafbfc; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table thead th { white-space: nowrap; }
.data-table .center { text-align: center; }
.muted-row { background: #fafafa; color: #94a3b8; }
.muted-row td { color: inherit; }

/* ===== Timeline (factura_detalle) ===== */
.timeline {
    margin-top: 16px;
    position: relative;
    padding-left: 8px;
}
.tl-item {
    position: relative;
    display: flex;
    gap: 18px;
    padding-bottom: 22px;
}
.tl-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 9px;
    top: 24px;
    bottom: 0;
    width: 2px;
    background: #e2e8f0;
}
.tl-dot {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-top: 4px;
    background: #94a3b8;
    border: 3px solid #fff;
    box-shadow: 0 0 0 2px #e2e8f0;
    z-index: 1;
}
.tl-dot.brand  { background: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.tl-dot.amber  { background: #f59e0b; box-shadow: 0 0 0 2px #f59e0b; }
.tl-dot.green  { background: #16a34a; box-shadow: 0 0 0 2px #16a34a; }
.tl-dot.red    { background: #dc2626; box-shadow: 0 0 0 2px #dc2626; }
.tl-dot.gray   { background: #cbd5e1; box-shadow: 0 0 0 2px #cbd5e1; }
.tl-body { flex: 1; min-width: 0; padding: 4px 0 0; }
.tl-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}
.tl-date { font-size: 12px; color: var(--ink-soft); }
.tl-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
}
.tl-meta {
    font-size: 12px;
    color: var(--ink-soft);
    line-height: 1.7;
    background: #f8fafc;
    padding: 10px 14px;
    border-radius: 6px;
    border-left: 3px solid #e2e8f0;
}
.tl-meta code { background: rgba(0,0,0,.04); padding: 1px 5px; border-radius: 3px; font-size: 11px; }
.tl-empty .tl-body { padding-top: 6px; }
.tl-final .tl-body { padding-top: 0; }
.diff-neg { color: #dc2626; font-weight: 600; }

@media (max-width: 768px) {
    .form-row { grid-template-columns: 1fr; }
    .mainnav { width: 100%; order: 3; }
    .user { order: 2; }
}
