:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #6d7788;
  --line: #e6eaf1;
  --brand: #1477f8;
  --brand-dark: #0e5cc7;
  --danger: #e04444;
  --green: #179765;
  --teal: #0f8b8d;
  --orange: #cc7200;
  --purple: #7a48d1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

a {
  color: var(--brand);
  text-decoration: none;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #101828;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  font-weight: 800;
}

.brand small {
  display: block;
  color: #9aa4b2;
}

nav {
  display: grid;
  gap: 8px;
}

nav a {
  padding: 11px 12px;
  border-radius: 8px;
  color: #cbd5e1;
}

nav a.active,
nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.logout-form {
  margin-top: 24px;
}

.logout-form button {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
}

.main {
  padding: 28px;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.flash-message {
  padding: 10px 14px;
  border: 1px solid #b9e8cf;
  border-radius: 8px;
  background: #eafaf1;
  color: #13784e;
  font-weight: 700;
}

.flash-message.error {
  border-color: #f3b8b8;
  background: #fff0f0;
  color: var(--danger);
}

.page-head,
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-head {
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

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

.head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button,
button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.button.ghost {
  background: #e8f1ff;
  color: var(--brand-dark);
}

.danger-button {
  background: var(--danger);
}

.link-button {
  height: auto;
  padding: 0;
  background: transparent;
  color: var(--brand);
  box-shadow: none;
}

.danger-text {
  color: var(--danger);
}

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

.stats-grid article,
.panel,
.master-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(16, 24, 40, 0.04);
}

.stats-grid article {
  padding: 16px;
}

.stats-grid span {
  display: block;
  color: var(--muted);
}

.stats-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.tag,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-left: 6px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
}

.tag.danger {
  background: #ffe9e9;
  color: var(--danger);
}

.status.orange {
  background: #fff2de;
  color: var(--orange);
}

.status.blue {
  background: #e7f0ff;
  color: var(--brand-dark);
}

.status.purple {
  background: #f0e8ff;
  color: var(--purple);
}

.status.cyan,
.status.teal {
  background: #e4f8f8;
  color: var(--teal);
}

.status.green {
  background: #e5f8ef;
  color: var(--green);
}

.status.gray {
  background: #eef1f5;
  color: #667085;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.tabs a {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.tabs a.active {
  border-color: var(--brand);
  color: var(--brand-dark);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 18px;
}

.kv {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px 14px;
  margin: 14px 0 0;
}

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

.kv dd {
  margin: 0;
}

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

textarea {
  min-height: 86px;
  padding: 10px;
  resize: vertical;
}

input[type="file"] {
  display: flex;
  align-items: center;
  height: auto;
  min-height: 40px;
  padding: 8px 10px;
}

.auth-page {
  display: block;
  min-height: 100vh;
  background: #eef3f8;
}

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

