/* ==========================================================================
   Sistema - Artisanal Ledger Design System
   ========================================================================== */

:root {
    /* Color tokens */
    --surface: #f8f9fb;
    --surface-container-low: #f3f4f6;
    --surface-container: #edeef0;
    --surface-container-high: #e7e8ea;
    --surface-container-highest: #e1e2e4;
    --surface-container-lowest: #ffffff;

    --on-surface: #191c1e;
    --on-surface-variant: #434655;
    --outline: #737686;
    --outline-variant: #c3c6d7;

    --primary: #004ac6;
    --primary-container: #2563eb;
    --primary-fixed: #dbe1ff;
    --on-primary: #ffffff;

    --secondary: #006e2d;
    --secondary-container: #7cf994;
    --on-secondary-container: #007230;

    --tertiary: #4c5665;
    --tertiary-fixed: #d9e3f6;

    --error: #ba1a1a;
    --error-container: #ffdad6;
    --on-error-container: #93000a;

    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    --shadow-sm: 0 1px 2px rgba(25, 28, 30, 0.04), 0 1px 3px rgba(25, 28, 30, 0.02);
    --shadow-md: 0 4px 12px rgba(25, 28, 30, 0.05);
    --shadow-lg: 0 12px 32px rgba(25, 28, 30, 0.06);
}

* { box-sizing: border-box; }

html, body {
    font-family: 'Inter', sans-serif;
    background: var(--surface);
    color: var(--on-surface);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

.icon-box {
  background: #1e3a5f;
  padding: 12px;
  border-radius: 16px;
}

.icon-box svg {
  width: 40px;
  fill: #f59e0b;
}

body { min-height: 100vh; }

::selection { background: var(--primary-fixed); color: var(--primary); }

/* ==========================================================================
   Layout structure
   ========================================================================== */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-main {
    margin-left: 16rem;
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-canvas {
    padding: 2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .app-main { margin-left: 0; }
    .app-canvas { padding: 1rem; }
}

/* ==========================================================================
   Sidebar
   ========================================================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 16rem;
    height: 100vh;
    background: var(--surface-container-low);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0;
    z-index: 50;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 0 1.5rem 2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-brand-logo {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    box-shadow: var(--shadow-md);
}

.sidebar-brand-title {
    font-size: 1.125rem;
    font-weight: 900;
    color: var(--on-surface);
    line-height: 1;
}

.sidebar-brand-sub {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--on-surface-variant);
    font-weight: 700;
    opacity: 0.7;
    margin-top: 4px;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 0.5rem;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin: 0 0.5rem;
    border-radius: var(--radius-md);
    color: var(--on-surface-variant);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
}

.sidebar-item:hover {
    background: rgba(255, 255, 255, 0.6);
    transform: translateX(4px);
}

.sidebar-item.active {
    background: var(--surface-container-lowest);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.sidebar-footer {
    padding: 1.5rem 1rem 0;
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-cta {
    background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%);
    color: #fff;
    padding: 0.75rem;
    border-radius: var(--radius-lg);
    font-weight: 700;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
    text-align: center;
    border: none;
    cursor: pointer;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
}

.sidebar-cta:hover { filter: brightness(1.08); box-shadow: var(--shadow-lg); }
.sidebar-cta:active { transform: scale(0.97); }

.sidebar-item-danger {
    color: var(--error);
}

.sidebar-item-danger:hover {
    background: rgba(186, 26, 26, 0.08);
}

/* Mobile sidebar */
.sidebar-toggle {
    display: none;
    background: var(--surface-container-lowest);
    border: none;
    border-radius: var(--radius-md);
    padding: 0.5rem;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    color: var(--on-surface);
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: inline-flex; }
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    gap: 1rem;
}

.topbar-search {
    position: relative;
    flex: 1;
    max-width: 28rem;
}

.topbar-search input {
    width: 100%;
    background: var(--surface-container-low);
    border: none;
    border-radius: 9999px;
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    font-size: 0.875rem;
    color: var(--on-surface);
    transition: all 0.2s ease;
}

.topbar-search input:focus {
    outline: none;
    background: var(--surface-container-lowest);
    box-shadow: 0 0 0 3px rgba(0, 74, 198, 0.15);
}

.topbar-search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--on-surface-variant);
    font-size: 1.125rem;
    pointer-events: none;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar-icon-btn {
    padding: 0.5rem;
    border-radius: 9999px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--on-surface-variant);
    transition: background 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.topbar-icon-btn:hover { background: var(--surface-container); }

