/* MercaSoft — panel de licencias. Sistema visual minimalista.
   Marca: verde (Merca) + azul (Soft), acento cian, base navy. */

:root {
  color-scheme: light;

  --green: #2fb84e;
  --green-dark: #1e9e3c;
  --blue: #1c6dd0;
  --blue-dark: #175bb0;
  --cyan: #23c1e0;

  --ink: #0e1f33;
  --ink-soft: #1b3350;
  --paper: #ffffff;
  --mist: #f3f7fb;
  --line: #e4ebf3;
  --muted: #647689;

  --ok: #1e9e3c;
  --warn: #b7791f;
  --danger: #d64545;

  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(14, 31, 51, 0.06);
  --shadow: 0 12px 30px rgba(14, 31, 51, 0.1);
  --shadow-lg: 0 24px 60px rgba(14, 31, 51, 0.22);

  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Space Grotesk", var(--sans);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--mist);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  font-family: var(--display);
  letter-spacing: -0.01em;
  margin: 0;
}

/* ---------- Brand mark ---------- */

.brandmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brandmark svg {
  width: 34px;
  height: 34px;
  flex: none;
}

.brandmark .wordmark {
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
  line-height: 1;
}

.wordmark .merca {
  color: var(--green);
}

.wordmark .soft {
  color: var(--blue);
}

.brandmark.on-dark .soft {
  color: var(--cyan);
}

/* ---------- Buttons ---------- */

button {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

button:hover {
  background: var(--green-dark);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background: var(--paper);
  border-color: var(--line);
  color: var(--ink);
}

button.secondary:hover {
  background: #eef3f8;
  border-color: #cfdbe8;
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--blue);
  padding: 6px 10px;
}

button.ghost:hover {
  background: rgba(28, 109, 208, 0.09);
}

button.danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
  padding: 6px 10px;
}

button.danger-ghost:hover {
  background: rgba(214, 69, 69, 0.1);
}

button.danger {
  background: var(--danger);
}

button.danger:hover {
  background: #b83a3a;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ---------- Forms ---------- */

input,
select,
textarea {
  width: 100%;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  background: var(--paper);
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
}

textarea {
  min-height: 84px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

label input,
label select,
label textarea {
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--ink);
}

.form-stack {
  display: grid;
  gap: 15px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

/* ---------- Login ---------- */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.login-watermark {
  position: absolute;
  right: -80px;
  bottom: -90px;
  width: 460px;
  height: 460px;
  opacity: 0.06;
  transform: rotate(-8deg);
  pointer-events: none;
}

.login-card {
  position: relative;
  width: min(400px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px 30px;
}

.login-card .brandmark {
  margin-bottom: 22px;
}

.login-card h1 {
  font-size: 21px;
}

.login-card .lede {
  margin: 6px 0 24px;
  color: var(--muted);
}

.login-card form {
  margin-top: 4px;
}

.login-card button[type="submit"] {
  width: 100%;
  margin-top: 6px;
  padding: 11px;
}

/* ---------- App shell ---------- */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
}

.sidebar {
  background: var(--ink);
  color: #eaf1f8;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brandmark {
  padding: 4px 6px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar .brandmark .wordmark {
  color: #fff;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav button {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  background: transparent;
  border-color: transparent;
  color: #b7c6d8;
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
}

.nav button .dot {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.5;
}

.nav button:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav button.active {
  background: rgba(35, 193, 224, 0.14);
  color: #fff;
}

.nav button.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--cyan);
}

.nav button.active .dot {
  background: var(--cyan);
  opacity: 1;
}

.user-panel {
  margin-top: auto;
  display: grid;
  gap: 4px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
}

.user-panel .who {
  font-weight: 700;
}

.user-panel .role {
  color: #9fb2c7;
  font-size: 12px;
  margin-bottom: 8px;
}

.user-panel button {
  width: 100%;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.16);
  color: #dbe6f2;
}

.user-panel button:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* ---------- Content ---------- */

.content {
  min-width: 0;
  padding: 30px 34px 48px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.section-title h1 {
  font-size: 26px;
}

.section-title p {
  margin: 5px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ---------- Card + table ---------- */

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.card-head h2 {
  font-size: 14px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.count-pill {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--blue);
  background: rgba(28, 109, 208, 0.09);
  border-radius: 999px;
  padding: 2px 10px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  text-align: left;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

thead th {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f8fbfe;
  font-weight: 700;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: #f8fbfe;
}

.cell-strong {
  font-weight: 600;
}

.cell-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.id-chip {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  background: #eef2f7;
  color: var(--muted);
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.ok {
  background: rgba(47, 184, 78, 0.12);
  color: var(--ok);
}

.badge.warn {
  background: rgba(183, 121, 31, 0.14);
  color: var(--warn);
}

.badge.danger {
  background: rgba(214, 69, 69, 0.12);
  color: var(--danger);
}

.badge.info {
  background: rgba(35, 193, 224, 0.14);
  color: #0e7d95;
}

/* ---------- Row actions ---------- */

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: flex-end;
}

td.actions-cell {
  text-align: right;
  white-space: nowrap;
}

/* ---------- Empty state ---------- */

.empty {
  padding: 46px 24px;
  text-align: center;
  color: var(--muted);
}

.empty strong {
  display: block;
  color: var(--ink);
  font-family: var(--display);
  font-size: 16px;
  margin-bottom: 4px;
}

/* ---------- Toast ---------- */

#toast-root {
  position: fixed;
  top: 18px;
  right: 18px;
  display: grid;
  gap: 10px;
  z-index: 60;
  max-width: min(380px, calc(100vw - 36px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--ink);
  color: #eef4fa;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border-left: 3px solid var(--cyan);
  animation: toast-in 0.18s ease-out;
}

.toast.ok {
  border-left-color: var(--green);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast button {
  margin-left: auto;
  background: transparent;
  border: none;
  color: inherit;
  opacity: 0.7;
  padding: 0 2px;
  font-size: 16px;
  line-height: 1;
}

.toast button:hover {
  opacity: 1;
  background: transparent;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(14, 31, 51, 0.42);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
  animation: fade 0.14s ease-out;
}

.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: pop 0.16s ease-out;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 6px;
}

.modal-head h2 {
  font-size: 19px;
}

.modal-head .close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
}

.modal-head .close:hover {
  background: #eef3f8;
  color: var(--ink);
}

.modal-sub {
  padding: 0 22px;
  margin: 0 0 16px;
  color: var(--muted);
}

.modal-body {
  padding: 6px 22px 8px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px 22px;
}

.serial-callout {
  margin: 4px 22px 0;
  padding: 12px 14px;
  background: rgba(47, 184, 78, 0.09);
  border: 1px dashed rgba(47, 184, 78, 0.4);
  border-radius: var(--radius-sm);
}

.serial-callout .label {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.serial-callout .value {
  font-family: var(--mono);
  font-size: 16px;
  color: var(--ink);
  word-break: break-all;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: column;
  }

  .user-panel {
    margin-top: 8px;
  }

  .content {
    padding: 22px 18px 40px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
