:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --text: #172033;
  --muted: #66758c;
  --muted-strong: #46566f;
  --border: #d8e0ed;
  --border-strong: #b8c5d9;
  --accent: #0047ab;
  --accent-hover: #003b91;
  --accent-soft: #e7f0ff;
  --accent-line: #8fb6f3;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --success: #0f766e;
  --warning: #b45309;
  --radius: 8px;
  --shadow-panel: 0 18px 45px rgba(19, 38, 71, 0.08);
  --shadow-row: 0 10px 24px rgba(19, 38, 71, 0.07);
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(0, 71, 171, 0.045) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(180deg, #edf3fc 0, #f6f8fc 270px, #f6f8fc 100%);
  color: var(--text);
  min-height: 100vh;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role='button']:focus-visible {
  outline: 3px solid rgba(0, 71, 171, 0.26);
  outline-offset: 2px;
}

#app {
  max-width: 1220px;
  margin: 0 auto;
  padding: 24px 24px 52px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding: 16px 18px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(184, 197, 217, 0.82);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(10px);
}

.title {
  margin: 0;
  color: #10233f;
  font-size: 1.35rem;
  font-weight: 760;
  letter-spacing: 0;
  line-height: 1.2;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 15px;
  font-size: 0.92rem;
  font-weight: 680;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease,
    transform 0.1s ease, color 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(0, 71, 171, 0.2);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 12px 22px rgba(0, 71, 171, 0.26);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: #ffd0cc;
}

.btn-danger:hover {
  background: #ffe3e0;
  border-color: #ffb8b0;
}

.btn-ghost {
  min-height: 32px;
  background: #ffffff;
  color: var(--muted-strong);
  border-color: var(--border);
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-ghost:hover {
  background: var(--surface-soft);
  color: var(--accent);
  border-color: var(--accent-line);
}

.view-tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  margin: 0 0 18px;
  border: 1px solid rgba(184, 197, 217, 0.86);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 24px rgba(19, 38, 71, 0.06);
}

.view-tab {
  min-height: 34px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-strong);
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 680;
  padding: 7px 14px;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.view-tab:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.view-tab.active {
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(0, 71, 171, 0.2);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 5px 4px 10px;
  background: #f9fbff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.84rem;
}

.user-chip-name {
  max-width: 130px;
  overflow: hidden;
  color: var(--text);
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip-role {
  border-radius: 6px;
  padding: 2px 7px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 760;
  letter-spacing: 0;
}

.user-chip-role.role-super_admin {
  background: #fff7ed;
  color: var(--warning);
}

.user-chip-role.role-admin {
  background: #fef3c7;
  color: #92400e;
}

.user-chip-role.role-member {
  background: #dcfce7;
  color: #166534;
}

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  z-index: 40;
  max-width: min(520px, calc(100vw - 32px));
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius);
  background: #10233f;
  box-shadow: var(--shadow-panel);
  color: #ffffff;
  font-size: 0.9rem;
  padding: 10px 16px;
}

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

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

.sidebar,
.detail {
  min-height: 430px;
  border: 1px solid rgba(184, 197, 217, 0.88);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(10px);
}

.sidebar {
  max-height: calc(100vh - 150px);
  overflow: auto;
  padding: 10px;
}

.detail {
  padding: 22px;
}

.empty-hint {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  margin: 4px;
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-soft);
}

.empty-hint p {
  margin: 0.35em 0;
}

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

.small {
  font-size: 0.84rem;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item-row {
  list-style: none;
  padding: 0 0 12px;
  cursor: pointer;
}

.item-row:last-child {
  padding-bottom: 0;
}

.item-card {
  position: relative;
  overflow: hidden;
  border: 1px solid #c8d6ea;
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(19, 38, 71, 0.06);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease,
    transform 0.12s ease;
}

.item-row:hover .item-card {
  background: #ffffff;
  border-color: var(--accent-line);
  box-shadow: var(--shadow-row);
}

.item-row.active .item-card {
  background: #ffffff;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px rgba(0, 71, 171, 0.08), var(--shadow-row);
}

.item-row.active .item-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--accent);
  content: '';
}

