*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #0f1419;
  color: #e6edf3;
  min-height: 100vh;
}

a { color: #58a6ff; text-decoration: none; }
a:hover { text-decoration: underline; }

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: linear-gradient(180deg, #161b22 0%, #0d1117 100%);
  border-right: 1px solid #30363d;
  padding: 1rem 0;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 0.75rem 1rem 1rem;
  border-bottom: 1px solid #30363d;
  margin-bottom: 0.75rem;
}

.site-logo {
  display: block;
  max-width: 100%;
  height: auto;
}

.site-logo--sidebar {
  width: 100%;
}

.site-logo--login {
  width: min(100%, 320px);
  margin: 0 auto;
}

.sidebar nav a {
  display: block;
  padding: 0.6rem 1.25rem;
  color: #8b949e;
  border-left: 3px solid transparent;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  background: rgba(56, 139, 253, 0.1);
  color: #58a6ff;
  border-left-color: #388bfd;
  text-decoration: none;
}

.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: #161b22;
  border-bottom: 1px solid #30363d;
}

.topbar-search {
  flex: 1;
  max-width: 420px;
}

.topbar-search input[type="search"],
.topbar-search input[type="text"] {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #e6edf3;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.bell {
  position: relative;
  padding: 0.35rem 0.5rem;
  color: #8b949e;
}

.profile {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #e6edf3;
  font-size: 0.9rem;
}

.content {
  padding: 1.25rem;
  flex: 1;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 1rem;
}

.kpi-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b949e;
  font-weight: 600;
}

.kpi-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  color: #58a6ff;
}

.kpi-card .value.kpi-muted {
  color: #8b949e;
}

.kpi-card .kpi-hint {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: #6e7681;
  line-height: 1.3;
}