.topbar-divider {
    width: 1px;
    height: 1.75rem;
    background: var(--outline-variant);
    opacity: 0.3;
    margin: 0 0.5rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-left: 0.5rem;
}

.topbar-user-text { text-align: right; }
.topbar-user-name { font-size: 0.875rem; font-weight: 700; line-height: 1; color: var(--on-surface); }
.topbar-user-role { font-size: 0.75rem; color: var(--on-surface-variant); }

.topbar-user-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 9999px;
    background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    border: 2px solid #fff;
    box-shadow: var(--shadow-sm);
}

@media (max-width: 640px) {
    .topbar { padding: 0.75rem 1rem; }
    .topbar-user-text { display: none; }
}

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
    background: var(--surface-container-lowest);
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;
}

.card:hover { box-shadow: var(--shadow-md); }

.card-sm { padding: 1.5rem; }

.card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.card-header-icon {
    width: 3rem;
    height: 3rem;
    border-radius: var(--radius-lg);
    background: var(--surface-container);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--on-surface);
    margin: 0;
    line-height: 1.2;
}

.card-subtitle {
    font-size: 0.75rem;
    color: var(--on-surface-variant);
    font-weight: 500;
    margin-top: 2px;
}

.card-featured {
    border-left: 4px solid var(--primary);
}

/* Page title */
.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--on-surface);
    margin: 0 0 0.25rem;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--on-surface-variant);
    margin: 0 0 1.5rem;
}

/* Stat cards */
.stat-card {
    background: var(--surface-container-lowest);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.3s ease;
}

.stat-card:hover { transform: translateY(-4px); }

.stat-label {
    color: var(--on-surface-variant);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.875rem;
    font-weight: 900;
    color: var(--on-surface);
    line-height: 1.1;
}

.stat-meta { font-size: 0.75rem; font-weight: 700; margin-top: 0.5rem; display: flex; align-items: center; gap: 0.25rem; }
.stat-meta-up { color: var(--secondary); }
.stat-meta-down { color: var(--error); }
.stat-meta-neutral { color: var(--on-surface-variant); }

.stat-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon-primary { background: rgba(0, 74, 198, 0.1); color: var(--primary); }
.stat-icon-secondary { background: rgba(0, 110, 45, 0.1); color: var(--secondary); }
.stat-icon-error { background: rgba(186, 26, 26, 0.1); color: var(--error); }
.stat-icon-tertiary { background: rgba(76, 86, 101, 0.1); color: var(--tertiary); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-lg);
    font-weight: 700;
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: none;
    border: none;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    background: var(--surface-container-high);
    color: var(--on-surface);
    line-height: 1;
}

.btn:hover { background: var(--surface-container-highest); }
.btn:active { transform: scale(0.98); }

/* Primary */
.btn-primary {
    background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%);
    color: var(--on-primary);
    box-shadow: var(--shadow-md);
}

.btn-primary:hover { filter: brightness(1.08); box-shadow: var(--shadow-lg); }

/* Secondary (alias to default) */
.btn-secondary { background: var(--surface-container-high); color: var(--on-surface); }
.btn-secondary:hover { background: var(--surface-container-highest); }

/* Danger */
.btn-danger {
    background: var(--error-container);
    color: var(--on-error-container);
}

.btn-danger:hover { background: #ffc1bc; }

/* Success */
.btn-success {
    background: var(--secondary-container);
    color: var(--on-secondary-container);
}

/* Sizes */
.btn-sm { padding: 0.5rem 0.875rem; font-size: 0.75rem; border-radius: var(--radius-md); }
.btn-lg { padding: 1rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; }

/* Module action button (between primary and secondary) */
.btn-module {
    width: 100%;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
}

/* ==========================================================================
   Forms
   ========================================================================== */
.form-group { display: flex; flex-direction: column; gap: 0.375rem; margin-bottom: 1rem; }

.label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--on-surface);
    margin-bottom: 0.375rem;
    display: block;
}

