:root {
  --bg: #e8ecf1;
  --sheet: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #cbd5e1;
  --line-strong: #94a3b8;
  --input: #ffffff;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --font: "Outfit", system-ui, sans-serif;
  --font-brand: "Montserrat", "Arial Black", Impact, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --gap: 1.5rem;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 18px;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
}

body {
  padding: 1.75rem clamp(1.1rem, 3vw, 2.25rem) 2.75rem;
}

.sheet {
  max-width: 1440px;
  margin: 0 auto;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
}

.top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: var(--gap);
  padding: 1.1rem 1.25rem;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand {
  margin: 0;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  background: transparent;
  border: 0;
  padding: 0.1rem 0;
  color: var(--accent);
  line-height: 0;
  user-select: none;
}

.brand-mark {
  display: block;
  height: clamp(2.85rem, 5.4vw, 3.6rem);
  width: auto;
  overflow: visible;
  transition: transform 0.15s ease;
}

.brand:hover {
  color: #1d4ed8;
}

.brand:hover .brand-mark {
  transform: scale(1.03);
  transform-origin: left center;
  transition: transform 0.15s ease;
}

.modal-kicker {
  margin: 0;
  color: #0a0a0a;
  line-height: 0;
}

.logo-wordmark {
  display: block;
  height: 1.15rem;
  width: auto;
}

.tagline {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  top: 0.75rem;
  z-index: 1000;
  transform: translateX(-50%);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  width: max-content;
  max-width: calc(100vw - 1.5rem);
  padding: 0.65rem 1.15rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #bbf7d0;
  border-left: 5px solid #059669;
  color: #047857;
  font-weight: 650;
  font-size: 1.02rem;
  letter-spacing: 0;
  text-align: center;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.1);
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.toast.error {
  border-color: #fecaca;
  border-left-color: #dc2626;
  color: #b91c1c;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.1);
}

.toast-icon {
  display: none;
  flex-shrink: 0;
  width: 1.65rem;
  height: 1.65rem;
}

.toast-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.toast-icon .toast-check-circle {
  fill: none;
  stroke: #059669;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 36;
  stroke-dashoffset: 36;
}

.toast-icon .toast-check-mark {
  fill: none;
  stroke: #059669;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 14;
  stroke-dashoffset: 14;
}

.toast.show-icon:not(.error) .toast-icon {
  display: block;
}

.toast.show-icon:not(.error) .toast-check-circle {
  animation: toast-circle 0.45s ease forwards;
}

.toast.show-icon:not(.error) .toast-check-mark {
  animation: toast-check 0.35s ease 0.28s forwards;
}

.toast.error .toast-icon {
  display: none;
}

@keyframes toast-circle {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes toast-check {
  to {
    stroke-dashoffset: 0;
  }
}

#boot-error.toast {
  pointer-events: auto;
  border-radius: 14px;
  width: min(32rem, calc(100vw - 1.5rem));
  top: 1rem;
}

@media (min-width: 721px) {
  .toast.show-icon:not(.error) .toast-icon {
    display: block;
  }
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.icon-btn {
  min-width: 3rem;
  font-size: 1.2rem;
  line-height: 1;
  padding-left: 0.7rem;
  padding-right: 0.7rem;
}

.context-bar {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
}

.context-title {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.context-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.entry-grid-simple {
  grid-template-columns: 1.5fr 0.8fr 0.8fr 1.1fr auto;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: end;
}

.grow {
  min-width: 0;
}

.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  overflow-y: auto;
  align-content: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(4px);
}

.modal-card,
.settings-card {
  position: relative;
  z-index: 1;
  width: min(860px, 100%);
  max-height: none;
  overflow: visible;
  background: var(--sheet);
  border: 1px solid rgba(148, 163, 184, 0.55);
  border-radius: 22px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 28px 70px rgba(15, 23, 42, 0.28);
  padding: 0;
  display: block;
  margin: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.4rem 1.05rem;
  position: relative;
  top: auto;
  z-index: 2;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.modal-title-block {
  display: grid;
  gap: 0.35rem;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.modal-head-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn.icon-close {
  width: 2.4rem;
  min-height: 2.4rem;
  padding: 0;
  border-radius: 999px;
  font-size: 1.45rem;
  line-height: 1;
  color: var(--muted);
  background: #f1f5f9;
  border-color: transparent;
}

.btn.icon-close:hover {
  color: var(--ink);
  background: #e2e8f0;
}

.settings-nav {
  padding: 0.85rem 1.25rem 0;
}

.settings-dept-tabs.seg,
.settings-dept-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: 100%;
  border-radius: 14px;
  padding: 0.28rem;
  background: #eef2f7;
  border: 1px solid #e2e8f0;
  gap: 0.15rem;
}

.settings-dept-tabs .seg-btn {
  width: 100%;
  text-align: center;
  padding: 0.55rem 0.4rem;
  border-radius: 10px;
  font-size: 0.92rem;
}

.settings-dept-tabs .seg-btn.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08), 0 4px 12px rgba(37, 99, 235, 0.08);
}