/* Dashboard KPI cards: 3–4 columns so 7 tiles don’t leave a lone cell in a 2-col grid */
.card-grid.dashboard-kpis {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (min-width: 1100px) {
  .card-grid.dashboard-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 639px) {
  .card-grid.dashboard-kpis {
    grid-template-columns: 1fr;
  }
}

/* Create order — materials editor: keep table in viewport; action column always visible */
.table-wrap.table-wrap--mat-editor {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data.mat-editor-table {
  table-layout: auto;
  width: 100%;
  min-width: 0;
}

table.data.mat-editor-table.mat-editor-table--deduct {
  table-layout: fixed;
  width: 100%;
}

table.data.mat-editor-table.mat-editor-table--remnant {
  min-width: 32rem;
}

table.data.mat-editor-table--deduct col.col-remove {
  width: 4.75rem;
}

table.data.mat-editor-table--deduct col.col-mat {
  width: 17%;
}

table.data.mat-editor-table--deduct col.col-thick {
  width: 10%;
}

table.data.mat-editor-table--deduct col.col-width {
  width: 9%;
}

table.data.mat-editor-table--deduct col.col-length {
  width: 9%;
}

table.data.mat-editor-table--deduct col.col-qty {
  width: 7%;
}

table.data.mat-editor-table--deduct col.col-source {
  width: 11%;
}

table.data.mat-editor-table--deduct col.col-stock {
  width: auto;
}

table.data.mat-editor-table th,
table.data.mat-editor-table td {
  vertical-align: middle;
}

table.data.mat-editor-table th.row-actions,
table.data.mat-editor-table td.row-actions {
  width: 4.75rem;
  min-width: 4.75rem;
  max-width: 4.75rem;
  padding: 0.35rem 0.25rem;
  text-align: center;
  white-space: nowrap;
}

table.data.mat-editor-table .btn-del-row {
  display: inline-block;
  padding: 0.28rem 0.5rem;
  font-size: 0.75rem;
  line-height: 1.2;
  white-space: nowrap;
  color: #f85149;
  border-color: rgba(248, 81, 73, 0.45);
}

table.data.mat-editor-table .btn-del-row:hover {
  color: #fff;
  background: rgba(248, 81, 73, 0.15);
  border-color: #f85149;
}

/* Remnant rows — column min widths */
table.data.mat-editor-table--remnant th:nth-child(1),
table.data.mat-editor-table--remnant td:nth-child(1) {
  min-width: 9rem;
}

table.data.mat-editor-table select,
table.data.mat-editor-table input[type="text"],
table.data.mat-editor-table input[type="number"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

table.data.mat-editor-table .stock-hint {
  display: block;
  font-size: 0.78rem;
  line-height: 1.35;
  color: #8b949e;
  white-space: normal;
  word-break: normal;
  overflow-wrap: anywhere;
}

.prod-select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.prod-att-preview {
  margin-top: 0.35rem;
  font-size: 0.85rem;
}

.prod-att-link {
  color: #58a6ff;
  text-decoration: none;
}

.prod-att-link:hover {
  text-decoration: underline;
}

.prod-att-empty {
  font-size: 0.78rem;
  color: #8b949e;
}

table.data.mat-editor-table th.row-actions {
  font-size: 0.75rem;
  font-weight: 600;
  color: #8b949e;
}

.mat-ownership-row .mat-ownership-options {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: center;
  margin-top: 0.35rem;
  position: relative;
  z-index: 2;
}

.mat-ownership-row .field-label {
  display: block;
  font-size: 0.85rem;
  color: #8b949e;
  margin-bottom: 0.25rem;
}

.mat-ownership-hint {
  margin: 0.45rem 0 0;
  font-size: 0.82rem;
  color: #8b949e;
}

.mat-ownership-row .mat-ownership-option {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  font-weight: normal;
  cursor: pointer;
  color: #e6edf3;
  user-select: none;
  position: relative;
  z-index: 2;
}

.mat-ownership-row .mat-ownership-option input[type="checkbox"],
.mat-ownership-options--remnant .mat-ownership-option input[type="radio"] {
  width: 1.05rem;
  height: 1.05rem;
  min-width: 1.05rem;
  min-height: 1.05rem;
  margin: 0;
  cursor: pointer;
  accent-color: #388bfd;
  flex-shrink: 0;
  position: relative;
  z-index: 3;
}

.mat-ownership-options--remnant {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 9.5rem;
}

.mat-ownership-options--remnant .mat-ownership-option {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  font-weight: normal;
  cursor: pointer;
  color: #e6edf3;
  user-select: none;
  font-size: 0.85rem;
}

.mat-ownership-options--remnant .rem-party-name {
  color: #8b949e;
  font-size: 0.78rem;
}

.rem-owner-cell {
  vertical-align: top;
}
.mat-ownership-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.5rem 0 0.75rem;
  font-size: 0.82rem;
}

.mat-ownership-legend--board {
  margin: 0 0 1rem;
}

.mat-ownership-legend--mobile {
  margin-top: 0.65rem;
}

.mat-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: #8b949e;
}

.mat-legend-item::before {
  content: "";
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  border: 1px solid transparent;
}

.mat-legend-party::before,
.mat-owner-party,
.order-mat-party {
  border-left: 4px solid #388bfd;
}

.mat-legend-party::before {
  background: rgba(56, 139, 253, 0.22);
  border-color: #388bfd;
}

.mat-legend-inhouse::before,
.mat-owner-inhouse,
.order-mat-inhouse {
  border-left: 4px solid #3fb950;
}

.mat-legend-inhouse::before {
  background: rgba(63, 185, 80, 0.2);
  border-color: #3fb950;
}

.mat-legend-mixed::before,
.order-mat-mixed {
  border-left: 4px solid #d29922;
}

.mat-legend-mixed::before {
  background: rgba(210, 153, 34, 0.2);
  border-color: #d29922;
}

table.data.mat-editor-table tr.mat-owner-party > td:first-child,
table.data tr.mat-owner-party > td:first-child {
  box-shadow: inset 4px 0 0 #388bfd;
}

table.data.mat-editor-table tr.mat-owner-inhouse > td:first-child,
table.data tr.mat-owner-inhouse > td:first-child {
  box-shadow: inset 4px 0 0 #3fb950;
}

table.data tr.mat-owner-party {
  background: rgba(56, 139, 253, 0.06);
}

table.data tr.mat-owner-inhouse {
  background: rgba(63, 185, 80, 0.06);
}

.kanban-card.order-mat-party {
  background: rgba(56, 139, 253, 0.1);
  border-left: 4px solid #388bfd;
}

.kanban-card.order-mat-inhouse {
  background: rgba(63, 185, 80, 0.1);
  border-left: 4px solid #3fb950;
}

.kanban-card.order-mat-mixed {
  background: rgba(210, 153, 34, 0.1);
  border-left: 4px solid #d29922;
}

.mat-type-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.mat-type-badge.order-mat-party {
  background: rgba(56, 139, 253, 0.15);
  color: #79c0ff;
  border: 1px solid rgba(56, 139, 253, 0.35);
}

.mat-type-badge.order-mat-inhouse {
  background: rgba(63, 185, 80, 0.15);
  color: #7ee787;
  border: 1px solid rgba(63, 185, 80, 0.35);
}

.mat-type-badge.order-mat-mixed {
  background: rgba(210, 153, 34, 0.15);
  color: #e3b341;
  border: 1px solid rgba(210, 153, 34, 0.35);
}

.mat-type-badge.mat-type-none {
  background: transparent;
  color: #8b949e;
  border: 1px solid transparent;
  font-weight: normal;
}

.mobile-work-order.order-mat-party {
  border-color: #388bfd;
  box-shadow: inset 4px 0 0 #388bfd;
}

.mobile-work-order.order-mat-inhouse {
  border-color: #3fb950;
  box-shadow: inset 4px 0 0 #3fb950;
}

.mobile-work-order.order-mat-mixed {
  border-color: #d29922;
  box-shadow: inset 4px 0 0 #d29922;
}

.mobile-wo-mat-line.mat-owner-party {
  border-left: 3px solid #388bfd;
  padding-left: 0.5rem;
  background: rgba(56, 139, 253, 0.08);
  border-radius: 4px;
}

.mobile-wo-mat-line.mat-owner-inhouse {
  border-left: 3px solid #3fb950;
  padding-left: 0.5rem;
  background: rgba(63, 185, 80, 0.08);
  border-radius: 4px;
}

@media (max-width: 720px) {
  .table-wrap.table-wrap--mat-editor {
    overflow-x: auto;
  }

  table.data.mat-editor-table--deduct {
    min-width: 48rem;
  }

  table.data.mat-editor-table--remnant {
    min-width: 36rem;
  }
}

.mobile-production .order-overview-card {
  margin-bottom: 0.35rem;
}

.order-overview-card {
  line-height: 1.45;
}

.order-overview-id {
  font-size: 1.35rem;
  font-weight: 700;
  color: #f0f6fc;
  margin-bottom: 0.15rem;
}

.order-overview-created {
  font-size: 0.88rem;
  font-weight: 400;
  color: #8b949e;
}

.kanban-created {
  display: block;
  font-size: 0.82rem;
  font-weight: 400;
  color: #8b949e;
  margin-top: 0.1rem;
}

.order-overview-party {
  font-size: 1rem;
  font-weight: 600;
  color: #e6edf3;
  margin-bottom: 0.5rem;
}

.order-overview-line {
  font-size: 0.92rem;
  color: #c9d1d9;
  margin-bottom: 0.2rem;
}

.order-overview-step {
  margin-top: 0.45rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #58a6ff;
}

.order-overview-product-desc,
.order-product-desc,
.prod-desc-text {
  color: #8b949e;
  font-size: 0.88rem;
  font-weight: 400;
  white-space: pre-wrap;
}

.prod-desc-preview {
  margin-top: 0.35rem;
}

.prod-desc-readonly {
  color: #8b949e;
  font-size: 0.9rem;
  max-width: 280px;
  white-space: pre-wrap;
}

.order-products-list .order-product-desc {
  margin-top: 0.2rem;
  margin-left: 0;
  padding-left: 0;
  list-style: none;
}

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

.panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  overflow: hidden;
}

