:root {
    --bg: #f4f7f6;
    --ink: #1d2428;
    --muted: #66737a;
    --line: #d9e1df;
    --panel: #ffffff;
    --green: #167a5b;
    --red: #b63d45;
    --blue: #2f5f98;
    --gold: #a87915;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; background: var(--bg); color: var(--ink); }
a { color: inherit; text-decoration: none; }
input, select, button { font: inherit; }

.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: #172126; color: #fff; padding: 22px 16px; transition: width .2s ease, transform .2s ease; }
.sidebar.closed { width: 76px; }
.sidebar-backdrop { display: none; }
.brand { font-size: 20px; font-weight: 700; margin-bottom: 24px; white-space: nowrap; overflow: hidden; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar a { padding: 12px 14px; border-radius: 8px; color: #dce8e5; }
.sidebar a:hover { background: #26353b; }
.main { flex: 1; min-width: 0; }
.topbar { height: 64px; display: flex; align-items: center; gap: 14px; justify-content: space-between; padding: 0 24px; background: #fff; border-bottom: 1px solid var(--line); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.install-btn { border-color: var(--green); color: var(--green); font-weight: 700; }
.icon-btn { width: 40px; height: 40px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 28px 28px 12px; }
.page-head h1 { margin: 0 0 6px; font-size: 28px; }
.page-head p { margin: 0; color: var(--muted); }

.panel, .search, .stats, .alert { margin: 16px 28px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
.panel h2 { margin: 0 0 14px; font-size: 18px; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-title-row h2 { margin: 0; }
.movement-tools { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.movement-tools label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.movement-tools input { width: 82px; min-height: 40px; }
.count-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 28px; padding: 0 10px; border-radius: 999px; background: #eaf1ef; color: var(--ink); font-weight: 700; }
.search { display: flex; gap: 10px; }
.search input { flex: 1; }
.grid-form { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 10px; }
.empresa-form { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 14px; max-width: 860px; }
.empresa-form label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.empresa-form button { width: max-content; }
input, select { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; background: #fff; color: var(--ink); }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 14px; }
.stats article { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 18px; }
.stats span { display: block; color: var(--muted); margin-bottom: 8px; }
.stats strong { font-size: 26px; }
.alert { padding: 14px 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.alert.danger { border-color: #efb0b5; background: #fff1f2; color: #7e1f28; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 13px; }
td small { display: block; color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.ingreso { color: #07593f; background: #dff7ed; }
.pill.gasto { color: #8d2630; background: #ffe2e5; }
.ticket-panel { max-width: 760px; }
.ticket-preview { display: grid; gap: 8px; width: min(360px, 100%); border: 1px dashed var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; background: #fbfdfc; }
.ticket-preview strong { font-size: 20px; }
.ticket-print { width: min(380px, 100%); border: 1px dashed var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; background: #fff; }
.ticket-print pre { margin: 0; white-space: pre-wrap; font-family: Consolas, monospace; font-size: 14px; }

.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(23,33,38,.45); padding: 20px; z-index: 10; }
.modal.open { display: flex; }
.modal-card { width: min(720px, 100%); background: #fff; border-radius: 8px; padding: 22px; position: relative; }
.modal-large { width: min(960px, 100%); }
.modal-scroll { max-height: min(66vh, 620px); overflow: auto; padding-right: 4px; }
.modal-close { position: absolute; right: 12px; top: 10px; border: 0; background: transparent; font-size: 28px; cursor: pointer; }
.install-alert { position: fixed; right: 22px; bottom: 22px; z-index: 12; display: flex; align-items: center; gap: 12px; width: min(520px, calc(100% - 44px)); background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--green); border-radius: 8px; box-shadow: 0 16px 34px rgba(23,33,38,.18); padding: 14px; }
.install-alert[hidden], .install-btn[hidden] { display: none; }
.install-alert div { flex: 1; min-width: 0; }
.install-alert strong { display: block; margin-bottom: 4px; }
.install-alert span { color: var(--muted); font-size: 14px; }
.login-body { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(135deg, #172126, #2f5f98); }
.login-card { width: min(380px, calc(100% - 32px)); background: #fff; border-radius: 8px; padding: 28px; display: grid; gap: 12px; }
.login-card h1 { margin: 0 0 8px; }

@media (max-width: 900px) {
    .app { display: block; }
    .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 13; width: min(280px, 82vw); transform: translateX(0); box-shadow: 18px 0 34px rgba(23,33,38,.24); }
    .sidebar.closed { width: min(280px, 82vw); transform: translateX(-105%); }
    .sidebar-backdrop.open { display: block; position: fixed; inset: 0; z-index: 12; background: rgba(23,33,38,.45); }
    .main { width: 100%; }
    .grid-form { grid-template-columns: 1fr; }
    .empresa-form { grid-template-columns: 1fr; }
    .stats { grid-template-columns: 1fr; }
    .page-head { flex-direction: column; align-items: flex-start; }
    .panel-title-row { align-items: flex-start; flex-direction: column; }
    .movement-tools { width: 100%; justify-content: flex-start; }
    .topbar { padding: 0 12px; }
    .top-actions { gap: 6px; }
    .install-alert { left: 12px; right: 12px; bottom: 12px; width: auto; align-items: flex-start; flex-wrap: wrap; }
    .modal { align-items: flex-end; padding: 0; }
    .modal-card { width: 100%; max-height: 88vh; border-radius: 8px 8px 0 0; overflow: hidden; }
    .modal-scroll { max-height: calc(88vh - 92px); overflow: auto; padding-right: 0; }
}

@media (max-width: 520px) {
    .topbar { height: auto; min-height: 64px; flex-wrap: wrap; padding: 10px 12px; }
    .topbar > span { order: 3; width: 100%; color: var(--muted); font-size: 14px; }
    .top-actions { margin-left: auto; }
    .top-actions .btn { min-height: 38px; padding: 0 10px; font-size: 14px; }
    .panel, .search, .stats, .alert { margin-left: 12px; margin-right: 12px; }
    .page-head { padding-left: 12px; padding-right: 12px; }
    .page-head h1 { font-size: 24px; }
    .table-wrap { overflow: visible; }
    table.responsive-table { min-width: 0; border-collapse: separate; border-spacing: 0 12px; }
    .responsive-table thead { display: none; }
    .responsive-table tbody { display: grid; gap: 12px; }
    .responsive-table tr { display: grid; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
    .responsive-table td { display: grid; grid-template-columns: minmax(96px, 38%) 1fr; gap: 8px; align-items: start; border: 0; padding: 0; word-break: break-word; }
    .responsive-table td::before { content: attr(data-label); color: var(--muted); font-size: 13px; font-weight: 700; }
    .responsive-table td.actions { display: flex; gap: 8px; align-items: center; }
    .responsive-table td.actions::before { width: 96px; flex: 0 0 96px; }
    .responsive-table .actions .btn { flex: 1 1 auto; min-width: 72px; }
}

@media print {
    body { background: #fff; }
    .sidebar, .topbar, .page-head, .no-print, .alert { display: none !important; }
    .app { display: block; min-height: auto; }
    .main { display: block; }
    .panel { border: 0; margin: 0; padding: 0; }
    .ticket-print { border: 0; width: 58mm; padding: 0; }
    .ticket-print pre { font-size: 11px; }
}
