:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #d7dce5;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --secondary: #2563eb;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  font-family: 'Lexend Deca', Arial, Helvetica, sans-serif;
  font-size: 13px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-width: 320px;
  font-family: 'Lexend Deca', Arial, Helvetica, sans-serif;
  font-size: 0.92rem;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
  padding: 8px 10px;
  outline: none;
  min-width: 0;
  font-size: 0.9rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

label {
  display: grid;
  gap: 5px;
  font-weight: 600;
  color: #374151;
  font-size: 0.86rem;
}

textarea {
  resize: vertical;
}

.topbar {
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 18px;
  justify-content: space-between;
  padding: 12px clamp(16px, 4vw, 44px);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.brand,
.login-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.menu {
  flex: 1;
  display: flex;
  gap: 6px;
  min-width: 220px;
}

.menu-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
}

.menu-link.active {
  color: var(--primary-dark);
  background: #e7f4f2;
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-name {
  color: var(--muted);
  font-size: 0.84rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page {
  width: min(1180px, calc(100% - 28px));
  margin: 26px auto 42px;
  display: grid;
  gap: 18px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 2.4vw, 2rem);
}

h2 {
  font-size: 1rem;
}

.section-header p,
.login-title p,
.model-item p {
  color: var(--muted);
  margin-top: 5px;
}

.panel,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: clamp(16px, 3vw, 24px);
}

.panel-title,
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.sale-form,
.model-form,
.filter-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.filter-form {
  grid-template-columns: minmax(150px, 0.8fr) minmax(150px, 0.8fr) minmax(220px, 1.4fr) auto;
  align-items: end;
}

.span-2 {
  grid-column: span 2;
}

.inline-control {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
}

.btn,
.icon-button {
  border: 0;
  min-height: 34px;
  border-radius: 8px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
  text-align: center;
  font-size: 0.86rem;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-dark);
}

.btn-ghost {
  background: #eef2f7;
  color: #374151;
}

.btn-small {
  min-height: 30px;
  padding: 0 9px;
  font-size: 0.8rem;
}

.icon-button {
  width: 38px;
  padding: 0;
  background: var(--primary);
  color: #fff;
  font-size: 1.1rem;
}

.icon-button.close {
  background: #eef2f7;
  color: #374151;
}

.full {
  width: 100%;
}

.form-actions,
.filter-actions,
.row-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.form-actions {
  justify-content: flex-end;
}

.filter-actions {
  align-self: end;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  overflow-x: auto;
}

.week-nav {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tab-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.tab-link.active {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  color: #4b5563;
  font-size: 0.76rem;
  text-transform: uppercase;
}

.ventas-table {
  --bs-table-bg: transparent;
  --bs-table-hover-bg: #f8fafc;
  font-size: 0.86rem;
}

.ventas-table > :not(caption) > * > * {
  padding: 0.45rem 0.5rem;
}

.list-count {
  font-weight: 600;
  color: var(--muted);
}

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

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 700;
}

.alert.success {
  background: #dcfce7;
  color: #166534;
}

.alert.danger {
  background: #fee2e2;
  color: #991b1b;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.13), transparent 38%),
    var(--bg);
}

.login-panel {
  width: min(430px, 100%);
  padding: clamp(20px, 5vw, 30px);
}

.stack {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.app-version {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 14px;
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 20;
}

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

.modal {
  display: block;
  position: relative;
  inset: auto;
  width: min(880px, 100%);
  height: auto;
  max-height: min(760px, calc(100dvh - 36px));
  overflow: auto;
  background: var(--panel);
  border-radius: 8px;
  padding: clamp(16px, 3vw, 24px);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.24);
  pointer-events: auto;
}

.modal-small {
  width: min(560px, 100%);
}

.modal-summary {
  width: min(980px, 100%);
}

.summary-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
  display: grid;
  gap: 5px;
}

.summary-preview p,
.summary-preview pre {
  color: var(--muted);
}

.summary-preview pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
}

.summary-table-wrap {
  margin-top: 0;
}

.summary-table input[type='number'] {
  min-width: 84px;
}

.stock-actions {
  margin-top: 16px;
}

.stock-accordion {
  display: grid;
  gap: 10px;
}

.stock-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.stock-item summary {
  min-height: 54px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

.stock-item summary::-webkit-details-marker {
  display: none;
}

.stock-item summary::after {
  content: '+';
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  background: #eef2f7;
  color: var(--primary-dark);
  font-weight: 800;
  flex: 0 0 auto;
}

.stock-item[open] summary::after {
  content: '-';
}

.stock-item summary strong {
  font-weight: 800;
}

.stock-item summary span {
  color: var(--muted);
  margin-left: auto;
  font-weight: 700;
  white-space: nowrap;
}

.stock-item-body {
  border-top: 1px solid var(--line);
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(140px, 220px) 1fr;
  gap: 14px;
}

.model-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.model-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
  }

  .menu,
  .menu-link,
  .logout-form,
  .logout-form .btn {
    width: 100%;
  }

  .menu {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .menu-link {
    justify-content: center;
    padding: 0 8px;
    font-size: 0.92rem;
  }

  .logout-form {
    justify-content: space-between;
  }

  .user-name {
    max-width: 60%;
  }

  .page {
    width: min(100% - 20px, 1180px);
    margin: 18px auto 28px;
    gap: 14px;
  }

  .section-header {
    align-items: stretch;
  }

  .section-header > div,
  .header-actions {
    width: 100%;
  }

  .sale-form,
  .model-form,
  .filter-form {
    grid-template-columns: 1fr;
  }

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

  .form-actions,
  .filter-actions,
  .header-actions,
  .form-actions .btn,
  .filter-actions .btn,
  .header-actions .btn {
    width: 100%;
  }

  .filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .week-nav,
  .week-nav .btn {
    width: 100%;
  }

  .week-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: 12px;
    padding: 10px;
    background: #fff;
  }

  td {
    border: 0;
    padding: 8px 0;
  }

  td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-weight: 800;
    font-size: 0.78rem;
    text-transform: uppercase;
    margin-bottom: 3px;
  }

  .row-actions,
  .row-actions .btn,
  .row-actions form {
    width: 100%;
  }

  .row-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .model-item {
    align-items: stretch;
    flex-direction: column;
  }

  .modal-backdrop {
    align-items: stretch;
    padding: 10px;
  }

  .modal {
    width: 100%;
    max-height: calc(100dvh - 20px);
    padding: 14px;
  }

  .modal-header {
    align-items: start;
  }

  .summary-preview {
    max-height: 210px;
    overflow: auto;
  }

  .stock-item summary {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .stock-item summary span {
    width: 100%;
    margin-left: 0;
  }

  .stock-item summary::after {
    position: absolute;
    right: 14px;
  }

  .stock-item summary {
    position: relative;
    padding-right: 52px;
  }

  .stock-item-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 1.55rem;
  }

  .brand span:last-child {
    font-size: 0.98rem;
  }

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

  .filter-actions {
    grid-template-columns: 1fr;
  }

  .week-nav {
    grid-template-columns: 1fr;
  }

  .tabs {
    gap: 4px;
  }

  .tab-link {
    min-height: 40px;
    padding: 0 10px;
    font-size: 0.9rem;
  }

  .btn,
  .icon-button {
    min-height: 44px;
  }
}
