:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #eef4f2;
  --text: #1d252c;
  --muted: #65717d;
  --border: #d8dee5;
  --primary: #176b5f;
  --primary-dark: #0e4f45;
  --accent: #bf7b18;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --warning-soft: #fff6e5;
  --success-soft: #eaf7ee;
  --info-soft: #edf4ff;
  --shadow: 0 16px 40px rgba(19, 35, 47, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 0 24px;
}

.topbar h1,
.section-heading h2,
.task-toolbar h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
  font-weight: 700;
}

.section-heading h2 {
  font-size: 22px;
  font-weight: 700;
}

.task-toolbar h3 {
  font-size: 18px;
  font-weight: 700;
}

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

.topbar-actions,
.button-row,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.date-badge,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(96px, 1fr));
  min-height: 42px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #e9edf1;
}

.tab-button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  min-height: 32px;
  padding: 0 14px;
}

.tab-button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(18, 31, 45, 0.08);
}

.workspace-panel {
  display: none;
}

.workspace-panel.active {
  display: block;
}

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

.plan-form,
.filters,
.summary-card,
.plan-card,
.department-stats,
.empty-state {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.plan-form {
  padding: 22px;
}

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

.filters {
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: none;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label span {
  color: #34404a;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  padding: 9px 11px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 95, 0.14);
}

.full-field {
  margin-top: 16px;
}

.task-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 24px 0 10px;
}

.tasks-container {
  display: grid;
  gap: 12px;
}

.task-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.15fr) minmax(220px, 1.5fr) minmax(118px, 0.7fr) minmax(112px, 0.65fr) 42px;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.task-row .wide {
  grid-column: span 2;
}

.remove-task-btn {
  align-self: end;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--danger);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.remove-task-btn:hover {
  border-color: #efb0aa;
  background: var(--danger-soft);
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 6px;
  padding: 0 16px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

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

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

.secondary-button {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.secondary-button:hover {
  border-color: #b5c0ca;
  background: #f4f7f9;
}

.ghost-button {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.ghost-button:hover {
  background: #edf0f3;
  color: var(--text);
}

.form-actions {
  justify-content: flex-end;
  margin-top: 20px;
}

.form-errors {
  display: none;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #efb0aa;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
}

.form-errors.active {
  display: block;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.summary-card {
  min-height: 96px;
  padding: 14px;
  box-shadow: none;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  line-height: 1.1;
}

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

.summary-card.warning {
  background: var(--warning-soft);
}

.summary-card.success {
  background: var(--success-soft);
}

.summary-card.info {
  background: var(--info-soft);
}

.department-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0;
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: none;
}

.department-stat {
  min-height: 86px;
  padding: 14px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.department-stat strong {
  display: block;
  margin-bottom: 5px;
}

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

.plans-board {
  display: grid;
  gap: 14px;
}

.plan-card {
  overflow: hidden;
  box-shadow: none;
}

.plan-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: #fbfcfd;
}

.plan-card-header h3 {
  margin: 0 0 5px;
  font-size: 18px;
}

.meta-line {
  color: var(--muted);
  font-size: 13px;
}

.plan-actions {
  display: flex;
  gap: 8px;
}

.danger-button {
  min-height: 36px;
  border: 1px solid #efb0aa;
  border-radius: 6px;
  background: var(--danger-soft);
  color: var(--danger);
  cursor: pointer;
  padding: 0 12px;
  font-weight: 700;
}

.plan-body {
  padding: 16px;
}

.leftovers {
  margin: 0 0 14px;
  padding: 12px;
  border-radius: 6px;
  background: #f2f5f7;
  color: #34404a;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #f7f9fb;
}

.status-pill,
.priority-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  min-width: 58px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-not_started {
  background: #eef1f4;
  color: #52606c;
}

.status-in_progress {
  background: var(--info-soft);
  color: #235a9f;
}

.status-completed {
  background: var(--success-soft);
  color: #17663a;
}

.status-not_completed {
  background: var(--danger-soft);
  color: var(--danger);
}

.priority-high {
  background: var(--danger-soft);
  color: var(--danger);
}

.priority-medium {
  background: var(--warning-soft);
  color: #9a5b00;
}

.priority-low {
  background: #eef1f4;
  color: #52606c;
}

.review-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 14px;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
  box-shadow: none;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  min-width: 220px;
  max-width: min(420px, calc(100% - 40px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #1d252c;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.active {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .topbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

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

  .remove-task-btn {
    grid-column: span 2;
    width: 100%;
  }
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 20px, 1240px);
    padding-top: 14px;
  }

  .topbar h1 {
    font-size: 23px;
  }

  .topbar-actions,
  .button-row,
  .form-actions {
    flex-wrap: wrap;
  }

  .date-badge,
  .tabs,
  .button-row,
  .button-row > *,
  .form-actions > * {
    width: 100%;
  }

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

  .plan-form {
    padding: 14px;
  }

  .form-grid,
  .filters,
  .summary-grid,
  .task-row,
  .review-box {
    grid-template-columns: 1fr;
  }

  .task-row .wide,
  .remove-task-btn {
    grid-column: auto;
  }

  .plan-card-header {
    flex-direction: column;
  }

  .plan-actions {
    width: 100%;
  }

  .plan-actions > * {
    flex: 1;
  }
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef2f5;
}

.auth-card {
  width: min(460px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 26px;
}

.auth-heading {
  margin-bottom: 18px;
}

.auth-heading h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  min-height: 42px;
  padding: 4px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #e9edf1;
}

.auth-tab {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(18, 31, 45, 0.08);
}

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

.auth-form .primary-button {
  width: 100%;
}

.auth-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--primary-dark);
  font-weight: 700;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .auth-screen {
    align-items: start;
    padding-top: 42px;
  }

  .auth-card {
    padding: 18px;
  }

  .auth-inline {
    grid-template-columns: 1fr;
  }

  .user-badge {
    width: 100%;
    justify-content: center;
  }
}

.auth-note {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-link {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-weight: 700;
  min-height: 32px;
  padding: 0;
  text-align: center;
}

.auth-link:hover {
  color: var(--primary-dark);
}

/* Simplified department task cards */
.task-row {
  display: block;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.task-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: #f6f8fa;
}

.task-index {
  font-size: 15px;
  color: #25313b;
}

.task-core-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) minmax(150px, 0.7fr) minmax(140px, 0.6fr) minmax(120px, 0.5fr);
  gap: 14px;
  padding: 14px;
}

.task-detail-field {
  grid-column: span 2;
}

.task-detail-field textarea {
  min-height: 92px;
}

.incomplete-field {
  grid-column: span 2;
}

.task-extra {
  border-top: 1px solid var(--border);
  background: #fff;
}

.task-extra summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--primary);
  cursor: pointer;
  font-weight: 700;
  outline: none;
}

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

.task-row .remove-task-btn {
  align-self: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
}

@media (max-width: 980px) {
  .task-core-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .task-detail-field,
  .incomplete-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .task-core-grid,
  .task-extra-grid {
    grid-template-columns: 1fr;
  }

  .task-row .remove-task-btn {
    width: 36px;
  }
}