.settings-body {
  display: grid;
  gap: 0.9rem;
  padding: 0.9rem 1.4rem 1.45rem;
  grid-template-columns: 1fr;
}

.settings-section {
  margin: 0;
  padding: 1rem 1.05rem 1.1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: grid;
  gap: 0.85rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.settings-section-muted {
  background: #f8fafc;
}

.section-head {
  display: grid;
  gap: 0.25rem;
}

.settings-section h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #475569;
}

.gate {
  margin: 0.9rem 1.25rem 1.35rem;
  max-width: none;
  display: grid;
  gap: 0.85rem;
  padding: 1.15rem 1.2rem;
  background: linear-gradient(180deg, #f8fafc, #f1f5f9);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.gate-lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

.field {
  display: grid;
  gap: 0.35rem;
}

.field > span {
  font-size: 0.82rem;
  font-weight: 650;
  color: #475569;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.item-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
}

.item-list .name {
  font-weight: 650;
  font-size: 0.98rem;
  min-width: 0;
  word-break: break-word;
}

.item-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.field-error {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger);
  font-weight: 650;
  font-size: 0.92rem;
}

.section-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.toggle-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.toggle-row.is-on {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.toggle-row .switch-name {
  font-weight: 700;
  font-size: 0.98rem;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  width: 2.7rem;
  height: 1.55rem;
  border-radius: 999px;
  background: #cbd5e1;
  border: 1px solid #94a3b8;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-track {
  background: var(--accent);
  border-color: #1d4ed8;
}

.switch input:checked + .switch-track::after {
  transform: translateX(1.1rem);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}

.btn-sm {
  min-height: 2.2rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.84rem;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  margin: 0;
}

.password-form {
  display: grid;
  gap: 0.75rem;
}

body.modal-open {
  overflow: hidden;
}

.dept-toolbar,
.dept-badge {
  display: none !important;
}

.dept-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: var(--gap);
}

.dept-btn {
  flex: 1 1 9.5rem;
  min-height: 3.45rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--sheet);
  color: var(--muted);
  font: inherit;
  font-weight: 650;
  font-size: 1.12rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.dept-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.dept-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.dept-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.85rem;
  align-items: center;
  margin-bottom: var(--gap);
  padding: 0.75rem 1rem;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.dept-badge {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
}

.seg {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem;
  gap: 0.2rem;
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

.panel {
  display: grid;
  gap: var(--gap);
}

.panel[hidden],
[hidden] {
  display: none !important;
}

.entry,
.global-search,
.block,
.filters,
.table-wrap {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.entry,
.global-search,
.block {
  padding: 1.25rem;
  margin-bottom: 0;
}

.entry-title,
.search-title,
.block h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
}

.search-hint {
  margin: -0.5rem 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.entry-grid {
  display: grid;
  grid-template-columns: 1.5fr 0.8fr 0.8fr 1.1fr 1.1fr auto;
  gap: 1rem;
  align-items: end;
}

.filters {
  display: grid;
  grid-template-columns: 1.6fr 0.9fr 0.9fr auto;
  gap: 1rem;
  align-items: end;
  padding: 1.15rem 1.25rem;
  margin-bottom: 0;
}

.filter-actions {
  display: flex;
  gap: 0.5rem;
}

label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

label.req > span:first-child::after {
  content: " *";
  color: var(--danger);
  font-weight: 700;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  min-height: 3rem;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid var(--line-strong);
  background: var(--input);
  color: var(--ink);
  border-radius: 10px;
}

input.big {
  min-height: 3.25rem;
  font-size: 1.1rem;
  font-weight: 600;
}

.mono {
  font-family: var(--mono);
  font-feature-settings: "zero" 0;
}

.when {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: 0.01em;
  color: var(--muted);
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.35);
  outline-offset: 1px;
  border-color: var(--accent);
}

.nice-select {
  position: relative;
  width: 100%;
}

.nice-select-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  border: 0 !important;
  min-height: 0 !important;
  clip: rect(0, 0, 0, 0);
}

.nice-select-trigger {
  width: 100%;
  min-height: 3rem;
  padding: 0.6rem 2.6rem 0.6rem 0.85rem;
  border: 1.5px solid var(--line-strong);
  background: var(--input);
  color: var(--ink);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  cursor: pointer;
  box-shadow: none;
  position: relative;
  font: inherit;
  font-weight: 550;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.nice-select.is-placeholder .nice-select-label {
  color: var(--muted);
  font-weight: 500;
}

.nice-select-trigger:hover {
  border-color: #64748b;
}

.nice-select.open .nice-select-trigger,
.nice-select-trigger:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.35);
  outline-offset: 1px;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.nice-select-chevron {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid #64748b;
  border-bottom: 2px solid #64748b;
  transform: translateY(-65%) rotate(45deg);
  transition: transform 0.18s ease, border-color 0.15s ease;
  pointer-events: none;
}

.nice-select.open .nice-select-chevron {
  transform: translateY(-20%) rotate(225deg);
  border-color: var(--accent);
}

.nice-select-menu {
  z-index: 80;
  margin: 0;
  padding: 0.35rem;
  background: #fff;
  border: 1px solid rgba(148, 163, 184, 0.65);
  border-radius: 12px;
  box-shadow:
    0 4px 6px rgba(15, 23, 42, 0.04),
    0 18px 40px rgba(15, 23, 42, 0.16);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.nice-select-menu[hidden] {
  display: none !important;
}

.nice-select-option {
  width: 100%;
  min-height: 2.55rem;
  margin: 0;
  padding: 0.55rem 0.7rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 550;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  box-shadow: none;
}

.nice-select-option + .nice-select-option {
  margin-top: 0.1rem;
}

.nice-select-option:hover,
.nice-select-option:focus-visible {
  background: var(--accent-soft);
  color: #1e3a8a;
  outline: none;
}

.nice-select-option.is-selected {
  background: linear-gradient(180deg, #eff6ff 0%, #dbeafe 100%);
  color: #1e40af;
  font-weight: 650;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.nice-select-option.is-placeholder-option {
  color: var(--muted);
  font-weight: 500;
}

.nice-select-option.is-placeholder-option.is-selected {
  background: #f8fafc;
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--line);
}

.nice-select-check {
  width: 0.85rem;
  height: 0.45rem;
  border-left: 2px solid transparent;
  border-bottom: 2px solid transparent;
  transform: rotate(-45deg) translateY(-1px);
  flex: 0 0 auto;
  opacity: 0;
}

.nice-select-option.is-selected .nice-select-check {
  border-left-color: var(--accent);
  border-bottom-color: var(--accent);
  opacity: 1;
}

.btn {
  min-height: 3.15rem;
  padding: 0.55rem 1.05rem;
  border: 1.5px solid var(--line-strong);
  background: #f8fafc;
  color: var(--ink);
  font-weight: 650;
  border-radius: 10px;
  cursor: pointer;
}

.btn:hover {
  background: #f1f5f9;
}

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

.btn.primary:hover {
  background: #1d4ed8;
}

.btn.ghost {
  background: transparent;
}

.entry-submit {
  min-width: 8rem;
}

.table-wrap {
  overflow: auto;
  margin-bottom: 0;
  padding: 0.15rem 0;
}

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

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

th:first-child,
td:first-child {
  padding-left: 1.25rem;
}

th:last-child,
td:last-child {
  padding-right: 1.1rem;
  width: 11.5rem;
  text-align: right;
  white-space: nowrap;
  vertical-align: middle;
}

.row-actions,
.work-card-actions {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0.45rem;
  justify-content: flex-end;
  align-items: center;
}

.row-actions .btn,
.work-card-actions .btn {
  margin: 0;
  flex: 0 0 auto;
  white-space: nowrap;
  min-height: 2.4rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.88rem;
}

.work-card-actions {
  width: 100%;
  margin-top: 0.35rem;
}

.work-card-actions .btn {
  flex: 1 1 0;
}

.edit-card {
  width: min(420px, 100%);
  border-radius: 16px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 18px 48px rgba(15, 23, 42, 0.22);
  padding: 0;
  overflow: visible;
}

.edit-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
}

.edit-form {
  padding: 1.25rem 1.25rem 1.2rem;
}

.edit-form .entry-title {
  margin: 0 2.4rem 1rem 0;
  font-size: 1.15rem;
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem 0.75rem;
  align-items: end;
}

.edit-field-number,
.edit-field-operator,
.edit-actions {
  grid-column: 1 / -1;
}

.edit-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.15rem;
}

.edit-actions .btn {
  width: 100%;
  min-width: 0;
}

.confirm-card {
  width: min(380px, 100%);
  border-radius: 16px;
  padding: 1.35rem 1.3rem 1.25rem;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 18px 48px rgba(15, 23, 42, 0.22);
}

#confirm-modal {
  z-index: 60;
}

