:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --line: #dbe2e7;
  --text: #172026;
  --muted: #65717a;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --blue: #2563eb;
  --amber: #b45309;
  --red: #b91c1c;
  --green: #15803d;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

button,
.button,
input,
select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  font: inherit;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  text-decoration: none;
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 60px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
}

.brand {
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.nav a {
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.nav a.active,
.nav a:hover {
  background: #e8f3f1;
  color: var(--brand-dark);
}

.logout {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.page,
.board-page {
  padding: 22px;
}

.narrow {
  max-width: 760px;
  margin: 0 auto;
}

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

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

.compact-note {
  margin: 0 0 10px;
  font-size: 13px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 14px;
}

.toolbar-actions,
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.view-form {
  display: inline-flex;
}

.toolbar-actions input {
  width: min(340px, 42vw);
}

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

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

.unassigned {
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 104px);
  padding: 14px;
  overflow: auto;
}

.unassigned-header {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.unassigned-header h2 {
  margin: 0;
}

.unassigned-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.unassigned-actions button {
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.board-scroll {
  overflow: auto;
  max-height: calc(100vh - 136px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.schedule-board {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
}

.schedule-board th,
.schedule-board td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.schedule-board thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  width: 150px;
  min-width: 150px;
  padding: 10px;
  background: #edf5f4;
  font-size: 13px;
}

.sticky-corner,
.contractor-name {
  position: sticky;
  left: 0;
  z-index: 25;
  width: 190px;
  min-width: 190px;
  background: #ffffff;
}

.contractor-name {
  padding: 10px;
  text-align: left;
  font-size: 13px;
}

.section-row th {
  position: sticky;
  left: 0;
  z-index: 18;
  padding: 9px 12px;
  background: #172026;
  color: #fff;
  text-align: left;
}

.job-list {
  min-height: 76px;
  padding: 6px;
}

.unassigned-list {
  min-height: 220px;
}

.job-card {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 5px 7px;
  margin-bottom: 6px;
  padding: 7px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  font-size: 12px;
}

.job-card strong,
.job-card span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.job-card span {
  grid-column: 2;
  color: var(--muted);
}

.job-edit {
  grid-column: 2;
  justify-self: start;
  min-height: 24px;
  padding: 0 7px;
  color: var(--brand-dark);
  font-size: 11px;
}

.job-card.manual {
  border-left-color: var(--amber);
}

.job-card.unavailable {
  border-color: #cbd5e1;
  border-left-color: #475569;
  background: #f8fafc;
}

.job-card.unavailable strong {
  color: #334155;
}

.unassigned-list .job-card.synced {
  border-color: #bbf7d0;
  border-left-color: var(--green);
  background: #f0fdf4;
}

.job-card.locked {
  opacity: 0.62;
}

.job-card.sync-failed {
  border-color: #fecaca;
  border-left-color: var(--red);
  background: #fff7f7;
}

.job-card.syncing {
  opacity: 0.7;
}

.job-card.search-hidden {
  display: none !important;
}

.job-card.selected {
  border-color: #facc15;
  outline: 2px solid #facc15;
}

.drag-handle {
  grid-row: 1 / span 2;
  width: 24px;
  min-height: 24px;
  padding: 0;
  color: var(--muted);
  cursor: grab;
}

.bulk-bar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #172026;
  color: #fff;
  box-shadow: var(--shadow);
}

.toast.success {
  background: var(--green);
}

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

.toast.info {
  background: var(--blue);
}

.job-dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.job-dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.job-dialog-shell {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.job-dialog-shell label {
  display: grid;
  gap: 6px;
}

.job-dialog-shell input,
.job-dialog-shell select,
.job-dialog-shell textarea {
  width: 100%;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dialog-actions {
  justify-content: flex-end;
}

.alert {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.alert.warning {
  border-color: #fde68a;
  background: #fffbeb;
  color: #78350f;
}

.alert.info {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
}

.alert.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.alert.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--red);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
}

.badge.warning,
.badge.failed {
  background: #fef3c7;
  color: #92400e;
}

.badge.success {
  background: #dcfce7;
  color: #166534;
}

.badge.skipped {
  background: #e5e7eb;
  color: #374151;
}

.empty-section {
  padding: 12px;
  color: var(--muted);
  background: #fafafa;
}

.year-board thead th {
  width: 120px;
  min-width: 120px;
}

.year-cell {
  min-width: 120px;
  height: 70px;
  padding: 8px;
  background: #fff;
}

.year-count {
  display: inline-flex;
  margin-bottom: 6px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
}

.year-job {
  max-width: 110px;
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel,
.table-panel {
  margin-top: 14px;
  padding: 16px;
}

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

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

.table-panel th,
.table-panel td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.settings-grid div,
.summary-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.settings-grid span,
.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

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

.import-rules {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.import-rules div {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.import-form {
  max-width: 520px;
}

.plain-list {
  margin: 8px 0 0;
  padding-left: 18px;
}

.import-preview {
  margin-top: 12px;
  box-shadow: none;
}

.settings-form {
  display: grid;
  gap: 14px;
  max-width: 900px;
  margin-top: 14px;
}

.settings-form label {
  display: grid;
  gap: 6px;
}

.settings-form input:not([type="checkbox"]) {
  width: 100%;
}

.settings-help {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.settings-help div {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
}

.settings-help span {
  color: var(--muted);
  font-size: 13px;
}

.settings-help code {
  overflow-wrap: anywhere;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.sso-button {
  width: 100%;
  margin-top: 14px;
}

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

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

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

.stack label {
  display: grid;
  gap: 6px;
}

.stack input,
.stack button {
  width: 100%;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stack label.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
}

.checkbox input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin: 0;
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
  }

  .logout {
    width: 100%;
    justify-content: space-between;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions input {
    width: 100%;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .unassigned {
    position: static;
    max-height: 260px;
  }

  .board-scroll {
    max-height: 72vh;
  }
}