.input, select.input, textarea.input {
    width: 100%;
    background: var(--surface-container-low);
    color: var(--on-surface);
    border: none;
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-family: inherit;
    transition: all 0.2s ease;
    box-shadow: inset 0 0 0 1px transparent;
}

.input:focus, select.input:focus, textarea.input:focus {
    outline: none;
    background: var(--surface-container-lowest);
    box-shadow: 0 0 0 3px rgba(0, 74, 198, 0.15), inset 0 0 0 1px var(--primary);
}

textarea.input { min-height: 100px; resize: vertical; }

select.input {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23434655'%3e%3cpath fill-rule='evenodd' d='M5.23 7.21a.75.75 0 011.06.02L10 11.06l3.71-3.83a.75.75 0 111.08 1.04l-4.25 4.39a.75.75 0 01-1.08 0L5.21 8.27a.75.75 0 01.02-1.06z' clip-rule='evenodd'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1rem;
    padding-right: 2.25rem;
}

.input-group { position: relative; }
.input-prefix {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--on-surface-variant);
    font-size: 0.875rem;
    pointer-events: none;
}
.input-prefix + .input { padding-left: 2.5rem; }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrapper {
    background: var(--surface-container-lowest);
    border-radius: var(--radius-xl);
    overflow: hidden;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875rem;
}

.table thead th {
    background: var(--surface-container-low);
    color: var(--on-surface-variant);
    text-align: left;
    padding: 0.875rem 1.25rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.table tbody td {
    padding: 0.875rem 1.25rem;
    color: var(--on-surface);
    background: var(--surface-container-lowest);
}

.table tbody tr + tr td {
    border-top: 1px solid var(--surface-container);
}

.table tbody tr:hover td { background: var(--surface-container-low); }

.table-text-right { text-align: right; }
.table-text-center { text-align: center; }

/* Chips */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 700;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chip-success { background: rgba(0, 110, 45, 0.12); color: var(--on-secondary-container); }
.chip-warn { background: rgba(255, 176, 32, 0.15); color: #8a5a00; }
.chip-error { background: var(--error-container); color: var(--on-error-container); }
.chip-primary { background: rgba(0, 74, 198, 0.1); color: var(--primary); }
.chip-neutral { background: var(--surface-container); color: var(--on-surface-variant); }

/* ==========================================================================
   Misc / utilities
   ========================================================================== */
.divider-soft { height: 1px; background: var(--surface-container); margin: 1.5rem 0; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: var(--on-surface-variant);
    font-size: 0.875rem;
}

.value-positive { color: var(--secondary); font-weight: 700; }
.value-negative { color: var(--error); font-weight: 700; }

.total-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    padding-top: 1rem;
    margin-top: 1rem;
    border-top: 1px solid var(--surface-container);
    font-size: 1.125rem;
    font-weight: 800;
    color: var(--primary);
}

.footer-system {
    padding: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--on-surface-variant);
    opacity: 0.8;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.footer-system a { color: inherit; text-decoration: none; }
.footer-system a:hover { color: var(--primary); }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(25, 28, 30, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.modal-backdrop.open { display: flex; }

.modal-dialog {
    background: var(--surface-container-lowest);
    border-radius: var(--radius-xl);
    padding: 1.75rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 24px 60px rgba(25, 28, 30, 0.2);
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 800;
    color: var(--on-surface);
    margin: 0 0 0.5rem;
}

.modal-body { color: var(--on-surface-variant); font-size: 0.875rem; margin-bottom: 1.25rem; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Grid helpers */
.grid-auto { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.row-gap-3 > * + * { margin-top: 0.75rem; }

/* Link style */
.link-primary { color: var(--primary); font-weight: 600; text-decoration: none; }
.link-primary:hover { text-decoration: underline; }

/* Print-friendly */
@media print {
    .sidebar, .topbar, .sidebar-toggle, .footer-system { display: none !important; }
    .app-main { margin-left: 0 !important; }
    .card { box-shadow: none !important; }
}
