:root {
    --bg: #0f172a;
    --bg-2: #1e293b;
    --sidebar: #111827;
    --card: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --brand: #4f46e5;
    --brand-2: #6366f1;
    --ok: #16a34a;
    --ok-bg: #dcfce7;
    --warn: #d97706;
    --warn-bg: #fef3c7;
    --pending: #dc2626;
    --pending-bg: #fee2e2;
    --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
    --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f1f5f9;
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 250px; background: var(--sidebar); color: #cbd5e1;
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
    flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 22px 20px; font-weight: 700; color: #fff; font-size: 18px; }
.brand-mark { font-size: 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px;
    color: #cbd5e1; font-weight: 500; transition: .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-ico { width: 18px; text-align: center; opacity: .9; }
.sidebar-foot { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-2); color: #fff;
    display: grid; place-items: center; font-weight: 700; }
.user-name { font-size: 13px; color: #e2e8f0; }
.logout { display: block; text-align: center; padding: 8px; border-radius: 8px; background: rgba(255,255,255,.06); color: #cbd5e1; }
.logout:hover { background: rgba(255,255,255,.12); color: #fff; }

.content { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between;
    padding: 20px 32px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 20px; margin: 0; }
.container { padding: 28px 32px; max-width: 1200px; }

/* ---------- Flash ---------- */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash-success { background: var(--ok-bg); color: #166534; }
.flash-error { background: var(--pending-bg); color: #991b1b; }
.flash-info { background: #dbeafe; color: #1e40af; }

/* ---------- Cards & stats ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.accent { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border: none; color: #fff; }
.stat.accent .label, .stat.accent .sub { color: rgba(255,255,255,.85); }
.stat.danger .value { color: var(--pending); }

.section-title { font-size: 16px; font-weight: 700; margin: 26px 0 12px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; background: #fff; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f8fafc; }
table.data tbody tr:hover, table.data tr:hover td { background: #f8fafc; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: #166534; }
.badge.warn { background: var(--warn-bg); color: #92400e; }
.badge.pending { background: var(--pending-bg); color: #991b1b; }
.badge.gray { background: #f1f5f9; color: var(--muted); }
.badge.stock-low { background: var(--warn-bg); color: #92400e; }
.badge.stock-out { background: var(--pending-bg); color: #991b1b; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 9px;
    border: 1px solid var(--line); background: #fff; color: var(--ink); font-weight: 600; cursor: pointer; font-size: 14px; }
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { background: #fff; border-color: var(--pending); color: var(--pending); }
.btn.danger:hover { background: var(--pending-bg); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f5f9; }

/* ---------- Forms ---------- */
.form-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); max-width: 900px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.field input[type=text], .field input[type=number], .field input[type=email],
.field input[type=password], .field input[type=date], .field input[type=file],
.field select, .field textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--brand-2); border-color: var(--brand-2); }
.field textarea { min-height: 70px; resize: vertical; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
fieldset.block { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
fieldset.block legend { font-weight: 700; padding: 0 8px; color: var(--brand); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.search { position: relative; }
.search input { padding: 9px 14px; border: 1px solid var(--line); border-radius: 9px; width: 260px; }

/* ---------- Doc thumbnails ---------- */
.doc-thumbs { display: flex; gap: 12px; flex-wrap: wrap; }
.doc-thumb { width: 140px; }
.doc-thumb img { width: 140px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.doc-thumb .cap { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; }

/* ---------- Order items builder ---------- */
.line-items { width: 100%; border-collapse: collapse; margin-top: 8px; }
.line-items th, .line-items td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.line-items th { font-size: 12px; color: var(--muted); text-align: left; }
.line-items input, .line-items select { padding: 8px; border: 1px solid var(--line); border-radius: 8px; width: 100%; }
.line-items .num { text-align: right; }
.totals-box { margin-top: 16px; margin-left: auto; max-width: 320px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 6px 0; }
.totals-box .row.total { font-size: 18px; font-weight: 700; border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; }

/* ---------- Expediente ---------- */
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
.info-list { list-style: none; padding: 0; margin: 0; }
.info-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.info-list li .k { color: var(--muted); }
.info-list li .v { font-weight: 600; text-align: right; }
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; display:flex; justify-content:space-between; align-items:center;}
.panel-body { padding: 20px; }
.balance-big { font-size: 30px; font-weight: 800; }
.balance-big.owed { color: var(--pending); }
.balance-big.clear { color: var(--ok); }

@media (max-width: 900px) {
    .sidebar { width: 68px; }
    .brand-name, .nav-item span:not(.nav-ico), .user-name { display: none; }
    .two-col, .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .container, .topbar { padding-left: 18px; padding-right: 18px; }
}

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1e293b, #4f46e5); }
.login-card { background: #fff; border-radius: 16px; padding: 36px; width: 360px; box-shadow: 0 20px 40px rgba(0,0,0,.3); }
.login-card .brand { justify-content: center; color: var(--ink); padding: 0 0 8px; }
.login-card h2 { text-align: center; margin: 0 0 24px; color: var(--muted); font-size: 14px; font-weight: 500; }
.login-card .btn.primary { width: 100%; justify-content: center; margin-top: 8px; }
