:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #677189;
  --border: #dbe2ee;
  --primary: #1f6feb;
  --primary-dark: #1857ba;
  --good: #1a7f37;
  --warning: #b98500;
  --danger: #c62828;
  --grid-border: #8e99ab;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.page {
  width: 100vw;
  max-width: 100vw;
  margin: 0;
  padding: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
  width: 100%;
}

.compact-topbar {
  margin-bottom: 12px;
}

.top-actions-right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

h1,
h2 {
  margin: 0 0 12px 0;
}

.muted {
  color: var(--muted);
}

.tiny {
  font-size: 12px;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--primary);
  text-decoration: none;
}

.card {
  width: 100%;
  max-width: 100%;
  margin: 0 0 16px 0;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(16, 24, 40, 0.04);
}

.form-grid,
.task-create-grid,
.task-add-form {
  display: grid;
  gap: 14px;
}

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

.task-create-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.task-create-grid .span-2,
.task-add-form .span-2 {
  grid-column: span 2;
}

.form-grid label,
.task-create-grid label,
.task-add-form label,
.filters label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-actions,
.filter-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.filters {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
}

.filters .grow {
  flex: 1;
  min-width: 260px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 6px 8px;
  background: #fff;
}

textarea {
  resize: vertical;
}

.btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

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

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.secondary {
  background: #e9effb;
  color: #173a7a;
}

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

