:root {
  --bg: #f4f5f4;
  --surface: #fff;
  --soft: #edf2ef;
  --ink: #18221e;
  --muted: #66736d;
  --line: #dce2df;
  --nav: #14231c;
  --green: #1e7b47;
  --blue: #2568b7;
  --amber: #b67805;
  --red: #c43d3d;
  --shadow: 0 16px 45px rgba(19, 33, 27, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Noto Sans Thai", Tahoma, sans-serif;
}

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

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  background: var(--nav);
  color: #f8fbf9;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 14px;
}

.brand img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #fff;
  object-fit: contain;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.local-card small,
.meta {
  color: var(--muted);
}

.sidebar .brand span,
.sidebar .local-card small {
  color: #b9c8c0;
}

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

.nav button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 9px 10px;
  background: transparent;
  color: #edf5f1;
  text-align: left;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: center;
}

.nav button.active,
.nav button:hover {
  background: rgba(255, 255, 255, 0.12);
}

.nav span:first-child {
  width: 25px;
  height: 25px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.13);
  font-size: 12px;
  font-weight: 800;
}

.local-card {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
}

.local-card > span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #55d77c;
}

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

.topbar {
  min-height: 70px;
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: 30px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 0;
}

.topbar-actions,
.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn,
.icon-btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
}

.icon-btn {
  width: 40px;
  padding: 8px;
  display: inline-grid;
  place-items: center;
}

.btn.primary {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.btn.secondary {
  background: var(--surface);
}

.content {
  display: grid;
  gap: 16px;
}

.card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.card {
  padding: 16px;
  min-height: 118px;
  display: grid;
  gap: 8px;
  align-content: space-between;
}

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

.card strong {
  font-size: 25px;
}

.card small {
  color: var(--green);
  font-weight: 800;
}

.panel {
  padding: 16px;
  min-width: 0;
}

.panel-header {
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

.unit-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.unit-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 10px;
}

.unit-card h3 {
  margin: 0;
  font-size: 17px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--soft);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.badge.green {
  background: #e2f5e8;
  color: var(--green);
}

.badge.blue {
  background: #e4efff;
  color: var(--blue);
}

.badge.amber {
  background: #fff2d4;
  color: var(--amber);
}

.badge.red {
  background: #ffe3e3;
  color: var(--red);
}

.progress {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--soft);
}

.progress span {
  display: block;
  height: 100%;
  background: var(--green);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 16px;
}

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

.info-cell {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
}

.info-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

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

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

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

th {
  color: var(--muted);
  background: #f8faf9;
  font-size: 12px;
}

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

.gantt-row {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-width: 1040px;
  border-bottom: 1px solid var(--line);
}

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

.gantt-label {
  padding: 10px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.gantt-track {
  position: relative;
  min-height: 54px;
  background-image: linear-gradient(to right, rgba(20, 35, 28, 0.11) 1px, transparent 1px);
  background-size: calc(100% / 12) 100%;
}

.gantt-bar {
  position: absolute;
  top: 13px;
  height: 26px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 850;
  min-width: 36px;
}

.gantt-bar.not-started {
  background: #858c88;
}

.gantt-bar.in-progress {
  background: var(--blue);
}

.gantt-bar.done {
  background: var(--green);
}

.gantt-bar.blocked {
  background: var(--red);
}

.image-strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.image-strip img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(360px, calc(100vw - 36px));
  border-radius: 8px;
  padding: 13px 14px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
}

.toast.error {
  background: var(--red);
}

.hidden {
  display: none !important;
}

.dialog {
  border: 0;
  padding: 0;
  background: transparent;
}

.dialog::backdrop {
  background: rgba(12, 22, 17, 0.45);
}

.dialog-panel {
  width: min(860px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.dialog-panel header,
.dialog-panel footer {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.dialog-panel footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.dialog-panel h2 {
  margin: 0;
  font-size: 20px;
}

.dialog-body {
  padding: 16px;
  overflow: auto;
}

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

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

.field.full {
  grid-column: 1 / -1;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfcfb;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

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

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

@media (max-width: 720px) {
  .main {
    padding: 16px;
  }

  .topbar,
  .panel-header {
    display: grid;
  }

  .topbar-actions,
  .toolbar {
    justify-content: start;
  }

  .nav,
  .kpi-grid,
  .unit-grid,
  .info-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