.item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  border-bottom: 1px solid #cfdcec;
  background: #f8fbff;
  padding: 10px 12px 9px 14px;
}

.item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: #132747;
  font-size: 0.95rem;
  font-weight: 760;
  line-height: 1.32;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-header-actions {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 10px;
}

.item-times {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  max-width: 132px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.25;
  text-align: right;
}

.item-time-done[hidden] {
  display: none !important;
}

.item-done-cb {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.item-done-cb:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.item-body {
  min-height: 2.5em;
  background: #ffffff;
  padding: 12px 14px 13px;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.48;
  word-break: break-word;
}

.item-card.completed .item-body,
.item-card.completed .item-title {
  color: var(--muted);
  text-decoration: line-through;
}

.item-meta {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 7px;
}

.project-status {
  flex-shrink: 0;
  border: 1px solid #b9d7ff;
  border-radius: 6px;
  background: #edf5ff;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 780;
  line-height: 1.2;
  padding: 3px 8px;
}

.project-status.status-reviewing,
.project-status.status-discussing {
  background: #fff7ed;
  border-color: #fed7aa;
  color: var(--warning);
}

.project-status.status-developing {
  background: var(--accent-soft);
  border-color: #b9d7ff;
  color: var(--accent);
}

.project-status.status-paused {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #475569;
}

.project-status.status-delivered {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: var(--success);
}

.project-snapshot {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.72rem;
}

.project-snapshot span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field {
  margin-bottom: 18px;
}

.project-two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field label,
.assignment-field span {
  display: block;
  color: var(--muted-strong);
  font-size: 0.83rem;
  font-weight: 760;
  letter-spacing: 0;
  margin-bottom: 8px;
}

.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fbfdff;
  color: var(--text);
  font-family: inherit;
  font-size: 0.94rem;
  line-height: 1.45;
  padding: 10px 12px;
  resize: vertical;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.input::placeholder {
  color: #8795a8;
}

.input:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(0, 71, 171, 0.11);
  outline: none;
}

textarea.input {
  min-height: 92px;
}

.input-content {
  min-height: 150px;
}

.field-error {
  color: var(--danger);
  font-size: 0.84rem;
  margin: 7px 0 0;
}

.assignment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  border: 1px solid #dbe6f5;
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 14px;
}

.assignment-field {
  display: grid;
  gap: 0;
  margin: 0;
}

.assignment-field span {
  margin-bottom: 7px;
}

.row-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.check-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted-strong);
  cursor: pointer;
  font-size: 0.94rem;
  user-select: none;
}

.check-wrap input {
  accent-color: var(--accent);
}

.footer-actions {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.drop-zone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 22px;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.drop-zone:focus,
.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  outline: none;
}

.drop-zone.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.thumb {
  position: relative;
  width: 88px;
  height: 88px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #edf2f8;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  cursor: zoom-in;
  object-fit: cover;
}

.thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 23px;
  height: 23px;
  border: none;
  border-radius: 50%;
  background: rgba(16, 35, 63, 0.76);
  color: #ffffff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.thumb-remove:hover {
  background: rgba(16, 35, 63, 0.92);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 35, 63, 0.86);
  padding: 24px;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.26);
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  #app {
    padding: 16px 14px 40px;
  }

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

  .sidebar {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }

  .topbar-right {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .topbar-right .btn-primary {
    flex: 1;
  }

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

  .view-tabs {
    display: flex;
    width: 100%;
  }

  .view-tab {
    flex: 1;
  }

  .detail {
    padding: 16px;
  }

  .project-two-col,
  .assignment-grid,
  .project-snapshot {
    grid-template-columns: 1fr;
  }
}
