/* LapiStok - navy & grey theme */
:root {
  --navy-900: #0f2440;
  --navy-800: #1e3a5f;
  --navy-700: #2a4d7a;
  --navy-100: #e3eaf3;
  --grey-900: #1f2933;
  --grey-700: #3e4c59;
  --grey-500: #7b8794;
  --grey-300: #cbd2d9;
  --grey-200: #e4e7eb;
  --grey-100: #f2f4f7;
  --white: #ffffff;
  --red-700: #b42318;
  --red-50: #fef3f2;
  --green-700: #067647;
  --green-50: #ecfdf3;
  --amber-700: #8a5a00;
  --amber-50: #fffaeb;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--grey-900);
  background: var(--grey-100);
}

[hidden] { display: none !important; }

a { color: var(--navy-700); }

h1, h2, h3 { color: var(--navy-900); line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  outline: none;
}

.muted { color: var(--grey-500); }
.mono { font-family: var(--mono); }
.small { font-size: 0.85rem; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--navy-800);
  color: var(--white);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 8px 24px;
  flex-wrap: wrap;
}
.brand {
  color: var(--white);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background:
    linear-gradient(var(--white), var(--white)) 4px 6px / 14px 2px no-repeat,
    linear-gradient(var(--white), var(--white)) 4px 10px / 14px 2px no-repeat,
    linear-gradient(var(--white), var(--white)) 4px 14px / 14px 2px no-repeat,
    var(--navy-700);
}
.nav { display: flex; gap: 4px; }
.nav a {
  color: #d5deea;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, 0.08); color: var(--white); }
.nav a[aria-current="page"] { background: var(--navy-900); color: var(--white); }
.account {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.account-name {
  color: #c3cfdf;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 9px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  background: var(--white);
  color: var(--navy-800);
  border-color: var(--grey-300);
}
.btn:hover { background: var(--grey-100); }
.btn:focus-visible, .input:focus-visible, .select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid #8fb3e0;
  outline-offset: 1px;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--navy-800); color: var(--white); border-color: var(--navy-800); }
.btn-primary:hover { background: var(--navy-900); }
.btn-danger { background: var(--white); color: var(--red-700); border-color: #f1b8b3; }
.btn-danger:hover { background: var(--red-50); }
.btn-danger-solid { background: var(--red-700); color: var(--white); border-color: var(--red-700); }
.btn-danger-solid:hover { background: #912018; }
.btn-sm { padding: 5px 10px; font-size: 0.85rem; }
.btn-lg { padding: 13px 24px; font-size: 1.05rem; }
.btn-ghost-light { background: transparent; color: #d5deea; border-color: rgba(255, 255, 255, 0.25); }
.btn-ghost-light:hover { background: rgba(255, 255, 255, 0.08); color: var(--white); }
.btn-link {
  background: none; border: none; padding: 0; color: var(--navy-700);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline;
}

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 0.9rem; color: var(--grey-700); }
.field .req { color: var(--red-700); }
.field-hint { font-size: 0.8rem; color: var(--grey-500); }
.field-error { font-size: 0.85rem; color: var(--red-700); font-weight: 500; }
.input, .select, textarea {
  font: inherit;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--grey-300);
  border-radius: 6px;
  background: var(--white);
  color: var(--grey-900);
}
textarea { resize: vertical; min-height: 70px; }
.input[aria-invalid="true"], .select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--red-700);
  background: var(--red-50);
}