.confirm-title {
  margin: 0 0 0.55rem;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.confirm-message {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.45;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.confirm-actions .btn {
  width: 100%;
  min-width: 0;
}

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

.btn.danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* Номер | Размер | Оператор | Дата | кнопка */
th:nth-child(1),
td:nth-child(1) {
  width: 18%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 16%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 20%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 28%;
}

/* Поиск: Отдел | Номер | Размер | Оператор | Дата | кнопка */
table.search-mode th:nth-child(1),
table.search-mode td:nth-child(1) {
  width: 12%;
}

table.search-mode th:nth-child(2),
table.search-mode td:nth-child(2) {
  width: 14%;
}

table.search-mode th:nth-child(3),
table.search-mode td:nth-child(3) {
  width: 14%;
}

table.search-mode th:nth-child(4),
table.search-mode td:nth-child(4) {
  width: 16%;
}

table.search-mode th:nth-child(5),
table.search-mode td:nth-child(5) {
  width: 24%;
}

th {
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--muted);
  background: #f8fafc;
  position: sticky;
  top: 0;
}

tbody tr:hover {
  background: #f8fafc;
}

.empty {
  margin: 0;
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 1rem;
}

.settings-bar {
  margin-bottom: 0;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.settings-grid-single {
  grid-template-columns: 1fr;
  max-width: 480px;
}

.badge {
  margin-left: 0.35rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--muted);
}

.pill {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #1d4ed8;
  font-weight: 650;
  font-size: 0.8rem;
}

#panel-settings {
  display: grid;
  gap: var(--gap);
}