.btn-sm {
  padding: 8px 12px;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

th,
td {
  border: 1px solid var(--grid-border);
  text-align: left;
  padding: 6px;
  vertical-align: top;
}

th {
  background: #efefef;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: normal;
  text-align: center;
  font-weight: 700;
  color: #000;
}

.tasks-table {
  min-width: 3050px;
}

.compact-table th,
.compact-table td {
  padding: 0;
}

.compact-table th {
  font-size: 12px;
  line-height: 1.15;
  padding: 6px 6px;
  word-break: break-word;
  overflow-wrap: anywhere;
  vertical-align: middle;
}

.compact-table input,
.compact-table select,
.compact-table textarea {
  font-size: 12px;
  padding: 6px 8px;
  border: 0;
  min-height: 34px;
}

.compact-input,
.compact-select,
.compact-date,
.compact-textarea {
  min-width: 0;
}

.compact-date {
  width: 138px;
}

.w-xxs {
  width: 72px;
}

.w-xs {
  width: 90px;
}

.w-sm {
  width: 130px;
}

.w-md {
  width: 190px;
}

.w-lg {
  width: 300px;
}

.w-status {
  width: 140px;
}

.grid-table {
  border: 1px solid var(--grid-border);
  background: #fff;
}

.grid-table th,
.grid-table td {
  border: 1px solid var(--grid-border);
}

.grid-table thead th {
  background: #efefef;
}

.grid-table thead .col-gate-head {
  width: 90px;
  min-width: 90px;
}

.grid-table thead .col-task-no-head {
  width: 90px;
  min-width: 90px;
}

.grid-table thead .col-task-head {
  width: 220px;
  min-width: 220px;
}

.grid-table thead .col-km-head {
  width: 140px;
  min-width: 140px;
  background: #ffc000;
}

.grid-table thead .col-subtask-head {
  width: 220px;
  min-width: 220px;
}

.grid-table thead .col-dependency-head {
  width: 380px;
  min-width: 380px;
}

.grid-table thead .col-exec-head {
  width: 190px;
  min-width: 190px;
}

.grid-table thead .col-doc-head {
  width: 240px;
  min-width: 240px;
}

.grid-table thead .col-recipient-head {
  width: 240px;
  min-width: 240px;
}

.grid-table thead .col-responsible-head {
  width: 170px;
  min-width: 170px;
}

.grid-table thead .col-date-head {
  width: 145px;
  min-width: 145px;
}

.grid-table thead .col-days-head {
  width: 120px;
  min-width: 120px;
}

.grid-table thead .col-status-head {
  width: 150px;
  min-width: 150px;
}

.grid-table thead .col-relevant-head {
  width: 160px;
  min-width: 160px;
}

.gate-group-row td {
  background: #d9e2f3;
  font-weight: 700;
  font-size: 14px;
  padding: 8px 10px;
  border-top: 1px solid var(--grid-border);
  border-bottom: 1px solid var(--grid-border);
}

.empty-grid-row td {
  height: 34px;
  background: #fff;
  padding: 6px 8px;
}

.row-saving td {
  background: #fff7e6;
}

.row-saved td {
  background: #edf9ee;
}

.row-error td {
  background: #fdecec;
}

.stats-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

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

.stat-card {
  padding: 14px;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
}

.layout-2-single {
  margin-bottom: 16px;
}

.gate-page {
  width: 100%;
  padding: 8px;
}

.compact-gate-page {
  padding: 4px 8px 8px;
}

.gate-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.compact-gate-topbar {
  margin-bottom: 4px;
}

.gate-plan-sheet-wrap {
  overflow-x: auto;
}

.compact-sheet-wrap {
  max-width: 980px;
}

.gate-plan-sheet {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
  border: 2px solid #2c2c2c;
}

.compact-gate-sheet {
  min-width: 960px;
}

.gate-plan-sheet th,
.gate-plan-sheet td {
  border: 1px solid #2c2c2c;
  padding: 0;
  text-align: center;
  vertical-align: middle;
}

.gate-plan-sheet .sheet-title-row th {
  background: #dbe9f6;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 8px;
  border-bottom: 2px solid #2c2c2c;
  position: static;
}

.gate-plan-sheet .sheet-group-row th,
.gate-plan-sheet .sheet-sub-row th {
  background: #f3f3f3;
  font-weight: 700;
  color: #000;
  position: static;
}

.gate-plan-sheet .sheet-group-row th {
  padding: 5px 6px;
  font-size: 13px;
}

.gate-plan-sheet .sheet-sub-row th {
  padding: 5px 6px;
  font-size: 12px;
}

.gate-plan-sheet .sheet-gate-col {
  width: 280px;
}

.gate-plan-sheet .sheet-date-col {
  width: 165px;
}

.gate-plan-sheet .sheet-gate-name {
  text-align: left;
  font-weight: 400;
  white-space: nowrap;
  padding: 6px 8px;
  background: #fff;
  font-size: 13px;
}

.gate-sheet-input {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 0;
  padding: 4px 6px;
  height: 28px;
  text-align: center;
  background: #fff;
  font-size: 12px;
}

.gate-sheet-input:focus,
.grid-table input:focus,
.grid-table textarea:focus,
.grid-table select:focus {
  outline: 2px solid #9dc2ff;
  outline-offset: -2px;
}

@media (max-width: 1200px) {
  .form-grid,
  .task-create-grid,
  .task-add-form,
  .stats-grid-3 {
    grid-template-columns: 1fr;
  }

  .task-create-grid .span-2,
  .task-add-form .span-2 {
    grid-column: span 1;
  }

  .topbar,
  .gate-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions-right {
    justify-content: flex-start;
  }
}

.sticky-scroll-host {
  overflow-x: auto;
  overflow-y: visible;
}

.sticky-x-scroll {
  position: sticky;
  bottom: 0;
  z-index: 30;
  height: 18px;
  overflow-x: auto;
  overflow-y: hidden;
  background: rgba(245, 247, 251, 0.98);
  border-top: 1px solid var(--grid-border);
  display: none;
}

.sticky-x-scroll-inner {
  height: 1px;
}

.date-not-started {
  background: #e6e6e6 !important;
}

.date-progress {
  background: #f3dd8c !important;
}

.date-done {
  background: #dff0d8 !important;
}

.date-delay {
  background: #efc08d !important;
}

.date-shifted {
  background: #f4d6dc !important;
}

.grid-table thead .col-task-no-head {
  width: 58px;
  min-width: 58px;
}

.grid-table thead .col-dependency-head {
  width: 260px;
  min-width: 260px;
}

.grid-table thead .col-exec-head {
  width: 145px;
  min-width: 145px;
}

.grid-table thead .col-days-head {
  width: 82px;
  min-width: 82px;
}

.grid-table thead .col-status-head {
  width: 100px;
  min-width: 100px;
}

.grid-table thead .col-relevant-head {
  width: 100px;
  min-width: 100px;
}

.w-xs {
  width: 58px;
}

.w-status {
  width: 100px;
}

.w-xxs {
  width: 60px;
}