:root {
  --bg: #f5f7f9;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #65717d;
  --line: #dce3e8;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warning: #b7791f;
  --danger: #b42318;
  --ok: #16803c;
  --blue: #2463a7;
  --shadow: 0 12px 28px rgba(25, 35, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #b7c4cc;
}

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

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

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.sidebar {
  background: #172026;
  color: #f8fbfc;
  padding: 18px 14px;
  min-height: 100vh;
  position: sticky;
  top: 0;
}

.brand {
  display: grid;
  gap: 6px;
  padding: 10px 8px 22px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  color: #aebbc4;
  font-size: 13px;
}

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

.nav-item {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: #cdd6dc;
  border-color: transparent;
}

.nav-item.active,
.nav-item:hover {
  color: #fff;
  background: #24313a;
  border-color: #34454f;
}

.shell {
  min-width: 0;
  padding: 22px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 16px;
}

.topbar p {
  color: var(--muted);
  margin-top: 6px;
  font-size: 14px;
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.filters.compact {
  grid-template-columns: repeat(3, minmax(160px, 220px));
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px 10px;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

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

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 156px);
}

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

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  font-size: 13px;
  vertical-align: top;
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #edf2f5;
  font-weight: 700;
}

.data-table tr:hover td {
  background: #f9fbfc;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #eef3f2;
  color: var(--accent-strong);
  font-weight: 700;
}

.status.cancel {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}

.status.pending {
  background: #fef3c7;
  border-color: #fde68a;
  color: #92400e;
}

.status.confirmed {
  background: #dcfce7;
  border-color: #bbf7d0;
  color: #166534;
}

.status.assistant {
  background: #dbeafe;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.status.rest {
  background: #f3e8ff;
  border-color: #e9d5ff;
  color: #7e22ce;
}

.status.todo {
  background: #ffedd5;
  border-color: #fed7aa;
  color: #c2410c;
}

.status.unknown {
  background: #e5e7eb;
  border-color: #d1d5db;
  color: #374151;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

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

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

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

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

.panel {
  padding: 14px;
  min-height: 290px;
}

canvas {
  width: 100%;
  height: 230px;
  display: block;
  margin-top: 12px;
}

.calendar-wrap {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 156px);
}

.calendar-grid {
  display: grid;
  min-width: max-content;
}

.cal-cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 240px;
  min-height: 78px;
  padding: 8px;
  font-size: 12px;
  background: #fff;
}

.cal-cell.person,
.cal-cell.day {
  position: sticky;
  background: #edf2f5;
  z-index: 2;
  font-weight: 700;
}

.cal-cell.person {
  left: 0;
  min-width: 126px;
}

.cal-cell.corner {
  left: 0;
  z-index: 4;
}

.cal-item {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #2563eb;
  border-radius: 6px;
  background: #eff6ff;
  color: #1e3a8a;
  padding: 5px 7px;
  margin-bottom: 6px;
  font-weight: 700;
}

.cal-item.confirmed {
  background: #f0fdf4;
  border-color: #bbf7d0;
  border-left-color: #16a34a;
  color: #166534;
}

.cal-item.cancel {
  background: #fef2f2;
  border-color: #fecaca;
  border-left-color: #dc2626;
  color: #991b1b;
}

.cal-item.pending {
  background: #fffbeb;
  border-color: #fde68a;
  border-left-color: #d97706;
  color: #92400e;
}

.cal-item.assistant {
  background: #eff6ff;
  border-color: #bfdbfe;
  border-left-color: #2563eb;
  color: #1d4ed8;
}

.cal-item.rest {
  background: #faf5ff;
  border-color: #e9d5ff;
  border-left-color: #9333ea;
  color: #7e22ce;
}

.cal-item.todo {
  background: #fff7ed;
  border-color: #fed7aa;
  border-left-color: #ea580c;
  color: #c2410c;
}

.cal-item.unknown {
  background: #f9fafb;
  border-color: #d1d5db;
  border-left-color: #6b7280;
  color: #374151;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: #f8fafb;
  font-size: 13px;
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1.05fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.settings-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.people-order-panel {
  grid-row: span 3;
}

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

.standalone-head {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.panel-head p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-top: 6px;
}

.panel-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.order-list {
  display: grid;
  gap: 8px;
}

.order-row {
  display: grid;
  grid-template-columns: 34px 28px minmax(0, 1fr) 82px;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.order-row:hover {
  border-color: #b7c4cc;
  box-shadow: 0 8px 18px rgba(25, 35, 45, 0.07);
}

.order-row.dragging {
  opacity: 0.55;
  transform: scale(0.995);
}

.order-row.drop-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.order-index {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #edf2f5;
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}

.drag-handle {
  color: #7b8790;
  cursor: grab;
  text-align: center;
  font-size: 18px;
  line-height: 1;
}

.person-name {
  min-width: 0;
  font-weight: 700;
}

.order-controls {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.order-controls button {
  width: 34px;
  min-height: 32px;
  padding: 0;
}

.save-note {
  color: var(--accent-strong);
  font-size: 13px;
  min-height: 18px;
  margin-top: 10px;
}

.binding-list {
  display: grid;
  gap: 8px;
}

.binding-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.binding-main strong,
.binding-main span {
  display: block;
}

.binding-main span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.binding-actions {
  display: flex;
  gap: 6px;
}

.notification-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

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

.mini-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

.mini-table th,
.mini-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  font-size: 12px;
  vertical-align: top;
}

.mini-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #edf2f5;
  font-weight: 700;
}

.log-status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid transparent;
  font-weight: 700;
}

.log-status.success {
  background: #dcfce7;
  border-color: #bbf7d0;
  color: #166534;
}

.log-status.failed {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}

.log-status.skipped {
  background: #f3f4f6;
  border-color: #d1d5db;
  color: #374151;
}

dialog {
  width: min(860px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(23, 32, 38, 0.36);
}

.record-form header,
.record-form footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.record-form footer {
  justify-content: flex-end;
  margin-top: 16px;
}

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

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

label.wide {
  grid-column: 1 / -1;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

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

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

  .filters,
  .filters.compact,
  .kpi-grid,
  .chart-grid,
  .settings-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .people-order-panel {
    grid-row: auto;
  }

  .panel-head {
    flex-direction: column;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