/* ---------- Cards / layout ---------- */
.card {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head p { margin: 4px 0 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stack > * + * { margin-top: 16px; }

/* ---------- Search hero ---------- */
.search-hero {
  background: var(--navy-800);
  color: var(--white);
  border-radius: 10px;
  padding: 28px 24px;
  margin-bottom: 20px;
}
.search-hero h1 { color: var(--white); font-size: 1.6rem; }
.search-hero p { color: #c3cfdf; margin: 6px 0 18px; }
.search-form { display: flex; gap: 10px; flex-wrap: wrap; }
.search-form .search-input {
  flex: 1 1 320px;
  min-width: 0;
  font-size: 1.25rem;
  padding: 14px 16px;
  border-radius: 8px;
  border: 2px solid transparent;
  font-family: var(--mono);
}
.search-form .search-input:focus-visible { outline: none; border-color: #8fb3e0; }
.search-form .select { flex: 0 1 190px; padding: 14px 12px; border-radius: 8px; font-size: 1rem; }
.search-form .btn { padding: 14px 26px; font-size: 1.05rem; border-radius: 8px; }
.search-form .btn-primary { background: var(--white); color: var(--navy-800); border-color: var(--white); }
.search-form .btn-primary:hover { background: var(--navy-100); }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  background: var(--grey-100);
  color: var(--grey-700);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--grey-200);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--grey-200); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }
.table .col-actions { text-align: right; white-space: nowrap; }
.table .col-actions .btn + .btn { margin-left: 6px; }
.table .num { text-align: right; }
.code-cell { font-family: var(--mono); font-weight: 600; color: var(--navy-900); word-break: break-all; }
.shelf-pill {
  display: inline-block;
  font-family: var(--mono);
  font-weight: 700;
  background: var(--navy-100);
  color: var(--navy-800);
  padding: 2px 10px;
  border-radius: 999px;
  text-decoration: none;
  border: 1px solid #c9d6e7;
}
a.shelf-pill:hover { background: #d3deec; }
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--grey-200);
  color: var(--grey-700);
}

/* Phones: each row becomes a card */
@media (max-width: 680px) {
  .container { padding-top: 16px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--grey-200); padding: 10px 14px; }
  .table tr:last-child { border-bottom: none; }
  .table td { border: none; padding: 3px 0; display: flex; gap: 12px; justify-content: space-between; text-align: right; }
  .table td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--grey-500);
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
  }
  .table .col-actions { justify-content: flex-end; padding-top: 8px; }
  .table .col-actions::before { content: none; }
  .search-hero { padding: 20px 16px; }
  .search-form .select, .search-form .btn { flex: 1 1 100%; }
  .account-name { display: none; }
  .account { margin-left: 0; }
  .topbar-inner { justify-content: space-between; }
  .nav { order: 3; width: 100%; }
  .nav a { flex: 1; text-align: center; }
}

/* ---------- States ---------- */
.state {
  background: var(--white);
  border: 1px dashed var(--grey-300);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  color: var(--grey-700);
}
.state h2 { margin-bottom: 6px; }
.state p { margin: 4px 0; }
.state .toolbar { justify-content: center; margin-top: 14px; }
.state-error { border: 1px solid #f1b8b3; background: var(--red-50); color: var(--red-700); }
.state-error h2 { color: var(--red-700); }
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid var(--grey-300);
  border-top-color: var(--navy-700);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -4px;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } }

.alert {
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.92rem;
  border: 1px solid;
}
.alert-error { background: var(--red-50); color: var(--red-700); border-color: #f1b8b3; }
.alert-warn { background: var(--amber-50); color: var(--amber-700); border-color: #f5d48a; }
.alert-info { background: var(--navy-100); color: var(--navy-800); border-color: #c9d6e7; }
.alert p { margin: 4px 0; }
.alert .toolbar { margin-top: 8px; }

.summary { margin: 0 0 10px; color: var(--grey-700); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- Login ---------- */
.auth-wrap { max-width: 400px; margin: 48px auto 0; }
.auth-wrap .brand-big {
  display: flex; align-items: center; gap: 12px; justify-content: center;
  margin-bottom: 20px; color: var(--navy-900); font-weight: 700; font-size: 1.4rem;
}
.auth-wrap .brand-mark { width: 32px; height: 32px; border-radius: 7px; background-size: auto; }
.auth-wrap .btn { width: 100%; }
.auth-foot { text-align: center; margin-top: 14px; font-size: 0.85rem; }

/* ---------- Dialogs ---------- */
dialog.dialog {
  border: none;
  border-radius: 10px;
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  box-shadow: 0 20px 50px rgba(15, 36, 64, 0.35);
  color: var(--grey-900);
}
dialog.dialog::backdrop { background: rgba(15, 36, 64, 0.45); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dialog-head { padding: 16px 20px; border-bottom: 1px solid var(--grey-200); }
.dialog-body { padding: 18px 20px 6px; overflow-y: auto; }
.dialog-foot {
  padding: 12px 20px;
  border-top: 1px solid var(--grey-200);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--grey-100);
  border-radius: 0 0 10px 10px;
}
.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 8px 0; }
.detail-list dt { color: var(--grey-500); font-size: 0.85rem; }
.detail-list dd { margin: 0; font-weight: 600; word-break: break-all; }

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  background: var(--navy-900);
  color: var(--white);
  padding: 11px 16px;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 36, 64, 0.3);
  font-weight: 500;
}
.toast-error { background: var(--red-700); }
.toast-success { background: var(--green-700); }

.card-title { margin-bottom: 14px; }

/* ---------- Stock + import ---------- */
.stock { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--navy-900); }
.stock-zero { color: var(--grey-500); font-weight: 500; }
.strong { font-weight: 700; }
.section-title { margin: 28px 0 10px; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.file-input:focus-visible + * { outline: 3px solid #8fb3e0; }
label.btn[for="import-file"] { cursor: pointer; margin: 6px 0 14px; }
.rules { margin: 0; padding-left: 18px; }
.rules li { margin: 2px 0; }
.file-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.file-head h2 { margin-bottom: 2px; }
.file-head p { margin: 0; }
.panel { margin-bottom: 14px; }
.panel h2 { margin-bottom: 4px; }
.panel-warn { border-left: 4px solid #d99a00; }
.fix-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.fix-row { background: var(--grey-100); border-radius: 6px; padding: 10px 12px; }
.fix-row-head { margin-bottom: 6px; word-break: break-all; }
.fix-row .toolbar .input, .fix-row .toolbar .select { flex: 1 1 260px; width: auto; }
details.card summary, details.row-details summary { cursor: pointer; font-weight: 600; color: var(--navy-800); }
details.row-details { margin-top: 18px; }
details.row-details .table-wrap { margin-top: 10px; }
.scroll-y { max-height: 460px; overflow: auto; }
.table-compact th, .table-compact td { padding: 7px 10px; font-size: 0.9rem; }
.row-skipped td { color: var(--grey-500); text-decoration: line-through; }
.row-skipped td:last-child { text-decoration: none; }
.badge-ok { background: var(--green-50); color: var(--green-700); }
.badge-warn { background: var(--amber-50); color: var(--amber-700); }
.badge-bad { background: var(--red-50); color: var(--red-700); }
.badge.tight { margin-left: 8px; vertical-align: 2px; }
.confirm-bar { margin-top: 18px; position: sticky; bottom: 8px; box-shadow: 0 -2px 12px rgba(16, 24, 40, 0.12), var(--shadow); }
.confirm-summary { display: flex; gap: 8px 28px; flex-wrap: wrap; align-items: baseline; margin-bottom: 10px; }
.confirm-summary .big { font-size: 1.6rem; font-weight: 700; color: var(--navy-900); }
.alert-success { background: var(--green-50); color: var(--green-700); border-color: #abefc6; }
.toolbar.spaced { margin-top: 14px; }
dialog.dialog-wide { width: min(980px, calc(100vw - 32px)); }

@media (max-width: 680px) {
  .confirm-bar { position: static; }
  .scroll-y { max-height: 380px; }
  .table-compact td { padding: 3px 0; }
}

/* ---------- Materials ---------- */
.nav-badge { display: inline-block; margin-left: 6px; min-width: 18px; padding: 0 5px; border-radius: 999px; background: #d92d20; color: #fff; font-size: 0.72rem; font-weight: 700; line-height: 18px; text-align: center; vertical-align: 1px; }
.row-low td { background: #fff5f4; }
.row-low td:first-child { box-shadow: inset 4px 0 0 #d92d20; }
.row-inactive td { color: var(--grey-500); }
.stock-low { color: var(--red-700); }
.low-banner { font-size: 1rem; }
td.pos { color: var(--green-700); font-weight: 600; }
td.neg { color: var(--red-700); font-weight: 600; }
.material-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 14px; margin-top: 8px; }
.consumption { margin-top: 4px; }
.consumption-list { grid-template-columns: max-content 1fr; }
.consumption-area { font-size: 1.15rem; color: var(--navy-900); }
.material-result { margin-bottom: 18px; }
@media (max-width: 680px) { .material-grid { grid-template-columns: 1fr; } }
