:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d9e0e7;
  --text: #17202a;
  --muted: #667587;
  --accent: #1f7a8c;
  --accent-strong: #145c6a;
  --ok: #237a4b;
  --warn: #b15d18;
  --bad: #a33a3a;
  --soft: #eef4f7;
  --shadow: 0 10px 24px rgba(17, 31, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

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

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 10px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

button.primary:hover {
  background: var(--accent-strong);
}

button.danger {
  color: var(--bad);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 9px;
  background: white;
  color: var(--text);
}

textarea {
  min-height: 72px;
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.checkbox-label input {
  width: auto;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.login-card p {
  margin: 0 0 18px;
  color: var(--muted);
}

.form-grid {
  display: grid;
  gap: 12px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
}

.brand span,
.user-meta {
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 14px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  text-align: left;
  border-color: transparent;
  background: transparent;
}

.nav button.active {
  background: var(--soft);
  border-color: var(--line);
  color: var(--accent-strong);
}

.nav-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.nav-badge {
  min-width: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bad);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.main {
  min-width: 0;
  padding: 18px;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 20px;
}

.section-head p {
  margin: 3px 0 0;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.stat b {
  display: block;
  font-size: 24px;
  line-height: 1.1;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.danger-stat b {
  color: var(--bad);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 180px;
}

.view-mode-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: -4px 0 12px;
}

.view-mode-control span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.view-mode-control button {
  min-width: 92px;
}

.view-mode-control button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.table-wrap {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.split > .table-wrap {
  min-width: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px 9px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f7fafc;
  color: #405164;
  font-size: 12px;
  z-index: 1;
}

tr:last-child td {
  border-bottom: 0;
}

.project-comments-row td {
  padding: 0 9px 9px 9px;
  background: #fbfdfe;
}

.deadline-row.overdue td:first-child {
  box-shadow: inset 4px 0 0 var(--bad);
}

.deadline-row.today td:first-child {
  box-shadow: inset 4px 0 0 #d77a1f;
}

.deadline-row.soon td:first-child {
  box-shadow: inset 4px 0 0 var(--warn);
}

.priority-low {
  --priority-color: var(--ok);
  --priority-bg: #edf8f2;
  --priority-text: var(--ok);
  --priority-border: #cae5d6;
}

.priority-medium {
  --priority-color: #c28a18;
  --priority-bg: #fff8db;
  --priority-text: #8a5d00;
  --priority-border: #efd785;
}

.priority-high {
  --priority-color: #d77a1f;
  --priority-bg: #fff1df;
  --priority-text: #9a4f0d;
  --priority-border: #f4ca98;
}

.priority-urgent {
  --priority-color: var(--bad);
  --priority-bg: #fdeaea;
  --priority-text: var(--bad);
  --priority-border: #f2b6b6;
}

.priority-row td:first-child {
  border-left: 4px solid var(--priority-color, transparent);
}

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

.project-title-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.compact-title {
  flex-wrap: nowrap;
}

.compact-title b {
  display: inline-block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.deadline-under-title {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 3px 0 4px;
}

.deadline-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  background: #f8fafc;
  color: #405164;
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
}

.deadline-pill b {
  font-weight: 700;
}

.deadline-pill.overdue {
  border-color: #f2b6b6;
  background: #fdeaea;
  color: var(--bad);
}

.deadline-pill.today {
  border-color: #f4ca98;
  background: #fff1df;
  color: #9a4f0d;
}

.deadline-pill.soon {
  border-color: #f0d1a7;
  background: #fff7e8;
  color: var(--warn);
}

.deadline-pill.ok {
  border-color: #cae5d6;
  background: #edf8f2;
  color: var(--ok);
}

.meta-item .deadline-pill span,
.meta-item .deadline-pill b {
  display: inline;
  margin: 0;
  font-size: 12px;
}

.priority-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--priority-border, var(--line));
  border-left: 5px solid var(--priority-color, var(--line));
  border-radius: 999px;
  padding: 2px 8px 2px 7px;
  background: var(--priority-bg, #f8fafc);
  color: var(--priority-text, #405164);
  font-size: 12px;
  line-height: 1.25;
  white-space: nowrap;
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.compact-badges {
  gap: 4px;
}

.compact-projects-table td {
  vertical-align: middle;
}

.compact-projects-table .project-meta-line {
  margin-top: 2px;
}

.compact-edit-row td {
  background: #fbfdfe;
  padding: 10px;
}

.project-action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.icon-button {
  width: 34px;
  min-width: 34px;
  padding: 7px 0;
  text-align: center;
  font-size: 15px;
  line-height: 1;
}

.icon-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.inline-deadline-form,
.inline-load-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.inline-deadline-form input {
  width: 136px;
}

.inline-load-form {
  margin-bottom: 6px;
}

.inline-load-form input {
  width: 72px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--soft);
  color: #2e4658;
  font-size: 12px;
  white-space: nowrap;
}

.badge.working {
  background: #e8f5ee;
  color: var(--ok);
}

.badge.waiting {
  background: #fff2df;
  color: var(--warn);
}

.badge.submitted {
  background: #e6f3f7;
  color: var(--accent-strong);
}

.badge.issue {
  background: #fdeaea;
  color: var(--bad);
}

.badge.finished {
  background: #e7edf2;
  color: #445569;
}

.badge.paused {
  background: #edf0f4;
  color: #5b6675;
}

.badge.no_repair,
.badge.na {
  background: #f1f5f9;
  color: #64748b;
}

.badge.operator {
  background: #eef2ff;
  color: #4f46e5;
}

.badge.reviewing {
  background: #fef9c3;
  color: #a16207;
}

.progress {
  height: 8px;
  background: #e7edf2;
  border-radius: 999px;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  width: var(--value);
  background: var(--accent);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}

.side-stack {
  display: grid;
  gap: 12px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.project-grid {
  display: grid;
  gap: 10px;
}

.project-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.project-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.project-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.meta-item {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.meta-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 2px;
}

.card-actions {
  display: grid;
  grid-template-columns: 180px 120px minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: start;
  margin-top: 10px;
}

.status-actions {
  grid-template-columns: repeat(4, minmax(130px, 1fr));
}

.status-actions label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.status-actions label select {
  margin-top: 4px;
}

.status-actions textarea {
  grid-column: 1 / span 3;
}

.status-actions button {
  align-self: end;
}

.comment-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.comment {
  border-left: 3px solid var(--line);
  padding: 5px 8px;
  color: #334252;
  background: #fafcfd;
  white-space: pre-wrap;
}

.comment small {
  display: block;
  color: var(--muted);
  margin-bottom: 2px;
  white-space: normal;
}

.comment .read-more-text {
  white-space: normal;
}

.project-details-stack {
  display: grid;
  gap: 8px;
}

.project-comments-panel {
  display: grid;
  gap: 4px;
  border-left: 3px solid var(--line);
  padding: 7px 10px;
  background: #f8fafc;
  color: #334252;
}

.project-comments-panel.empty {
  display: block;
}

.comment-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.comment-panel-head b {
  font-size: 12px;
  color: #405164;
}

.comment-panel-head small {
  color: var(--muted);
  font-size: 11px;
}

.comment-panel-text {
  line-height: 1.35;
  white-space: pre-wrap;
}

.comment-text {
  line-height: 1.35;
  white-space: pre-wrap;
}

.read-more-text input {
  display: none;
}

.read-more-text label {
  display: inline-block;
  margin-top: 2px;
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.read-more-text.no-overflow label {
  display: none;
}

.read-more-text .less {
  display: none;
}

.clamp-target {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.read-more-text input:checked + .clamp-target {
  display: block;
  overflow: visible;
  -webkit-line-clamp: unset;
}

.read-more-text input:checked ~ label .more {
  display: none;
}

.read-more-text input:checked ~ label .less {
  display: inline;
}

.comment-history-row small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 2px;
}

.comment-history {
  margin-top: 6px;
}

.comment-history summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-size: 12px;
}

.comment-history-row {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.tiny {
  padding: 3px 7px;
  min-height: 0;
  font-size: 11px;
}

.admin-project-tools {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.admin-project-tools summary {
  cursor: pointer;
  padding: 8px 10px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.admin-tools-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 10px 10px;
}

.tools-panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #fbfdfe;
}

.tools-panel h4 {
  margin: 0;
  font-size: 13px;
}

.compact-details {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0;
}

.compact-details summary {
  cursor: pointer;
  padding: 8px 9px;
  color: #405164;
  font-weight: 700;
}

.compact-details > *:not(summary) {
  margin: 0 9px 9px;
}

.tech-select-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.assignment-editor {
  display: grid;
  gap: 8px;
}

.technician-list {
  max-height: 120px;
  overflow: auto;
}

.mini-log {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.mini-log summary {
  cursor: pointer;
  padding: 7px 9px;
  color: #405164;
  font-size: 12px;
  font-weight: 700;
}

.mini-log-row {
  display: grid;
  gap: 2px;
  padding: 7px 9px;
  border-top: 1px solid var(--line);
  color: #334252;
  font-size: 12px;
}

.mini-log-row span:last-child {
  color: var(--muted);
}

.create-form,
.user-form {
  display: grid;
  gap: 10px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.assign-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.gantt {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

.gantt-row {
  display: grid;
  grid-template-columns: 230px 1fr 150px;
  align-items: center;
  min-width: var(--gantt-min-width, 1100px);
  border-bottom: 1px solid var(--line);
}

.gantt-row:last-child {
  border-bottom: 0;
}

.gantt-scale-row {
  background: #fbfdfe;
  min-height: 84px;
}

.gantt-name,
.gantt-date {
  padding: 8px 10px;
}

.gantt-name {
  position: sticky;
  left: 0;
  z-index: 4;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--line), 10px 0 16px rgba(17, 31, 45, 0.06);
}

.gantt-date {
  position: sticky;
  right: 0;
  z-index: 4;
  background: var(--panel);
  box-shadow: -1px 0 0 var(--line), -10px 0 16px rgba(17, 31, 45, 0.06);
}

.gantt-scale-row .gantt-name,
.gantt-scale-row .gantt-date {
  z-index: 6;
  background: #fbfdfe;
}

.gantt-date-heading {
  align-self: stretch;
  display: grid;
  grid-template-rows: 1fr 1fr;
  align-items: center;
  line-height: 1.2;
  padding-top: 10px;
  padding-bottom: 10px;
}

.gantt-date-heading span {
  display: block;
}

.gantt-track {
  position: relative;
  height: 34px;
  background-image: repeating-linear-gradient(to right, #eef2f5 0, #eef2f5 1px, transparent 1px, transparent 12.5%);
}

.gantt-scale {
  display: grid;
  grid-template-rows: 22px 26px 28px;
  height: 84px;
  background-image: none;
  overflow: hidden;
}

.gantt-scale-band {
  position: absolute;
  left: 0;
  right: 0;
  border-bottom: 1px solid var(--line);
}

.gantt-scale-years {
  top: 0;
  height: 22px;
}

.gantt-scale-months {
  top: 22px;
  height: 26px;
}

.gantt-scale-days {
  top: 48px;
  height: 28px;
  border-bottom: 0;
}

.gantt-scale-segment,
.gantt-day-cell {
  position: absolute;
  left: var(--left);
  width: var(--width);
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
  border-left: 1px solid #dfe7ee;
  padding: 0 2px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
  z-index: 1;
}

.gantt-scale-segment {
  color: #405164;
  background: #f8fafc;
}

.gantt-day-cell {
  color: var(--muted);
  background: #ffffff;
  font-size: 10px;
}

.gantt-month-frames {
  position: absolute;
  inset: 22px 0 0;
  pointer-events: none;
  z-index: 2;
}

.gantt-month-frame {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--left);
  width: var(--width);
  border-left: 4px solid rgba(127, 147, 167, 0.75);
  border-right: 4px solid rgba(127, 147, 167, 0.75);
  box-sizing: border-box;
}

.gantt-today-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--left);
  width: 0;
  border-left: 2px solid #e5484d;
  pointer-events: none;
  z-index: 5;
}

.gantt-today-marker.has-label {
  z-index: 7;
}

.gantt-today-marker.has-label span {
  position: absolute;
  top: 3px;
  left: 6px;
  padding: 2px 6px;
  border: 1px solid rgba(229, 72, 77, 0.35);
  border-radius: 999px;
  background: #fff1f2;
  color: #9f1239;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(159, 18, 57, 0.12);
}

.gantt-bar {
  position: absolute;
  top: 8px;
  left: var(--left);
  width: var(--width);
  height: 18px;
  min-width: 6px;
  border-radius: 4px;
  background: var(--accent);
  box-shadow: inset 4px 0 0 var(--priority-color, rgba(255, 255, 255, 0.45));
}

.gantt-bar.waiting {
  background: var(--warn);
}

.gantt-bar.submitted {
  background: var(--accent-strong);
}

.gantt-bar.issue {
  background: var(--bad);
}

.gantt-bar.paused {
  background: #7b8794;
}

details.archive {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
}

details.archive summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 700;
}

.archive-body {
  padding: 0 12px 12px;
}

.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fffdf7;
  color: #66512d;
  margin-bottom: 12px;
}

.password-notice {
  margin-bottom: 12px;
  border-color: #f5c766;
  background: #fffaf0;
}

.section-head.compact {
  margin-bottom: 8px;
}

code {
  display: inline-block;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f8fafc;
  color: #102033;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.error {
  color: var(--bad);
  min-height: 18px;
}

.readonly {
  opacity: 0.72;
}

@media (max-width: 980px) {
  .layout,
  .split {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    display: flex;
    overflow-x: auto;
  }

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

  .meta-grid,
  .field-row,
  .card-actions,
  .assign-row,
  .tech-select-grid,
  .admin-tools-grid {
    grid-template-columns: 1fr;
  }
}
