:root {
  color-scheme: light;
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-muted: #f0f3f4;
  --text: #20272d;
  --muted: #65717a;
  --border: #d8dee2;
  --brand: #176b5b;
  --brand-dark: #105246;
  --blue: #206fa5;
  --amber: #a96808;
  --red: #b5413f;
  --purple: #6e5596;
  --shadow: 0 8px 24px rgba(35, 48, 57, 0.08);
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

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

.auth-card {
  width: min(100%, 430px);
  display: grid;
  gap: 18px;
  padding: 30px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(30, 43, 59, 0.12);
}

.auth-brand {
  padding-bottom: 18px;
}

.auth-heading h1 {
  margin: 4px 0 6px;
  font-size: 26px;
}

.auth-heading p,
.field-hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.auth-submit {
  width: 100%;
  min-height: 46px;
}

.auth-logout {
  justify-self: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 18px;
}

.session-summary {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.session-summary > span:nth-child(2) {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.session-summary strong,
.session-summary small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.team-reset-button {
  margin-top: 10px;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(32, 111, 165, 0.25);
  outline-offset: 2px;
}

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

h1 {
  margin-bottom: 0;
  font-size: 27px;
  line-height: 1.25;
}

h2 {
  margin-bottom: 4px;
  font-size: 21px;
  line-height: 1.3;
}

h3 {
  margin-bottom: 0;
  font-size: 16px;
  line-height: 1.4;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background: #eef1ef;
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  padding: 0 8px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  color: #fff;
  background: var(--brand);
  border-radius: 5px;
  font-weight: 800;
}

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

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

.brand div span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 5px;
  margin-top: 18px;
}

.nav-button,
.mobile-nav button {
  min-height: 42px;
  border: 0;
  color: #3b464e;
  background: transparent;
  font-weight: 650;
}

.nav-button {
  padding: 0 13px;
  text-align: left;
  border-radius: 5px;
}

.nav-button:hover,
.nav-button.is-active {
  color: var(--brand-dark);
  background: #dfe9e5;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 8px 0;
  border-top: 1px solid var(--border);
}

.storage-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.storage-indicator > span {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  background: var(--brand);
  border-radius: 50%;
}

.main-content {
  min-width: 0;
  padding: 26px 30px 44px;
}

.project-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 27px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.title-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.project-heading p,
.section-heading p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-chip,
.priority-badge,
.ticket-key,
.due-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-chip {
  color: #16594c;
  background: #dceee9;
}

.header-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 40px;
  padding: 0 15px;
  border-radius: 5px;
  font-weight: 700;
}

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

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

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

.secondary-button:hover {
  border-color: #aeb8be;
  background: #f9faf9;
}

.danger-button {
  color: var(--red);
  background: #fff;
  border: 1px solid #e1b5b3;
}

.text-button {
  min-height: 32px;
  padding: 0;
  color: var(--blue);
  background: transparent;
  border: 0;
  font-weight: 650;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-heading {
  min-height: 49px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 17px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(145px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card,
.panel,
.team-card,
.schedule-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.metric-card {
  min-height: 104px;
  padding: 17px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  display: block;
  margin-top: 8px;
  font-size: 29px;
  line-height: 1;
  font-weight: 800;
}

.metric-card.is-danger .metric-value {
  color: var(--red);
}

.metric-card.is-warning .metric-value {
  color: var(--amber);
}

.metric-card.is-success .metric-value {
  color: var(--brand);
}

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

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

.span-two {
  grid-column: 1 / -1;
}

.panel-heading {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.panel-heading > strong {
  color: var(--brand);
  font-size: 24px;
}

.progress-track {
  width: 100%;
  height: 12px;
  overflow: hidden;
  background: #e4e8e8;
  border-radius: 999px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: var(--brand);
  border-radius: inherit;
  transition: width 180ms ease-out;
}

.status-breakdown {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 15px;
}

.status-count {
  min-width: 0;
  padding: 10px;
  background: var(--surface-muted);
  border-radius: 5px;
}

.status-count strong,
.status-count span {
  display: block;
}

.status-count strong {
  font-size: 19px;
}

.status-count span {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-list,
.activity-list {
  display: grid;
}

.compact-row,
.activity-row {
  min-height: 46px;
  display: grid;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid #e9edef;
}

.compact-row:first-child,
.activity-row:first-child {
  border-top: 0;
}

.compact-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.compact-row button {
  overflow: hidden;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.activity-row {
  grid-template-columns: 33px minmax(0, 1fr) auto;
}

.activity-dot {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--brand-dark);
  background: #dceee9;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
}

.activity-row p {
  margin: 0;
  overflow-wrap: anywhere;
}

.empty-state {
  min-height: 84px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.board-heading {
  align-items: flex-end;
}

.board-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.board-filters input,
.board-filters select {
  height: 38px;
  min-width: 145px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.search-field input {
  width: 210px;
}

.ticket-list {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ticket-list-header,
.ticket-list-row {
  display: grid;
  grid-template-columns: 90px minmax(220px, 1fr) 128px 86px 150px 105px;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 12px 16px;
}

.ticket-list-header {
  min-height: 44px;
  color: var(--muted);
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
}

.ticket-list-row {
  min-height: 68px;
  border-bottom: 1px solid var(--border);
  border-left: 4px solid var(--blue);
}

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

.ticket-list-row:hover {
  background: #f8faf9;
}

.ticket-list-row[data-priority="urgent"] {
  border-left-color: var(--red);
}

.ticket-list-row[data-priority="high"] {
  border-left-color: var(--amber);
}

.ticket-list-row[data-priority="low"] {
  border-left-color: var(--muted);
}

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

.priority-badge {
  min-height: 23px;
  color: #6a4505;
  background: #fae7bd;
}

.priority-badge.priority-urgent {
  color: #8b2927;
  background: #f5d6d5;
}

.priority-badge.priority-normal {
  color: #315f7a;
  background: #dbeaf3;
}

.priority-badge.priority-low {
  color: #58636b;
  background: #e6eaec;
}

.ticket-title-button {
  width: 100%;
  min-height: 36px;
  margin: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  font-weight: 750;
  line-height: 1.45;
  text-align: left;
}

.ticket-title-button:hover {
  color: var(--brand-dark);
}

.assignee-inline {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.avatar {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  flex: 0 0 26px;
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
}

.due-badge {
  min-height: 24px;
  color: var(--muted);
  background: var(--surface-muted);
}

.due-badge.is-overdue {
  color: #8b2927;
  background: #f5d6d5;
}

.due-badge.is-soon {
  color: #76500b;
  background: #fae7bd;
}

.ticket-status-select {
  width: 100%;
  height: 36px;
  padding: 0 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 5px;
}

.ticket-list-empty {
  min-height: 160px;
}

.schedule-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.8fr) minmax(0, 2fr);
  gap: 16px;
}

.project-timeline {
  align-self: start;
}

.timeline-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 17px;
}

.timeline-date {
  padding: 12px;
  background: var(--surface-muted);
  border-radius: 5px;
}

.timeline-date span,
.timeline-date strong {
  display: block;
}

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

.timeline-date strong {
  margin-top: 5px;
}

.schedule-list {
  display: grid;
  gap: 12px;
}

.schedule-group {
  padding: 16px;
}

.schedule-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.schedule-item {
  min-height: 53px;
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid #e8ecee;
}

.schedule-item button {
  overflow: hidden;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  font-weight: 700;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.schedule-date {
  color: var(--muted);
  font-size: 13px;
}

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

.team-card {
  min-height: 190px;
  padding: 17px;
}

.member-heading {
  display: flex;
  align-items: center;
  gap: 11px;
}

.member-heading .avatar {
  width: 38px;
  height: 38px;
  flex-basis: 38px;
  font-size: 14px;
}

.member-heading strong,
.member-heading span {
  display: block;
}

.member-heading span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.workload-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 20px;
}

.workload-item {
  padding: 10px 6px;
  background: var(--surface-muted);
  border-radius: 5px;
  text-align: center;
}

.workload-item strong,
.workload-item span {
  display: block;
}

.workload-item strong {
  font-size: 19px;
}

.workload-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.team-progress {
  height: 7px;
  margin-top: 16px;
  overflow: hidden;
  background: #e4e8e8;
  border-radius: 999px;
}

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

dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: calc(100vh - 36px);
  padding: 0;
  overflow: auto;
  background: var(--surface);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(24, 35, 42, 0.25);
}

dialog::backdrop {
  background: rgba(21, 29, 34, 0.52);
}

.compact-dialog {
  max-width: 530px;
}

.dialog-form {
  padding: 23px;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.dialog-heading h2 {
  margin: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 50%;
  font-size: 25px;
}

.icon-button:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: #414c53;
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-weight: 450;
}

.field textarea {
  resize: vertical;
}

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

.form-error {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
}

.dialog-actions {
  margin-top: 12px;
  padding-top: 17px;
  border-top: 1px solid var(--border);
}

.action-spacer {
  flex: 1;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 16px;
  color: #fff;
  background: #28343b;
  border-radius: 5px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.mobile-nav {
  display: none;
}

.is-hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1050px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(145px, 1fr));
  }

  .team-grid {
    grid-template-columns: repeat(2, minmax(230px, 1fr));
  }

  .project-header,
  .header-right {
    align-items: flex-start;
  }

  .header-right {
    flex-direction: column;
  }

  .ticket-list-header,
  .ticket-list-row {
    grid-template-columns: 80px minmax(180px, 1fr) 120px 76px 125px 95px;
    gap: 10px;
  }
}

@media (max-width: 760px) {
  body {
    padding-bottom: 64px;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .main-content {
    padding: 18px 16px 30px;
  }

  .project-header {
    align-items: flex-start;
    margin-bottom: 21px;
    padding-bottom: 18px;
  }

  .auth-screen {
    padding: 14px;
  }

  .auth-card {
    padding: 22px 18px;
  }

  .header-right {
    width: 100%;
    gap: 12px;
  }

  .session-summary {
    width: 100%;
  }

  .session-summary > span:nth-child(2) {
    flex: 1;
  }

  h1 {
    font-size: 23px;
  }

  .header-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .header-actions button {
    min-width: 106px;
  }

  .metric-grid,
  .dashboard-grid,
  .schedule-layout,
  .team-grid {
    grid-template-columns: 1fr;
  }

  .span-two {
    grid-column: auto;
  }

  .status-breakdown {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .board-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .board-filters label:first-child {
    grid-column: 1 / -1;
  }

  .board-filters input,
  .board-filters select,
  .search-field input {
    width: 100%;
    min-width: 0;
  }

  .ticket-list-header {
    display: none;
  }

  .ticket-list-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "key priority"
      "title title"
      "status status"
      "assignee due";
    gap: 9px 12px;
    min-height: 0;
    padding: 14px 12px;
  }

  .ticket-list-row .ticket-key {
    grid-area: key;
  }

  .ticket-list-row .ticket-title-button {
    grid-area: title;
  }

  .ticket-list-row .ticket-status-select {
    grid-area: status;
  }

  .ticket-list-row .priority-badge {
    grid-area: priority;
  }

  .ticket-list-row .assignee-inline {
    grid-area: assignee;
  }

  .ticket-list-row .due-badge {
    grid-area: due;
    justify-self: end;
  }

  .schedule-item {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .schedule-item .assignee-inline {
    grid-column: 2;
  }

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

  .dialog-form {
    padding: 18px;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    height: 64px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--border);
  }

  .mobile-nav button {
    min-width: 0;
    font-size: 12px;
  }

  .mobile-nav button.is-active {
    color: var(--brand-dark);
    box-shadow: inset 0 3px 0 var(--brand);
  }

  .toast {
    right: 16px;
    bottom: 78px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