.panel-heading {
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #30363d;
  background: #161b22;
}

.panel-heading-note {
  font-size: 0.78rem;
  font-weight: normal;
  color: #8b949e;
  margin-left: 0.5rem;
}

tr.dashboard-order-pending {
  background: rgba(210, 153, 34, 0.08);
}

tr.dashboard-order-pending td:first-child {
  box-shadow: inset 4px 0 0 #d29922;
}

.panel-body { padding: 0.75rem 1rem; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.data th,
table.data td {
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid #30363d;
}

table.data th {
  background: #0d1117;
  color: #8b949e;
  font-weight: 600;
}

table.data tr:hover td {
  background: rgba(56, 139, 253, 0.05);
}

table.data tr.low-stock td {
  background: rgba(248, 81, 73, 0.12);
}

table.data tr.audit-pager td {
  background: transparent;
  border-bottom: none;
  padding: 0.85rem 0.65rem;
}

table.data tr.audit-pager a,
table.data tr.audit-pager span {
  display: inline-block;
  margin: 0 0.15rem;
  padding: 0.2rem 0.45rem;
}

table.data tr.audit-pager a {
  color: #58a6ff;
  text-decoration: none;
}

table.data tr.audit-pager a:hover {
  text-decoration: underline;
}

table.data tr.audit-pager span {
  color: #e6edf3;
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-pending { background: #3d3d00; color: #d4d4a0; }
.badge-progress { background: #1a3d2e; color: #56d364; }
.badge-hold { background: #3d2a1a; color: #ff9f40; }
.badge-done { background: #1f2d3d; color: #79c0ff; }

.badge-cancelled {
  background: #3d1a1f;
  color: #ff7b72;
}

.btn {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #21262d;
  color: #e6edf3;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-primary {
  background: #238636;
  border-color: #2ea043;
}

.btn-primary:hover { background: #2ea043; }

.btn-ghost {
  background: transparent;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar h1 {
  margin: 0;
  font-size: 1.35rem;
  flex: 1;
  min-width: 140px;
}

.form-section {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.form-section h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: #8b949e;
}

.form-row {
  margin-bottom: 0.75rem;
}

.form-row label {
  display: block;
  font-size: 0.85rem;
  color: #8b949e;
  margin-bottom: 0.25rem;
}

input[type="text"],
input[type="date"],
input[type="number"],
input[type="search"],
select,
textarea {
  max-width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #e6edf3;
}

textarea { min-height: 80px; width: 100%; }

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid #30363d;
  margin-bottom: 1rem;
}

.tabs a, .tabs span.tab {
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  color: #8b949e;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tabs a.active, .tabs span.tab.active {
  color: #58a6ff;
  border-bottom-color: #388bfd;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.kanban {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 0.75rem;
}

.kanban-col {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  min-height: 200px;
}

.kanban-col h4 {
  margin: 0;
  padding: 0.5rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  border-bottom: 1px solid #30363d;
}

.kanban-card {
  padding: 0.5rem;
  border-bottom: 1px solid #21262d;
  font-size: 0.85rem;
}

.upload-zone {
  border: 2px dashed #30363d;
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  color: #8b949e;
}

.stock-ok { color: #56d364; }
.stock-warn { color: #ff9f40; }
.stock-bad { color: #f85149; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1f2d3d, #0d1117);
}

.login-box {
  width: 100%;
  max-width: 420px;
  padding: 2rem;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 12px;
}

.login-brand {
  text-align: center;
  margin-bottom: 1.25rem;
}

.login-intro {
  color: #8b949e;
  margin: 0 0 1rem;
  font-size: 0.92rem;
}

.alert {
  padding: 0.65rem 0.85rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

.alert-error {
  background: rgba(248, 81, 73, 0.2);
  border: 1px solid #f85149;
  color: #ffa198;
}

.alert-success {
  background: rgba(46, 160, 67, 0.2);
  border: 1px solid #3fb950;
  color: #7ee787;
}

.chk-menu-list label {
  display: inline-block;
  margin: 0.35rem 1.25rem 0.35rem 0;
}

tr.step-current td {
  background: rgba(56, 139, 253, 0.08);
}

tr.step-cancelled td {
  background: rgba(248, 81, 73, 0.06);
}

.mobile-shell {
  max-width: 480px;
  margin: 0 auto;
  background: #0d1117;
  min-height: 100vh;
  padding: 1rem;
  box-sizing: border-box;
}

/* Production: full-width shell, two cards side by side (no outer frame box) */
.mobile-shell.mobile-production {
  max-width: 960px;
  width: 100%;
  padding: 0.65rem;
}

.mobile-production-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: stretch;
  box-sizing: border-box;
}

.mobile-production-grid .mobile-card {
  margin-bottom: 0;
  min-width: 0;
}

.mobile-production .mobile-page-head {
  margin-bottom: 0.75rem;
}

.mobile-production .mobile-page-head h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.mobile-production .mobile-page-sub {
  font-size: 0.78rem;
  line-height: 1.4;
}

/* Smaller type + tighter spacing inside production cards (fits 2 columns on phone) */
.mobile-production .mobile-work-order .mobile-wo-head {
  padding: 0.55rem 0.55rem 0.5rem;
  gap: 0.35rem;
}

.mobile-production .mobile-wo-title {
  font-size: 0.8rem;
  letter-spacing: 0.01em;
}

.mobile-production .mobile-wo-client {
  font-size: 0.72rem;
  margin-top: 0.2rem;
  line-height: 1.3;
}

.mobile-production .mobile-wo-dl {
  margin-top: 0.45rem;
}

.mobile-production .mobile-wo-dl-row {
  font-size: 0.72rem;
  grid-template-columns: 2.25rem 1fr;
  gap: 0.25rem 0.35rem;
}

.mobile-production .mobile-wo-dl dt {
  font-size: 0.65rem;
}

.mobile-production .mobile-wo-badge {
  font-size: 0.62rem;
  padding: 0.12rem 0.35rem;
  line-height: 1.2;
}

.mobile-production .mobile-wo-body {
  padding: 0.55rem 0.55rem 0;
}

.mobile-production .mobile-wo-block {
  margin-top: 0.5rem;
}

.mobile-production .mobile-wo-section-title {
  font-size: 0.62rem;
  margin-bottom: 0.3rem;
}

.mobile-production .mobile-wo-desc {
  font-size: 0.72rem;
  line-height: 1.35;
  margin-top: 0.15rem;
}

.mobile-production .mobile-wo-mat-line {
  font-size: 0.72rem;
  margin-top: 0.3rem;
  padding: 0.35rem 0.45rem;
}

.mobile-production .mobile-wo-mat-qty {
  font-size: 0.68rem;
}

.mobile-production .mobile-wo-files li {
  padding: 0.35rem 0;
  font-size: 0.72rem;
}

.mobile-production .mobile-wo-file-meta {
  font-size: 0.65rem;
}

.mobile-production .mobile-muted {
  font-size: 0.72rem;
}

.mobile-production .mobile-wo-actions {
  margin-top: 0.5rem;
  padding: 0.55rem;
  gap: 0.35rem;
}

.mobile-production .mobile-wo-label {
  font-size: 0.62rem;
}

.mobile-production .mobile-select,
.mobile-production .mobile-textarea {
  font-size: 0.72rem;
  padding: 0.35rem 0.45rem;
}

.mobile-production .mobile-file {
  font-size: 0.68rem;
}

.mobile-production .mobile-btn-block {
  font-size: 0.72rem;
  padding: 0.4rem 0.55rem;
}

.mobile-production .mobile-empty-state {
  padding: 1.25rem 0.75rem;
}

.mobile-production .mobile-empty-title {
  font-size: 0.95rem;
}

.mobile-page-sub {
  margin: 0.4rem 0 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: #8b949e;
}

.mobile-empty-state {
  text-align: center;
  padding: 2rem 1rem;
  background: #161b22;
  border: 1px dashed #30363d;
  border-radius: 10px;
  margin-bottom: 0.75rem;
}

.mobile-empty-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #e6edf3;
}

.mobile-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 0;
  margin-bottom: 1rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mobile-work-order .mobile-wo-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.875rem;
  border-bottom: 1px solid #30363d;
  box-sizing: border-box;
}

.mobile-wo-head-main {
  flex: 1;
  min-width: 0;
}

.mobile-wo-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
  line-height: 1.3;
  color: #e6edf3;
}

.mobile-wo-client {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
  line-height: 1.35;
  color: #8b949e;
}

.mobile-wo-dl {
  margin: 0.65rem 0 0;
  padding: 0;
}

.mobile-wo-dl-row {
  display: grid;
  grid-template-columns: 2.75rem 1fr;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
  font-size: 0.88rem;
}

.mobile-wo-dl dt {
  margin: 0;
  padding: 0;
  color: #8b949e;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mobile-wo-dl dd {
  margin: 0;
  padding: 0;
  color: #e6edf3;
  font-weight: 600;
}

.mobile-due-overdue {
  color: #f85149;
  font-weight: 600;
}

.mobile-wo-badge {
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 0.1rem;
}

.mobile-wo-body {
  padding: 0.875rem 1rem 0;
  flex: 1;
}

.mobile-wo-block {
  margin-top: 0.75rem;
}

.mobile-wo-block:first-child {
  margin-top: 0;
}

.mobile-wo-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8b949e;
  margin: 0 0 0.4rem;
  font-weight: 600;
}

.mobile-wo-pad {
  margin: 0;
  padding: 0.15rem 0 0.25rem;
}

.mobile-wo-desc {
  font-size: 0.9rem;
  line-height: 1.45;
  color: #c9d1d9;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0.25rem 0 0;
}

.mobile-wo-mat-line {
  font-size: 0.9rem;
  margin-top: 0.4rem;
  padding: 0.5rem 0.65rem;
  border-left: 3px solid #388bfd;
  background: rgba(56, 139, 253, 0.07);
  border-radius: 0 6px 6px 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.mobile-wo-mat-line:first-of-type {
  margin-top: 0;
}

.mobile-wo-mat-name {
  line-height: 1.35;
}

.mobile-wo-mat-code {
  color: #8b949e;
  font-weight: 400;
}

.mobile-wo-mat-qty {
  font-size: 0.82rem;
  color: #c9d1d9;
  font-variant-numeric: tabular-nums;
}

.mobile-wo-files {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mobile-wo-files li {
  margin: 0;
  padding: 0.5rem 0;
  border-bottom: 1px solid #21262d;
  font-size: 0.9rem;
}

.mobile-wo-files li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.mobile-wo-file-link {
  color: #58a6ff;
  text-decoration: none;
  word-break: break-word;
  display: inline-block;
  line-height: 1.35;
}

.mobile-wo-file-link:active {
  opacity: 0.85;
}

.mobile-wo-file-meta {
  font-size: 0.78rem;
  color: #8b949e;
  margin-top: 0.2rem;
}

.mobile-wo-actions {
  border-top: 1px solid #30363d;
  margin-top: 0.75rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  box-sizing: border-box;
  background: rgba(1, 4, 9, 0.35);
}

.mobile-wo-label {
  display: block;
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #8b949e;
}

.mobile-wo-label-spaced {
  margin-top: 0.35rem;
}

.mobile-select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #e6edf3;
  font: inherit;
  font-size: 0.9rem;
}

.mobile-textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-height: 4.5rem;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #e6edf3;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  resize: vertical;
}

.mobile-file {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-size: 0.85rem;
  color: #c9d1d9;
}

.mobile-btn-block {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin-top: 0.15rem;
}

.mobile-muted {
  color: #8b949e;
  font-size: 0.88rem;
}

/* Horizontal scroll wrapper for wide tables on small screens */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  margin-bottom: 0.5rem;
}

.table-wrap table.data {
  margin-bottom: 0;
}

/*
  Sidebar is stable (always visible) from 640px up — same as desktop.
  Only narrow phones (max-width: 639px) get a Menu control; the nav expands in the document flow (no overlay).
*/
button.nav-toggle,
input.nav-toggle[type="button"],
.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-height: 2.75rem;
  padding: 0.4rem 0.85rem;
  margin: 0 0.35rem 0 0;
  border: 1px solid #58a6ff;
  border-radius: 6px;
  background: #21262d;
  color: #e6edf3;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  z-index: 5;
  box-sizing: border-box;
}

@media (max-width: 639px) {
  .layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  .sidebar {
    width: 100%;
    flex-shrink: 0;
    max-height: 0;
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
    border-right: none;
    border-bottom: 1px solid transparent;
    transition: max-height 0.3s ease-out, padding-top 0.3s ease-out, padding-bottom 0.3s ease-out, border-color 0.2s ease;
  }

  .sidebar.nav-open {
    max-height: min(28rem, 80vh);
    overflow-y: auto;
    padding-top: 1rem;
    padding-bottom: 1rem;
    border-bottom-color: #30363d;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar nav a {
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
  }

  .main-wrap {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    width: 100%;
  }

  .topbar {
    flex-wrap: wrap;
    padding: 0.5rem 0.65rem;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .topbar-search {
    order: 3;
    flex: 1 1 100%;
    max-width: none;
    min-width: 0;
  }

  .topbar-actions {
    margin-left: 0;
    flex: 1;
    justify-content: flex-end;
    min-width: 0;
  }

  .profile {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.35rem;
    font-size: 0.85rem;
  }

  .content {
    padding: 0.75rem 0.65rem 1.25rem;
  }

  .toolbar h1 {
    font-size: 1.15rem;
    flex: 1 1 100%;
  }

  .toolbar {
    gap: 0.5rem;
  }

  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .tabs .tab,
  .tabs a {
    flex-shrink: 0;
    padding: 0.55rem 0.75rem;
    font-size: 0.9rem;
  }

  .kanban {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
  }

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

  .kpi-card .value {
    font-size: 1.45rem;
  }

  .btn {
    min-height: 2.75rem;
    padding: 0.5rem 0.85rem;
    touch-action: manipulation;
  }

  input[type="text"],
  input[type="date"],
  input[type="number"],
  input[type="email"],
  input[type="search"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px;
  }

  .form-section input[type="text"],
  .form-section input[type="date"],
  .form-section input[type="number"],
  .form-section input[type="email"],
  .form-section select {
    width: 100%;
  }

  table.data {
    font-size: 0.85rem;
  }

  table.data th,
  table.data td {
    padding: 0.45rem 0.5rem;
  }
}

@media (min-width: 640px) {
  .nav-toggle {
    display: none !important;
  }
}

@media (min-width: 640px) and (max-width: 1279px) {
  .kanban {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
  }

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

  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .tabs .tab,
  .tabs a {
    flex-shrink: 0;
    padding: 0.55rem 0.75rem;
    font-size: 0.9rem;
  }

  .btn {
    min-height: 2.75rem;
    padding: 0.5rem 0.85rem;
    touch-action: manipulation;
  }

  .content {
    padding: 1rem 1rem 1.25rem;
  }
}

@media (max-width: 560px) {
  .kanban {
    grid-template-columns: 1fr;
  }

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

@supports (padding: max(0px, env(safe-area-inset-left))) {
  @media (max-width: 639px) {
    .content {
      padding-left: max(0.65rem, env(safe-area-inset-left));
      padding-right: max(0.65rem, env(safe-area-inset-right));
      padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    }

    .topbar {
      padding-left: max(0.65rem, env(safe-area-inset-left));
      padding-right: max(0.65rem, env(safe-area-inset-right));
    }

    .sidebar {
      padding-left: max(0, env(safe-area-inset-left));
    }
  }
}

@media (max-width: 1279px) {
  tr.row-clickable:active {
    background: rgba(56, 139, 253, 0.12);
  }
}

.workflow-step-list label {
  display: inline-block;
  margin-right: 1.25rem;
  margin-bottom: 0.35rem;
}

@media (max-width: 480px) {
  .login-box {
    margin: 0.75rem;
    padding: 1.25rem;
  }

  .login-page {
    align-items: flex-start;
    padding-top: 1rem;
  }
}

