:root {
  --sidebar-width: 260px;
  --gold: #b8922a;
  --gold-soft: #d4b45a;
  --ink: #1c2430;
  --muted: #6b7280;
  --bg: #f3f5f8;
  --card: #ffffff;
  --line: #e5e7eb;
  --ok: #0f766e;
  --danger: #b91c1c;
  --sidebar-bg: #121820;
  --sidebar-text: #d7dde7;
}

[data-theme="dark"] {
  --bg: #0e1218;
  --card: #171d27;
  --ink: #eef2f7;
  --muted: #9aa6b2;
  --line: #2a3340;
  --sidebar-bg: #0a0e13;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; display: flex; }

.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--sidebar-bg), #1a2330);
  color: var(--sidebar-text);
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  padding: 1rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 20;
  overflow: hidden;
}

.sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.15rem;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(184,146,42,.45) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(184,146,42,.4);
  border-radius: 999px;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 0.65rem 0.35rem 0.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.15));
}

.btn-logout {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  padding: .65rem .85rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  color: #e8edf4;
  font-weight: 600;
  font-size: .9rem;
  transition: .2s ease;
}
.btn-logout i { color: #f0c14b; }
.btn-logout:hover {
  background: rgba(185, 28, 28, .22);
  border-color: rgba(248, 113, 113, .45);
  color: #fff;
}
.btn-logout:hover i { color: #fca5a5; }

.user-chip {
  display: inline-flex;
  align-items: center;
}
.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: #fff;
  background: linear-gradient(135deg, var(--gold), #8a6a16);
  border: 1px solid rgba(184,146,42,.35);
  box-shadow: 0 4px 12px rgba(184,146,42,.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .45rem .5rem .9rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--gold), #8a6a16);
  display: grid; place-items: center; color: #fff; font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(184,146,42,.28);
}
.brand-mark i { font-size: 1.05rem; }
.brand h1 {
  font-size: 1.15rem; margin: 0; color: #fff; line-height: 1.2; font-weight: 700; letter-spacing: .01em;
}

.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #8090a3; margin: .55rem .45rem .25rem; }
.nav-link {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .7rem; border-radius: 10px; color: var(--sidebar-text);
  transition: .2s ease;
  font-size: .92rem;
}
.nav-link:hover, .nav-link.active {
  background: rgba(184,146,42,.18);
  color: #fff;
}
.nav-link i { width: 1.1rem; text-align: center; color: var(--gold-soft); }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.content {
  padding: 1.25rem;
  flex: 1;
  min-height: calc(100vh - 64px);
}

.page-title { margin: 0 0 1rem; font-size: 1.45rem; font-weight: 700; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.15rem;
  flex-wrap: wrap;
}
.page-header .page-title { margin-bottom: .25rem; }
.page-header .page-meta { color: var(--muted); font-size: .92rem; }

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
}
.page-actions .action-group {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
}
.page-actions .action-sep {
  width: 1px;
  height: 1.6rem;
  background: var(--line);
  margin: 0 .15rem;
}
.page-actions form {
  display: inline;
  margin: 0;
}
.page-actions .btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  white-space: nowrap;
}

.card-soft {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.1rem 1.2rem;
  box-shadow: 0 8px 24px rgba(16,24,40,.04);
  animation: rise .35s ease both;
}

/* Catálogos: materiales / marcas / categorías */
.catalog-create .form-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: .3rem;
}
.catalog-create .btn-gold { width: 100%; }
.catalog-list .table thead th {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  border-bottom-width: 1px;
  white-space: nowrap;
}
.catalog-list .table tbody td { vertical-align: middle; padding-top: .65rem; padding-bottom: .65rem; }
.catalog-list .table tbody tr:hover { background: rgba(184,146,42,.04); }
.catalog-list .form-control-sm,
.catalog-list .form-select-sm {
  min-height: 34px;
  font-size: .875rem;
}
.catalog-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: .35rem;
  white-space: nowrap;
}
.catalog-actions .btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.catalog-empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

.kpi {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
}
.kpi .label { color: var(--muted); font-size: .85rem; margin-bottom: .35rem; }
.kpi .value { font-size: 1.45rem; font-weight: 700; }
.kpi .icon {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: rgba(184,146,42,.12); color: var(--gold);
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), #8a6a16);
  border: 0; color: #fff;
}
.btn-gold:hover { filter: brightness(1.05); color: #fff; }

.table { --bs-table-bg: transparent; }
.table > :not(caption) > * > * { border-bottom-color: var(--line); color: var(--ink); }

.form-control, .form-select {
  background: var(--card);
  color: var(--ink);
  border-color: var(--line);
}
.form-control:focus, .form-select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 .2rem rgba(184,146,42,.15);
}

.badge-soft {
  display: inline-block;
  background: rgba(15,118,110,.12);
  color: var(--ok);
  border-radius: 999px;
  padding: .25rem .65rem;
  font-weight: 600;
  font-size: .78rem;
  line-height: 1.2;
  white-space: nowrap;
}
.badge-soft.off {
  background: rgba(185,28,28,.12);
  color: var(--danger);
}
.badge-soft.info {
  background: rgba(184,146,42,.16);
  color: #8a6a16;
}
[data-theme="dark"] .badge-soft.info {
  color: #e8d48b;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 500px at 10% 0%, rgba(184,146,42,.22), transparent 55%),
    radial-gradient(800px 400px at 100% 10%, rgba(40,70,120,.25), transparent 50%),
    linear-gradient(160deg, #0f1419, #1a2332);
  color: #f3f0e8;
}
.login-card {
  width: min(400px, 100%);
  background: rgba(255,255,255,.045);
  border: 1px solid rgba(184,146,42,.3);
  border-radius: 22px;
  padding: 2.25rem 2rem 2rem;
  backdrop-filter: blur(10px);
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  animation: rise .45s ease both;
}
.login-brand {
  text-align: center;
  margin-bottom: 1.75rem;
}
.login-mark {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  margin: 0 auto .9rem;
  background: linear-gradient(135deg, #b8922a, #8a6a16);
  color: #fff;
  font-size: 1.35rem;
  box-shadow: 0 8px 22px rgba(184,146,42,.35);
}
.login-brand h1 {
  color: #e8d48b;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: .02em;
  margin: 0 0 .35rem;
}
.login-brand p {
  color: #9aa3b2;
  margin: 0;
  font-size: .95rem;
}
.login-card .form-label {
  color: #c5ccd6;
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .4rem;
}
.login-card .form-control {
  background: rgba(0,0,0,.28);
  border-color: rgba(255,255,255,.12);
  color: #fff;
  min-height: 44px;
  border-radius: 12px;
}
.login-card .form-control:focus {
  background: rgba(0,0,0,.35);
  border-color: rgba(184,146,42,.65);
  box-shadow: 0 0 0 .2rem rgba(184,146,42,.18);
  color: #fff;
}
.login-card .form-control::placeholder { color: #7a8494; }
.login-card .btn-gold {
  border-radius: 12px;
  font-weight: 600;
  min-height: 46px;
  box-shadow: 0 8px 18px rgba(184,146,42,.25);
}
.login-card .alert { border-radius: 12px; }

.flash-alert {
  transition: opacity .25s ease, transform .25s ease;
}
.flash-alert.fade:not(.show) {
  opacity: 0;
  transform: translateY(-6px);
}

.theme-toggle {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  width: 40px; height: 40px;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 992px) {
  .sidebar { position: fixed; transform: translateX(-105%); transition: .25s ease; }
  .sidebar.open { transform: none; }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 15;
  }
  .sidebar-backdrop.show { display: block; }
}