.auth-panel {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  background: #fff;
  box-shadow: 0 14px 40px rgba(16, 24, 40, 0.08);
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.auth-switch,
.demo-note {
  margin-top: 16px;
}

.form-error {
  margin: 16px 0 0;
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffe9e9;
  color: var(--danger);
  font-weight: 700;
}

select[multiple] {
  min-height: 118px;
  padding: 8px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-form,
.bulk-bar,
.wide-form,
.inline-edit {
  display: grid;
  gap: 12px;
}

.filter-form {
  grid-template-columns: minmax(220px, 1.4fr) repeat(3, minmax(140px, 1fr)) auto auto;
  align-items: end;
}

.bulk-bar {
  grid-template-columns: auto 150px 180px 160px auto 1fr;
  align-items: center;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.wide-form {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  align-items: end;
  margin-top: 12px;
}

.wide-form .span-2 {
  grid-column: span 2;
}

.inline-edit {
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  align-items: end;
  min-width: 360px;
}

.inline-edit.master-edit {
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  min-width: 460px;
}

.inline-edit.service-edit {
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  min-width: 520px;
}

.service-form {
  align-items: start;
}

.service-table {
  min-width: 1080px;
}

.image-cell {
  width: 112px;
}

.service-thumb,
.image-empty {
  width: 96px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.service-thumb {
  object-fit: cover;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.image-empty {
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.file-line,
.checkbox-line {
  display: grid;
  gap: 6px;
}

.checkbox-line {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.row-actions {
  min-width: 96px;
}

.row-actions form,
.head-actions form {
  margin: 0;
}

.table-scroll {
  overflow-x: auto;
}

.person-table {
  min-width: 560px;
}

.person-table .check-cell {
  width: 46px;
  vertical-align: middle;
}

.person-table .action-cell {
  width: 160px;
}

.person-cell {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
}

.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 50%;
  background: #e8f1ff;
  color: var(--brand-dark);
  font-size: 16px;
  font-weight: 800;
}

.person-table .row-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.empty-state {
  padding: 34px 12px;
  color: var(--muted);
  text-align: center;
}

.modal {
  width: min(840px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(16, 24, 40, 0.28);
}

.modal::backdrop {
  background: rgba(16, 24, 40, 0.52);
}

.modal-card {
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.modal-card-wide {
  width: 100%;
}

.modal.modal-wide {
  width: min(1120px, calc(100vw - 48px));
}

.modal-head,
.modal-section-title,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.modal-head {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  flex: 0 0 36px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.detail-summary {
  margin: 18px 0;
  padding: 14px 16px;
  border-radius: 8px;
  background: #f8fafc;
}

.compact-kv {
  margin: 0;
  grid-template-columns: 90px 1fr;
}

.modal-form {
  display: grid;
  gap: 16px;
}

.modal-section-title {
  align-items: baseline;
}

.modal-section-title > .muted {
  max-width: 52%;
  font-size: 13px;
  text-align: right;
}

.modal-section-title h3 {
  margin: 0;
}

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

.form-grid-2 .span-2 {
  grid-column: span 2;
}

.modal-actions {
  justify-content: flex-end;
  padding-top: 4px;
}

.master-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.master-metrics > div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

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

.master-metrics strong {
  display: block;
  margin-top: 5px;
  font-size: 17px;
}

.master-metrics .status {
  display: inline-flex;
  margin: 5px 0 0;
  font-size: 12px;
}

.skill-picker {
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.skill-picker legend {
  padding: 0 6px;
  font-weight: 800;
}

.field-help {
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.skill-group + .skill-group {
  margin-top: 15px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.skill-group h4 {
  margin: 0 0 9px;
  font-size: 14px;
}

.skill-subgroup + .skill-subgroup {
  margin-top: 9px;
}

.skill-group-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.skill-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 7px;
}

.skill-option {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}

.skill-option:has(input:checked) {
  border-color: #8dbafc;
  background: #eef5ff;
  color: var(--brand-dark);
}

.skill-option input {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  margin: 0;
}

@media (max-width: 640px) {
  .modal-card,
  .modal-card-wide {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    padding: 18px;
  }

  .modal.modal-wide {
    width: calc(100vw - 20px);
  }

  .form-grid-2,
  .master-metrics {
    grid-template-columns: 1fr;
  }

  .form-grid-2 .span-2 {
    grid-column: auto;
  }

  .modal-section-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }
}

.table-address {
  min-width: 220px;
  max-width: 320px;
}

.form-inline,
.material-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.material-form {
  grid-template-columns: 1.2fr 1fr 80px 80px 90px 100px;
}

.timeline {
  margin: 14px 0 0;
  padding-left: 18px;
}

.timeline li {
  margin-bottom: 14px;
}

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

.warranty-box {
  margin-top: 20px;
  padding: 14px;
  border-radius: 8px;
  background: #f7fafc;
}

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

.master-card {
  padding: 16px;
}

.master-card span {
  display: block;
  color: var(--muted);
  margin: 4px 0 10px;
}

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

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

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

  .material-form {
    grid-template-columns: 1fr;
  }

  .filter-form,
  .bulk-bar,
  .wide-form,
  .inline-edit,
  .inline-edit.master-edit {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .wide-form .span-2 {
    grid-column: auto;
  }
}
