/* ESpsa Backend — full UI replacement for ESPSA_Pro.exe */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: #f5f6f8;
  color: #1a1a1a;
  font-size: 15px;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 0.93em; }

/* ======================== Top nav ======================== */
.topnav {
  display: flex;
  align-items: center;
  gap: 1em;
  background: linear-gradient(135deg, #1f2937, #111827);
  color: white;
  padding: 0.7em 1.5em;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  position: sticky; top: 0; z-index: 100;
}
.topnav a { color: white; opacity: 0.85; }
.topnav a:hover { opacity: 1; text-decoration: none; }
.topnav .brand { font-size: 1.25em; font-weight: 700; opacity: 1; margin-right: 0.5em; }
.nav-links { display: flex; gap: 1em; flex: 1; flex-wrap: wrap; row-gap: 0.4em; min-width: 0; }
.nav-links a { padding: 0.3em 0.5em; }
.nav-user { display: flex; align-items: center; gap: 0.8em; font-size: 0.9em; flex-shrink: 0; }
.lang-switch {
  display: inline-flex;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 12px;
  overflow: hidden;
  font-size: 0.82em;
}
.lang-switch a {
  padding: 0.2em 0.55em !important;
  opacity: 0.5;
  text-decoration: none !important;
}
.lang-switch a:hover { opacity: 0.9; background: rgba(255,255,255,0.1); }
.lang-switch a.lang-active {
  opacity: 1;
  background: #fbbf24;
  color: #1f2937 !important;
  font-weight: 700;
}
.user-name { font-weight: 500; }
.user-role { background: rgba(255,255,255,0.15); padding: 0.15em 0.55em; border-radius: 10px; font-size: 0.8em; }
.logout { color: #fca5a5 !important; }
.nav-toggle { display: none; background: none; border: 1px solid rgba(255,255,255,0.3); color: white; padding: 0.3em 0.7em; border-radius: 4px; cursor: pointer; font-size: 1.1em; }

/* Mobile nav */
@media (max-width: 768px) {
  .nav-toggle { display: block; }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%; left: 0; right: 0;
    flex-direction: column;
    background: #1f2937;
    padding: 0.5em;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 0.8em 1em; border-radius: 4px; }
  .nav-user { font-size: 0.8em; }
  .user-name { display: none; }
}

main {
  padding: 1.5em;
  max-width: 1400px;
  margin: 0 auto;
}
@media (max-width: 600px) {
  main { padding: 1em 0.7em; }
}

/* ======================== Login page ======================== */
.login-body {
  background: linear-gradient(135deg, #1f2937, #2563eb);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1em;
}
.login-box {
  background: white;
  padding: 2.5em;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 380px;
}
.login-box h1 { margin: 0; font-size: 2em; text-align: center; }
.login-subtitle { text-align: center; color: #6b7280; margin: 0.3em 0 1.8em; font-size: 0.9em; }
.login-error { background: #fee2e2; color: #991b1b; padding: 0.7em 1em; border-radius: 6px; margin-bottom: 1em; font-size: 0.9em; }
.login-box form label { display: block; margin: 0.8em 0 0.3em; font-size: 0.9em; color: #4b5563; font-weight: 500; }
.login-box form input { width: 100%; padding: 0.7em; border: 1px solid #d1d5db; border-radius: 6px; font-size: 1em; }
.login-box form button { width: 100%; margin-top: 1.5em; padding: 0.9em; background: #2563eb; color: white; border: none; border-radius: 6px; font-size: 1.05em; font-weight: 600; cursor: pointer; }
.login-box form button:hover { background: #1d4ed8; }
.login-hint { margin-top: 1.5em; text-align: center; font-size: 0.85em; color: #6b7280; }
.login-hint code { background: #f3f4f6; padding: 0.1em 0.4em; border-radius: 3px; }

/* ======================== Page header ======================== */
.page-header { margin-bottom: 1.5em; }
.page-header h1 { margin: 0.2em 0; font-size: 1.6em; }
.page-header .subtitle { color: #6b7280; font-size: 0.95em; }
.back-link { display: inline-block; margin-bottom: 0.4em; font-size: 0.9em; }

/* ======================== Flash messages ======================== */
.flash-msg {
  background: #d1fae5; color: #065f46; border-left: 4px solid #10b981;
  padding: 1em 1.5em; border-radius: 6px; margin-bottom: 1.5em; font-weight: 500;
}
.warning-banner {
  background: #fef3c7; color: #92400e; border-left: 4px solid #f59e0b;
  padding: 1em; border-radius: 4px; margin-bottom: 1em;
}

/* ======================== Search / date forms ======================== */
.search-form, .date-form {
  display: flex;
  gap: 0.5em;
  align-items: center;
  margin-bottom: 1em;
  flex-wrap: wrap;
}
.search-form input[type="text"], .date-form input[type="date"], .date-form input[type="number"] {
  flex: 1; max-width: 400px; padding: 0.6em 1em;
  border: 1px solid #d1d5db; border-radius: 6px; font-size: 1em;
}
.date-form input[type="number"] { max-width: 120px; }
.search-form button, .date-form button {
  padding: 0.6em 1.5em; background: #2563eb; color: white;
  border: none; border-radius: 6px; cursor: pointer; font-size: 1em;
}
.search-form button:hover, .date-form button:hover { background: #1d4ed8; }
.clear-btn { padding: 0.6em 1em; background: #e5e7eb; color: #1f2937; border-radius: 6px; }

/* ======================== Stat cards ======================== */
.card-grid { display: grid; gap: 1em; margin-bottom: 1.5em; }
.card-grid-3 { grid-template-columns: repeat(3, 1fr); }
.card-grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 700px) {
  .card-grid-3, .card-grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 460px) {
  .card-grid-3, .card-grid-4 { grid-template-columns: 1fr; }
}

.stat-card {
  background: white;
  padding: 1.2em 1.5em;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border-top: 4px solid #ccc;
}
.stat-blue   { border-top-color: #2563eb; }
.stat-green  { border-top-color: #10b981; }
.stat-amber  { border-top-color: #f59e0b; }
.stat-purple { border-top-color: #8b5cf6; }
.stat-red    { border-top-color: #ef4444; }
.stat-label { font-size: 0.85em; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 2em; font-weight: 700; margin-top: 0.2em; }
.stat-value-small { font-size: 1.1em; font-weight: 600; margin-top: 0.2em; color: #4b5563; }

/* ======================== Dash section ======================== */
.dash-section {
  background: white; padding: 1.5em; border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08); margin-bottom: 1.5em;
}
.dash-section h2 {
  margin: 0 0 1em; font-size: 1.15em;
  padding-bottom: 0.6em; border-bottom: 1px solid #f3f4f6;
}
.dual-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5em; }
@media (max-width: 900px) { .dual-col { grid-template-columns: 1fr; } }

/* ======================== Trend chart ======================== */
.trend-chart {
  display: flex; gap: 1%; align-items: flex-end;
  height: 180px; padding: 1em 0; border-bottom: 1px solid #e5e7eb;
}
.trend-bar {
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  height: 100%; position: relative;
}
.trend-fill {
  width: 80%; background: linear-gradient(180deg, #2563eb, #60a5fa);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: opacity 0.2s;
}
.trend-bar:hover .trend-fill { opacity: 0.85; }
.trend-label { font-size: 0.75em; color: #6b7280; margin-top: 0.3em; }
.trend-value { font-size: 0.7em; color: #1f2937; font-weight: 600; margin-top: 0.1em; }

/* ======================== Tables ======================== */
.goods-table, .compact-table {
  width: 100%; background: white; border-collapse: collapse;
  border-radius: 8px; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.goods-table th, .compact-table th {
  background: #f9fafb; text-align: left; padding: 0.7em 1em;
  font-size: 0.85em; color: #6b7280; text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 600; border-bottom: 2px solid #e5e7eb;
}
.goods-table td, .compact-table td {
  padding: 0.6em 1em; border-bottom: 1px solid #f3f4f6; vertical-align: middle;
}
.compact-table td, .compact-table th { padding: 0.45em 0.7em; }
.goods-table tr:hover, .compact-table tr:hover { background: #f9fafb; }
.goods-table .num, .compact-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.goods-table .mono, .compact-table .mono { font-family: ui-monospace, monospace; font-size: 0.9em; }
.goods-table .goodname { max-width: 380px; }
.goods-table .goodname small { color: #6b7280; display: block; font-size: 0.85em; margin-top: 2px; }
.goods-table .muted, .compact-table .muted, td.muted { color: #9ca3af; font-size: 0.88em; }
.goods-table .empty { text-align: center; color: #9ca3af; padding: 3em; }
.goods-table .price, .compact-table .price { font-weight: 600; color: #059669; }
.goods-table .price-old, .compact-table .price-old { color: #9ca3af; }
.goods-table .negative, .compact-table .negative { color: #dc2626; font-weight: 600; }

/* Responsive tables: stack on mobile */
@media (max-width: 700px) {
  .goods-table { display: block; overflow-x: auto; white-space: nowrap; }
  .goods-table thead { display: none; }
  .goods-table tbody tr { display: block; padding: 0.5em 0; border-bottom: 1px solid #f3f4f6; }
  .goods-table tbody td { display: inline-block; border: none; padding: 0.2em 0.5em; white-space: normal; }
  .goods-table tbody td.goodname { display: block; font-weight: 600; }
}

/* ======================== Buttons ======================== */
.btn-edit {
  display: inline-block; padding: 0.35em 0.9em;
  background: #2563eb; color: white !important;
  border-radius: 4px; font-size: 0.9em; cursor: pointer;
}
.btn-edit:hover { background: #1d4ed8; text-decoration: none; }
.btn-big {
  display: inline-block; padding: 0.8em 1.5em;
  border: none; border-radius: 6px; font-size: 1em; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn-primary { background: #2563eb; color: white; }
.btn-primary:hover { background: #1d4ed8; text-decoration: none; }
.btn-secondary { background: #6b7280; color: white; }
.btn-secondary:hover { background: #4b5563; text-decoration: none; }

/* ======================== Audit tags ======================== */
.modal-tag {
  display: inline-block; padding: 0.2em 0.6em;
  border-radius: 12px; font-size: 0.85em; font-weight: 500;
}
.modal-1 { background: #dbeafe; color: #1e40af; }
.modal-2 { background: #fef3c7; color: #92400e; }
.modal-3 { background: #f3f4f6; color: #374151; }

/* ======================== Pagination ======================== */
.pagination {
  margin-top: 1em; display: flex; gap: 1em;
  align-items: center; justify-content: center;
}
.pagination a {
  padding: 0.5em 1em; background: white;
  border: 1px solid #d1d5db; border-radius: 4px;
}
.pagination-info { color: #6b7280; }

/* ======================== Edit grid ======================== */
.edit-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5em; margin-top: 1.5em;
}
.edit-card {
  background: white; padding: 1.5em;
  border-radius: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.edit-card h2 {
  margin: 0 0 1em; font-size: 1.15em;
  padding-bottom: 0.6em; border-bottom: 1px solid #f3f4f6;
}
.card-price { border-top: 3px solid #10b981; }
.card-stock { border-top: 3px solid #f59e0b; }
.card-misc  { border-top: 3px solid #6b7280; }
.card-info  { border-top: 3px solid #2563eb; }
.kv {
  display: flex; justify-content: space-between;
  padding: 0.4em 0; border-bottom: 1px dashed #f3f4f6;
}
.kv:last-child { border-bottom: none; }
.kv strong { font-size: 1.4em; color: #1f2937; }
.edit-card label {
  display: block; margin: 1em 0 0.3em;
  font-size: 0.9em; color: #4b5563; font-weight: 500;
}
.edit-card input[type="number"],
.edit-card input[type="text"],
.edit-card textarea {
  width: 100%; padding: 0.6em;
  border: 1px solid #d1d5db; border-radius: 6px;
  font-size: 1.1em; font-family: inherit;
}
.edit-card textarea { font-size: 0.95em; resize: vertical; }
.edit-card button {
  width: 100%; margin-top: 1em; padding: 0.8em;
  border: none; border-radius: 6px;
  font-size: 1em; font-weight: 600; cursor: pointer;
}
em.danger { color: #dc2626; font-style: normal; font-weight: 600; }
em.ok { color: #059669; font-style: normal; font-weight: 600; }

/* ======================== Scan page ======================== */
.scan-container { max-width: 600px; margin: 0 auto; }
.scan-mode { display: flex; gap: 0.5em; margin-bottom: 1em; }
.mode-btn {
  flex: 1; padding: 0.7em; background: #e5e7eb; color: #1f2937;
  border: none; border-radius: 6px; font-size: 1em; cursor: pointer;
}
.mode-btn.active { background: #2563eb; color: white; }
.scan-status {
  padding: 1em; background: white; border-radius: 6px;
  margin-bottom: 1em; text-align: center; font-weight: 500;
}
.scan-status.active { background: #dbeafe; color: #1e40af; }
.scan-status.success { background: #d1fae5; color: #065f46; }
.scan-status.error { background: #fee2e2; color: #991b1b; }
#scanVideo {
  width: 100%; max-height: 60vh; background: #000;
  border-radius: 8px; display: block; margin-bottom: 1em;
}
.scan-actions { text-align: center; }
.scan-actions button { margin: 0 0.3em; }
.scan-hint {
  margin-top: 1em; font-size: 0.85em; color: #6b7280; text-align: center;
}
.manual-form { display: flex; gap: 0.5em; }
.manual-form input { flex: 1; padding: 0.8em; font-size: 1.2em; border: 1px solid #d1d5db; border-radius: 6px; font-family: monospace; }
.scan-recent { background: white; padding: 1em; border-radius: 8px; margin-top: 1.5em; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.scan-recent h3 { margin: 0 0 0.5em; font-size: 1em; color: #6b7280; }
.scan-recent ul { list-style: none; padding: 0; margin: 0; }
.scan-recent li { padding: 0.5em 0; border-bottom: 1px solid #f3f4f6; font-size: 0.9em; }

/* ======================== Export page ======================== */
.export-card {
  background: white; padding: 1.5em; border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08); border-top: 3px solid #2563eb;
}
.export-card h3 { margin: 0 0 0.5em; font-size: 1.1em; }
.export-card p { font-size: 0.9em; }
.export-card form button { margin-top: 0.5em; width: 100%; }
.export-card label { display: block; margin: 0.7em 0 0.2em; font-size: 0.9em; color: #4b5563; font-weight: 500; }
.export-card input { width: 100%; padding: 0.5em; border: 1px solid #d1d5db; border-radius: 4px; }

/* ======================== Not-found page ======================== */
.not-found {
  background: white; padding: 3em; border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08); text-align: center;
}
.not-found h1 { font-size: 2em; margin-top: 0; }
.not-found .actions { display: flex; gap: 0.8em; justify-content: center; margin-top: 1.5em; flex-wrap: wrap; }

.footer-info { text-align: center; margin-top: 2em; color: #9ca3af; font-size: 0.9em; }

/* ======================== Nav improvements ======================== */
.nav-group {
  display: flex;
  gap: 0.3em;
  align-items: center;
  position: relative;
  padding: 0 0.4em;
  border-right: 1px solid rgba(255,255,255,0.1);
}
.nav-group:last-child { border-right: none; }
.nav-group-label {
  display: none;
  font-size: 0.7em;
  opacity: 0.5;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 0.3em;
}
.topnav a {
  white-space: nowrap;
  font-size: 0.92em;
  padding: 0.3em 0.6em;
  border-radius: 4px;
  transition: background 0.15s;
}
.topnav a:hover { background: rgba(255,255,255,0.1); }
@media (max-width: 768px) {
  .nav-group {
    flex-direction: column;
    align-items: stretch;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding: 0.5em 0;
  }
  .nav-group-label { display: block; padding: 0 1em; }
  .nav-group:last-child { border-bottom: none; }
}

/* ======================== Review layout (TIENDA style) ======================== */
.review-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1em;
  align-items: start;
}
@media (max-width: 1100px) {
  .review-grid { grid-template-columns: 280px 1fr; }
}
@media (max-width: 900px) {
  .review-grid { grid-template-columns: 1fr; }
}

.action-pane {
  position: sticky;
  top: 4.5em;
  display: flex;
  flex-direction: column;
  gap: 1em;
}
@media (max-width: 900px) { .action-pane { position: static; } }

.scan-card, .lookup-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 1em;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.scan-card h3 {
  margin: 0 0 0.6em;
  font-size: 0.85em;
  color: #6b7280;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.lookup-card {
  border-left: 4px solid #2563eb;
  background: #eff6ff;
}
.lookup-name { font-size: 1.05em; font-weight: 700; margin-bottom: 0.3em; }
.lookup-sub { font-size: 0.85em; margin-bottom: 0.8em; }
.lookup-sub code { background: white; padding: 0.1em 0.4em; border-radius: 3px; }
.qty-price-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5em;
  margin-bottom: 0.7em;
}
.qty-price-row label {
  display: block;
  font-size: 0.78em;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.2em;
}
.qty-price-row input {
  width: 100%;
  padding: 0.5em;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 1.05em;
  font-weight: 600;
}
.btn-add {
  width: 100%;
  padding: 0.7em;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95em;
}

.right-pane {
  display: flex;
  flex-direction: column;
  gap: 0.9em;
}

/* header-card */
.header-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 0.9em 1em;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.header-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.7em;
}
.header-grid .field { display: flex; flex-direction: column; }
.header-grid .field label {
  font-size: 0.7em;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #6b7280;
  margin-bottom: 0.25em;
  text-transform: uppercase;
}
.header-grid .field input {
  background: #f9fafb;
  border: 1px solid #d1d5db;
  padding: 0.5em 0.7em;
  border-radius: 5px;
  font-size: 0.92em;
  outline: none;
  width: 100%;
}
.header-grid .field input:focus {
  border-color: #2563eb;
  background: white;
}
.header-grid .field input[readonly] {
  color: #9ca3af;
  background: #f3f4f6;
}

/* lines-card */
.lines-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.lines-toolbar {
  padding: 0.6em 1em;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  font-size: 0.88em;
}
.lines-scroll { overflow-x: auto; }
.lines-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.88em;
}
.lines-table th {
  background: #f9fafb;
  padding: 0.5em 0.6em;
  text-align: left;
  font-size: 0.7em;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #e5e7eb;
}
.lines-table td {
  padding: 0.4em 0.6em;
  vertical-align: middle;
  border-bottom: 1px solid #f3f4f6;
}
.lines-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.lines-table .mono { font-family: ui-monospace, monospace; font-size: 0.92em; }
.lines-table .col-desc { font-weight: 500; }
.lines-table .empty {
  text-align: center;
  padding: 2.5em 1em;
  color: #9ca3af;
}
.lines-table .price { color: #059669; font-weight: 700; }
.lines-table .ok { color: #059669; font-weight: 600; }
.lines-table .muted { color: #9ca3af; }
.lines-table input[type=number] {
  width: 100%;
  padding: 0.35em 0.5em;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 0.95em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  background: white;
}
.lines-table input[type=number]:focus {
  border-color: #2563eb;
  outline: none;
  background: #eff6ff;
}
.lines-table input[type=number]::-webkit-inner-spin-button,
.lines-table input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none; margin: 0;
}
.btn-rm {
  background: transparent;
  border: 1px solid #fca5a5;
  color: #dc2626;
  border-radius: 4px;
  padding: 0.2em 0.5em;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85em;
}
.btn-rm:hover { background: #dc2626; color: white; }

/* totals-footer */
.totals-footer {
  background: linear-gradient(135deg, #f0f9ff, #eff6ff);
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 0.8em 1.2em;
  font-size: 0.95em;
}
.tf-row {
  display: flex;
  align-items: center;
  gap: 0.8em;
  flex-wrap: wrap;
}
.tf-label { color: #6b7280; font-size: 0.88em; }
.tf-val { color: #1f2937; font-size: 1.05em; }
.tf-vs { color: #d1d5db; }
.tf-price { color: #059669 !important; font-size: 1.2em !important; }

/* actions */
.actions {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 0.9em 1em;
  display: flex;
  gap: 0.7em;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.actions .grow { flex: 1; }
.btn-action {
  padding: 0.7em 1.3em;
  border: none;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95em;
}
.btn-submit { font-size: 1.05em; padding: 0.8em 1.6em; }

/* ======================== Sortable column headers ======================== */
.sort-link {
  color: inherit !important;
  text-decoration: none !important;
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  white-space: nowrap;
}
.sort-link:hover { color: #2563eb !important; }
.sort-link .sort-arrow { font-size: 0.85em; opacity: 0.4; transition: opacity 0.15s; }
.sort-link:hover .sort-arrow { opacity: 0.8; }
.sort-link.sort-active { color: #2563eb !important; font-weight: 700; }
.sort-link.sort-active .sort-arrow { opacity: 1; color: #2563eb; }

/* ======================== Bulk selection floating bar ======================== */
.bulk-bar {
  position: fixed;
  bottom: 1.5em;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: white;
  padding: 0.7em 1.2em;
  border-radius: 50px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 150;
  display: flex;
  align-items: center;
  gap: 0.7em;
  font-size: 0.95em;
  border: 1px solid rgba(255,255,255,0.1);
}
.bulk-bar strong { color: #fbbf24; font-size: 1.1em; }
.bulk-bar .grow { flex: 1; min-width: 0.5em; }
.bulk-bar button, .bulk-bar a {
  padding: 0.45em 0.9em;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88em;
  text-decoration: none !important;
}
.bulk-bar .btn-secondary {
  background: rgba(255,255,255,0.15);
  color: white !important;
}
.bulk-bar .btn-primary {
  background: #fbbf24 !important;
  color: #1f2937 !important;
  padding: 0.55em 1.2em !important;
}
.bulk-bar .btn-primary:hover { background: #f59e0b !important; }

input.row-check, #checkAll {
  width: 1.2em;
  height: 1.2em;
  cursor: pointer;
  accent-color: #2563eb;
}

@media (max-width: 600px) {
  .bulk-bar {
    left: 0.5em; right: 0.5em; transform: none;
    bottom: 0.5em; border-radius: 12px;
    flex-wrap: wrap;
  }
}

/* ======================== Goods layout (sidebar) ======================== */
.goods-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 1.5em;
  align-items: start;
}
.goods-sidebar {
  background: white;
  padding: 0.8em;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  position: sticky;
  top: 4.5em;
  max-height: calc(100vh - 5.5em);
  overflow-y: auto;
}
.goods-sidebar h3 {
  margin: 0.3em 0 0.7em;
  padding: 0 0.5em;
  font-size: 0.78em;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.goods-sidebar a {
  display: block;
  padding: 0.7em 0.9em;
  border-radius: 6px;
  color: #374151 !important;
  margin-bottom: 0.15em;
  font-size: 0.96em;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.goods-sidebar a:hover {
  background: #f3f4f6;
  text-decoration: none !important;
}
.goods-sidebar a.active {
  background: #eff6ff;
  color: #1d4ed8 !important;
  font-weight: 600;
  border-left-color: #2563eb;
}
.goods-content {
  min-width: 0;
}

@media (max-width: 768px) {
  .goods-layout {
    grid-template-columns: 1fr;
    gap: 0.7em;
  }
  .goods-sidebar {
    position: static;
    max-height: none;
    padding: 0.4em;
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 0.3em;
    -webkit-overflow-scrolling: touch;
  }
  .goods-sidebar h3 { display: none; }
  .goods-sidebar a {
    flex-shrink: 0;
    margin: 0;
    padding: 0.55em 0.9em;
    white-space: nowrap;
    font-size: 0.9em;
    border-left: none;
    border-bottom: 3px solid transparent;
  }
  .goods-sidebar a.active {
    border-left: none;
    border-bottom-color: #2563eb;
  }
}

/* ======================== Nav dropdown ======================== */
.nav-dropdown {
  position: relative;
  display: inline-block;
}
.nav-dropdown-toggle {
  cursor: pointer;
  padding: 0.3em 0.6em;
  border-radius: 4px;
  white-space: nowrap;
}
.nav-submenu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: #1f2937;
  min-width: 180px;
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.3);
  z-index: 200;
  padding: 0.4em 0;
  margin-top: 0.3em;
  border: 1px solid rgba(255,255,255,0.1);
}
.nav-submenu a {
  display: block !important;
  padding: 0.6em 1em !important;
  white-space: nowrap;
  font-size: 0.95em;
  color: white !important;
  border-radius: 0 !important;
}
.nav-submenu a:hover {
  background: rgba(37, 99, 235, 0.5) !important;
}

/* Desktop: hover to open */
@media (min-width: 769px) {
  .nav-dropdown:hover .nav-submenu { display: block; }
  .nav-dropdown:hover .nav-dropdown-toggle { background: rgba(255,255,255,0.1); }
}

/* Mobile: click toggle (handled in JS) */
@media (max-width: 768px) {
  .nav-dropdown { display: block; width: 100%; }
  .nav-submenu {
    position: static;
    box-shadow: none;
    border: none;
    background: rgba(0,0,0,0.3);
    margin-top: 0;
    margin-left: 1em;
    border-radius: 0;
    border-left: 2px solid rgba(255,255,255,0.2);
  }
  .nav-dropdown.open .nav-submenu { display: block; }
  .nav-submenu a { padding: 0.7em 1em !important; }
}

/* ======================== Filter bar ======================== */
.filter-bar { margin-bottom: 1em; }
.filter-bar .search-form { align-items: center; }
.filter-bar select {
  padding: 0.6em;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.95em;
  background: white;
  min-width: 130px;
}

/* ======================== Tags ======================== */
.tag {
  display: inline-block;
  padding: 0.15em 0.55em;
  border-radius: 4px;
  font-size: 0.83em;
  font-weight: 500;
  background: #e5e7eb;
  color: #374151;
}
.tag-cat { background: #ede9fe; color: #6d28d9; font-family: monospace; }

/* Stock cell colors */
.goods-table td.zero { color: #f59e0b; font-weight: 600; }
.goods-table td.low { color: #ef4444; font-weight: 600; }

/* ======================== Categories grid ======================== */
.cat-card {
  background: white;
  border-radius: 12px;
  padding: 1.2em;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  text-decoration: none !important;
  color: inherit;
  display: block;
  border-top: 4px solid #8b5cf6;
  transition: transform 0.15s, box-shadow 0.15s;
}
.cat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(0,0,0,0.12);
  text-decoration: none !important;
}
.cat-code {
  font-size: 0.75em;
  color: #6d28d9;
  font-family: monospace;
  background: #ede9fe;
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: 4px;
  margin-bottom: 0.3em;
}
.cat-name {
  font-size: 1.3em;
  font-weight: 700;
  margin-bottom: 0.7em;
  color: #1f2937;
}
.cat-stats { font-size: 0.9em; line-height: 1.6; }
.cat-stats > div { display: flex; justify-content: space-between; padding: 0.1em 0; }
.cat-stats .warn { color: #f59e0b; font-weight: 500; margin-top: 0.5em; }
.cat-meta { margin-top: 0.7em; font-size: 0.8em; color: #9ca3af; }

/* ======================== Percentage bar ======================== */
.pct-bar {
  display: inline-block;
  width: 80px;
  height: 8px;
  background: #f3f4f6;
  border-radius: 4px;
  margin-right: 0.5em;
  vertical-align: middle;
  overflow: hidden;
}
.pct-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #34d399);
  border-radius: 4px;
}

/* ======================== Line builder (inbound / return) ======================== */
.line-builder { display: grid; gap: 1.5em; }
.add-form { display: flex; gap: 0.5em; }
.add-form input[type="text"] {
  flex: 1; padding: 0.7em; font-size: 1.1em;
  border: 1px solid #d1d5db; border-radius: 6px; font-family: monospace;
}
.add-form button { padding: 0.7em 1.2em; border: none; border-radius: 6px; font-size: 1em; cursor: pointer; }
.add-form button.btn-secondary { background: #e5e7eb; color: #1f2937; }

.lookup-result {
  background: #f0f9ff;
  padding: 1.2em;
  border-radius: 8px;
  margin-top: 1em;
  border-left: 4px solid #2563eb;
}
.lookup-info { margin-bottom: 1em; }
.lookup-info strong { font-size: 1.2em; }
.add-line-form {
  display: flex; gap: 0.7em; align-items: end;
}
.add-line-form > div { flex: 1; }
.add-line-form label { display: block; font-size: 0.85em; margin-bottom: 0.2em; color: #4b5563; }
.add-line-form input {
  width: 100%; padding: 0.6em; border: 1px solid #d1d5db; border-radius: 6px; font-size: 1.1em;
}
.add-line-form button { padding: 0.6em 1.2em; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; }

textarea {
  width: 100%; padding: 0.6em;
  border: 1px solid #d1d5db; border-radius: 6px;
  font-family: inherit; font-size: 0.95em; resize: vertical;
}
.dash-section label {
  display: block; margin-bottom: 0.3em; font-size: 0.9em; color: #4b5563; font-weight: 500;
}

/* Footer total row in tables */
.goods-table tfoot td {
  background: #f9fafb;
  border-top: 2px solid #e5e7eb;
  font-weight: 600;
}

.stat-card.stat-red { border-top-color: #ef4444; }
