:root {
  --bg: #1a1020;
  --panel: #2a1733;
  --panel-2: #3a2045;
  --line: #5a3568;
  --ink: #fff8f0;
  --muted: #d4b8c8;
  --accent: #f0a33a;
  --accent-ink: #3a1a08;
  --brand-purple: #6b2d7b;
  --brand-yellow: #ffe14a;
  --danger: #ff8f8f;
  --warn: #e6c35c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, #5a2a6e 0%, transparent 42%),
    radial-gradient(circle at 100% 100%, #8a4a20 0%, transparent 38%),
    var(--bg);
}

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

a { color: var(--accent); }

.hidden { display: none !important; }

#login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-box {
  width: min(420px, 100%);
  background: color-mix(in srgb, var(--panel) 90%, black);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.75rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.login-logo {
  width: min(220px, 70%);
  height: auto;
  margin: 0 auto 0.85rem;
  display: block;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.35));
}

.login-box h1 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
}

.login-box p {
  margin: 0 0 1.25rem;
  color: var(--muted);
  line-height: 1.45;
}

.login-box form {
  text-align: left;
}

label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  margin-bottom: 0.9rem;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #1a0f22;
  color: var(--ink);
}

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

.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-weight: 650;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
}

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

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-danger {
  background: #5a2222;
  color: #ffdede;
  border: 1px solid #7a3434;
}

.msg { margin-top: 0.8rem; font-size: 0.9rem; min-height: 1.2em; }
.msg.ok { color: var(--accent); }
.msg.err { color: var(--danger); }

#app-view {
  height: 100vh;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  overflow: hidden;
}

.sidebar {
  background: color-mix(in srgb, var(--panel) 92%, black);
  border-right: 1px solid var(--line);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.sidebar-brand {
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-right: 0.15rem;
  scrollbar-gutter: stable;
}

.brand-logo {
  width: 100%;
  max-width: 168px;
  height: auto;
  display: block;
  margin: 0 auto 0.75rem;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.35));
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  margin: 0 0 0.25rem;
  text-align: center;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0 0 1rem;
  text-align: center;
}

.price-items {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  margin-bottom: 0.9rem;
  max-height: 240px;
  overflow: auto;
  background: #1a0f22;
}

.price-item-row {
  display: grid;
  grid-template-columns: 1fr 110px 36px;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
  align-items: center;
}

.order-item-row {
  display: grid;
  grid-template-columns: 1fr 90px 90px 36px;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
  align-items: center;
}

.price-item-row input,
.price-item-row select,
.order-item-row input,
.order-item-row select {
  margin: 0;
}

.section-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.35rem 0 0.45rem;
}

.expedition-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.85rem;
  align-items: start;
}

.expedition-col {
  background: color-mix(in srgb, var(--panel) 85%, black);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  min-height: 180px;
}

.expedition-col h3 {
  margin: 0 0 0.65rem;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 650;
}

.expedition-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.75rem;
  margin-bottom: 0.55rem;
}

.expedition-card:last-child { margin-bottom: 0; }

.expedition-card strong {
  display: block;
  margin-bottom: 0.2rem;
}

.expedition-card .meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 0.55rem;
  line-height: 1.35;
}

.expedition-card .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.expedition-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.4rem 0;
}

.report-exports {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.report-exports .btn {
  width: auto;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
}

.reports-page {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 2.5rem);
}

.reports-page .topbar {
  margin-bottom: 0.75rem;
}

.report-kpis {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) repeat(2, minmax(140px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.report-kpi {
  background: color-mix(in srgb, var(--panel) 85%, black);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.report-kpi-main {
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--accent) 22%, var(--panel)),
    color-mix(in srgb, var(--panel) 88%, black)
  );
}

.report-kpi-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.report-kpi strong {
  font-size: 1.35rem;
  line-height: 1.15;
  word-break: break-word;
}

.report-kpi-main strong {
  font-size: 1.7rem;
}

.report-kpi-text {
  font-size: 0.95rem !important;
  font-weight: 600;
  color: var(--ink);
}

.report-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.7rem;
}