@media (max-width: 900px) {
  .dept-btn {
    flex-basis: calc(50% - 0.25rem);
  }

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

  .toggle-list {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 1100px) {
  .entry-grid,
  .entry-grid-simple,
  .filters,
  .search-row,
  .context-grid {
    grid-template-columns: 1fr 1fr;
  }
  .entry-submit,
  .filter-actions {
    grid-column: 1 / -1;
  }
}

.works-cards {
  display: none;
}

.works-list {
  display: grid;
  gap: 0;
}

/* —— Phone / shop-floor touch UI —— */
@media (max-width: 720px) {
  html {
    font-size: 19px;
  }

  body {
    padding: 0.75rem 0.7rem 2rem;
    overflow-x: hidden;
  }

  .sheet {
    max-width: none;
  }

  .top {
    padding: 1rem 1rem;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
  }

  .brand-mark {
    height: 3.1rem;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .icon-btn {
    min-width: 3rem;
    min-height: 3rem;
    font-size: 1.35rem;
  }

  .dept-nav {
    gap: 0.45rem;
    margin-bottom: 0.85rem;
  }

  .dept-btn {
    flex: 1 1 calc(50% - 0.25rem);
    min-height: 3.4rem;
    font-size: 1.05rem;
    border-radius: 14px;
  }

  .entry,
  .global-search {
    padding: 1.1rem 1rem 1.2rem;
    border-radius: 18px;
  }

  .entry-title,
  .search-title {
    font-size: 1.15rem;
    margin-bottom: 0.9rem;
  }

  .entry-grid,
  .filters,
  .search-row,
  .settings-grid,
  .inline-form,
  .context-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .entry-grid-simple {
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
  }

  .entry-grid-simple label:first-child,
  .entry-grid-simple label:nth-child(4),
  .entry-grid-simple .entry-submit {
    grid-column: 1 / -1;
  }

  label {
    font-size: 0.95rem;
    gap: 0.45rem;
  }

  input,
  select,
  .nice-select-trigger {
    min-height: 3.4rem;
    font-size: 1.08rem;
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
  }

  .nice-select-trigger {
    padding-right: 2.7rem;
  }

  .nice-select-option {
    min-height: 3rem;
    font-size: 1.05rem;
    border-radius: 10px;
  }

  input.big {
    min-height: 3.55rem;
    font-size: 1.2rem;
  }

  .btn {
    min-height: 3.4rem;
    font-size: 1.05rem;
    border-radius: 12px;
  }

  .entry-submit {
    width: 100%;
    margin-top: 0.25rem;
  }

  .works-desktop {
    display: none !important;
  }

  .works-cards {
    display: grid;
    gap: 0.7rem;
  }

  .work-card {
    display: grid;
    gap: 0.55rem;
    padding: 1rem 1.05rem;
    background: var(--sheet);
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    border-radius: 16px;
    box-shadow: var(--shadow);
  }

  .work-card-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem;
  }

  .work-card-number {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    word-break: break-all;
  }

  .work-card-size {
    font-size: 1.15rem;
    font-weight: 650;
    color: #1e3a8a;
  }

  .work-card-meta {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    color: var(--muted);
    font-size: 0.95rem;
  }

  .work-card-del {
    width: auto;
    margin-top: 0;
  }

  .work-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .empty {
    padding: 1.5rem 1rem;
    font-size: 1.05rem;
  }

  .toast {
    top: 0.55rem;
    font-size: 1.08rem;
    padding: 0.75rem 1.2rem;
  }

  .toast-icon {
    display: none !important;
  }

  .modal {
    padding: 0;
    align-items: stretch;
    align-content: stretch;
    justify-items: stretch;
  }

  .modal-card,
  .settings-card,
  .edit-card,
  .confirm-card {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.2);
  }

  .confirm-card {
    padding: 1.4rem 1.2rem calc(1.3rem + env(safe-area-inset-bottom, 0px));
  }

  .edit-card {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .edit-form {
    padding: 1.35rem 1.15rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  }

  .edit-close {
    top: 0.85rem;
    right: 0.85rem;
  }

  .settings-dept-tabs {
    grid-template-columns: 1fr;
  }

  .settings-dept-tabs .seg-btn {
    padding: 0.75rem 0.5rem;
    font-size: 1rem;
  }

  .toggle-list {
    grid-template-columns: 1fr;
  }

  .toggle-row {
    min-height: 3.2rem;
  }

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

  .item-actions {
    width: 100%;
  }

  .item-actions .btn {
    flex: 1;
  }
}