.report-tab {
  width: auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.report-tab.active {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  color: var(--ink);
}

.report-panels {
  flex: 1;
  min-height: 0;
}

.report-panel {
  min-height: 0;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.7rem;
}

.report-grid-sales {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.report-grid-stock {
  grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr);
}

.report-card {
  background: color-mix(in srgb, var(--panel) 85%, black);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.report-card h3 {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
}

.report-card-wide {
  grid-column: 1 / -1;
}

.report-table-scroll {
  max-height: min(52vh, 520px);
  overflow: auto;
}

.report-table-scroll-tall {
  max-height: min(62vh, 640px);
}

.report-table {
  min-width: 0 !important;
}

.report-table th,
.report-table td {
  padding: 0.45rem 0.55rem;
  font-size: 0.9rem;
}

@media (max-width: 1100px) {
  .report-grid-sales,
  .report-grid-stock {
    grid-template-columns: 1fr;
  }

  .report-kpis {
    grid-template-columns: 1fr;
  }
}

.badge-warn {
  background: rgba(230, 195, 92, 0.2);
  color: var(--warn);
}

.help-list {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.55;
}

.help-list code {
  color: var(--ink);
  font-size: 0.9em;
}

#permissions-table th,
#permissions-table td {
  text-align: center;
  vertical-align: middle;
}

#permissions-table th:first-child,
#permissions-table td:first-child {
  text-align: left;
  min-width: 180px;
}

#permissions-table input[type="checkbox"] {
  width: auto;
  margin: 0;
}

#permissions-table th,
#permissions-table td {
  text-align: center;
  vertical-align: middle;
}

#permissions-table th:first-child,
#permissions-table td:first-child {
  text-align: left;
  min-width: 180px;
}

#permissions-table input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.order-item-price {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

.nav-btn {
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
}

.nav-btn:hover { background: var(--panel-2); }
.nav-btn.active {
  background: var(--panel-2);
  border-color: var(--line);
}

.sidebar-foot {
  flex-shrink: 0;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.user-chip {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  line-height: 1.35;
}

.main {
  padding: 1.25rem 1.5rem 2rem;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.topbar h2 {
  margin: 0;
  font-size: 1.35rem;
}

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

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
}

.filters input, .filters select {
  margin: 0;
  width: auto;
  min-width: 180px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 80%, black);
}

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

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

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.18);
}

tr:last-child td { border-bottom: 0; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid var(--line);
}

.badge.on { color: var(--accent); border-color: #3f7a55; }
.badge.off { color: var(--danger); border-color: #7a3434; }

.row-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.row-actions .btn {
  padding: 0.4rem 0.65rem;
  font-size: 0.85rem;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  justify-items: center;
  align-items: start;
  padding: 1rem;
  z-index: 40;
  overflow-y: auto;
}

.dialog {
  width: min(520px, 100%);
  max-height: calc(100dvh - 2rem);
  margin: auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.25rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dialog-wide {
  width: min(860px, 100%);
}

.qty-pos { color: var(--accent); }
.qty-neg { color: var(--danger); }

.dialog h3 {
  margin: 0 0 1rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.unit-qty-row {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr);
  gap: 0.55rem;
}

.unit-qty-row input,
.unit-qty-row select {
  margin: 0;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: -0.4rem 0 0.9rem;
}

.empty {
  padding: 1.5rem;
  color: var(--muted);
}

@media (max-width: 860px) {
  #app-view {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100dvh;
    min-height: 100dvh;
  }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    height: auto;
    max-height: none;
    padding: 0.75rem;
    gap: 0.65rem;
  }
  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
  }
  .brand-logo {
    width: 44px;
    max-width: 44px;
    margin: 0;
  }
  .brand, .brand-sub {
    text-align: left;
    margin: 0;
  }
  .brand-sub { display: none; }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0.4rem;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .nav-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.55rem 0.75rem;
    font-size: 0.9rem;
  }
  .sidebar-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-top: 0;
    padding-top: 0.65rem;
  }
  .user-chip {
    flex: 1 1 auto;
    margin-bottom: 0;
    font-size: 0.8rem;
  }
  .main {
    height: auto;
    padding: 1rem 0.9rem 1.5rem;
    -webkit-overflow-scrolling: touch;
  }
  .toolbar {
    flex-wrap: wrap;
  }
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
