:root {
  color-scheme: light;
  --content-max: 760px;
  --wide-content-max: 1040px;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --green: #34c759;
  --green-dark: #16a34a;
  --green-soft: #e8f8e8;
  --yellow: #ffb020;
  --yellow-soft: #fff4d8;
  --red: #ff3b30;
  --red-soft: #ffe8e5;
  --blue: #2563eb;
  --shadow: 0 4px 18px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.phone-shell {
  position: relative;
  width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfc 100%);
  overflow-x: hidden;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen-active {
  display: flex;
  flex-direction: column;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: 76px 1fr 76px;
  align-items: center;
  min-height: 58px;
  padding: 8px max(16px, calc((100vw - var(--content-max)) / 2 + 16px));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.top-bar h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
}

.top-spacer {
  width: 76px;
}

.icon-button,
.back-button {
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--text);
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 1.55rem;
  line-height: 1;
}

.back-button {
  justify-self: start;
  padding: 0;
  color: #374151;
  font-size: 0.92rem;
}

.screen-body {
  flex: 1;
  width: min(100%, var(--content-max));
  margin: 0 auto;
  padding: 18px 16px 22px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.summary-card {
  min-height: 72px;
  padding: 10px 8px;
  border: 1px solid;
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
}

.summary-card span {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
  font-weight: 800;
}

.summary-card strong {
  font-size: 0.85rem;
}

.summary-card b {
  font-size: 1.55rem;
}

.summary-today {
  border-color: #ffb3ac;
  background: #fff7f6;
  color: var(--red);
}

.summary-week {
  border-color: #ffd47a;
  background: #fffaf0;
  color: #f59e0b;
}

.summary-open {
  border-color: #b9e9bf;
  background: #f4fff6;
  color: var(--green-dark);
}

.helper-text,
.helper-note,
.save-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.helper-text {
  margin-bottom: 8px;
  color: #374151;
  font-weight: 700;
}

.helper-note {
  margin-top: 10px;
  text-align: center;
}

.save-note {
  margin-top: 14px;
  color: var(--green-dark);
  text-align: center;
  opacity: 0;
  transition: opacity 160ms ease;
}

.save-note-visible {
  opacity: 1;
}

.category-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.category-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto minmax(42px, 58px);
  align-items: center;
  min-height: 48px;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

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

.category-all {
  grid-template-columns: 24px 1fr;
}

.category-loading {
  margin: 0;
  padding: 14px 12px;
  color: #4b5563;
  font-size: 0.9rem;
  border-top: 1px solid var(--line);
}

.category-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}

.view-tasks-button {
  width: 100%;
  min-height: 52px;
  margin-top: 16px;
  border: 0;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  font-weight: 900;
}

.category-name {
  font-weight: 800;
}

.category-meta {
  color: #4b5563;
  font-size: 0.82rem;
}

.progress-track {
  display: block;
  height: 4px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

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

.task-card {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 92px;
  padding: 16px min(28vw, 104px) 16px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  box-shadow: var(--shadow);
}

.task-card strong {
  display: block;
  margin-bottom: 9px;
  font-size: 1rem;
}

.task-date {
  color: #111827;
  font-weight: 700;
}

.due-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 800;
}

.task-card .due-label {
  position: absolute;
  right: 14px;
  bottom: 15px;
}

.due-safe {
  background: var(--green-soft);
  color: var(--green-dark);
}

.due-week {
  background: var(--yellow-soft);
  color: #d97706;
}

.due-soon {
  background: var(--red-soft);
  color: var(--red);
}

.due-over {
  background: #e5e7eb;
  color: #111827;
}

.empty-text {
  margin: 32px 0;
  color: var(--muted);
  text-align: center;
}

.detail-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 620px;
  padding-bottom: 88px;
}

.detail-card {
  padding: 22px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.detail-title-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.task-icon {
  font-size: 2rem;
}

.detail-title-row h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.detail-list {
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.detail-list div:last-child {
  border-bottom: 0;
}

.detail-list dt {
  color: #374151;
  font-size: 0.82rem;
  font-weight: 800;
}

.detail-list dd {
  margin: 0;
  line-height: 1.65;
}

.complete-large-button {
  position: fixed;
  right: max(16px, calc((100vw - var(--content-max)) / 2 + 16px));
  bottom: 16px;
  left: max(16px, calc((100vw - var(--content-max)) / 2 + 16px));
  z-index: 4;
  width: auto;
  min-height: 58px;
  margin-top: auto;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #45cc43 0%, #29b832 100%);
  color: #ffffff;
  font-size: 1.18rem;
  font-weight: 900;
  box-shadow: 0 12px 22px rgba(42, 184, 50, 0.28);
}

.confirm-dialog {
  width: min(calc(100% - 48px), 340px);
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
}

.confirm-dialog::backdrop {
  background: rgba(17, 24, 39, 0.55);
  backdrop-filter: blur(1px);
}

.confirm-card {
  padding: 24px 16px 16px;
  border-radius: 14px;
  background: var(--surface);
  text-align: center;
  box-shadow: 0 22px 60px rgba(17, 24, 39, 0.25);
}

.confirm-card h2 {
  margin: 0 0 20px;
  font-size: 1.08rem;
  line-height: 1.7;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border-radius: 8px;
  font-weight: 900;
}

.primary-button {
  border: 0;
  background: linear-gradient(180deg, #45cc43 0%, #29b832 100%);
  color: #ffffff;
}

.secondary-button {
  border: 0;
  background: #f3f4f6;
  color: #111827;
}

.complete-screen {
  background:
    radial-gradient(circle at 50% 30%, rgba(52, 199, 89, 0.14), transparent 36%),
    linear-gradient(180deg, #fbfff8 0%, #ffffff 100%);
}

.done-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
}

.done-mark {
  display: grid;
  width: 82px;
  height: 82px;
  margin-bottom: 26px;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: #ffffff;
  font-size: 3rem;
  font-weight: 900;
}

.done-body h1 {
  margin: 0 0 10px;
  font-size: 1.5rem;
}

.done-body p {
  margin: 0 0 28px;
}

.admin-login-body {
  padding-top: 40px;
}

.login-form,
.admin-form {
  display: grid;
  gap: 20px;
}

.login-form label,
.admin-form label {
  display: grid;
  gap: 8px;
  color: #374151;
  font-size: 0.84rem;
  font-weight: 800;
}

.login-form input,
.admin-form input,
.admin-form select,
.admin-form textarea {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
}

.admin-form select[multiple] {
  min-height: 176px;
  padding: 8px 12px;
}

.admin-form small {
  margin-top: -3px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.45;
}

.clear-members-button {
  justify-self: start;
  min-height: 36px;
  padding: 0 12px;
  margin-top: -2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: #374151;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 800;
}

.admin-form textarea {
  min-height: 104px;
  padding-top: 12px;
  resize: vertical;
}

.admin-form-body {
  width: min(100%, 560px);
}

.login-form input[aria-invalid="true"] {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.remember-row {
  display: flex !important;
  grid-template-columns: none;
  align-items: center;
  gap: 8px !important;
  font-size: 0.86rem !important;
  font-weight: 700 !important;
}

.remember-row input {
  width: 20px;
  min-height: 20px;
  accent-color: var(--blue);
}

.login-status {
  display: none;
  margin: -4px 0 0;
  color: #b91c1c;
  font-size: 0.86rem;
  font-weight: 800;
}

.login-status-visible {
  display: block;
}

.admin-login-button {
  min-height: 54px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 900;
}

.admin-login-button:disabled {
  opacity: 0.72;
}

.admin-menu-body {
  display: flex;
  flex-direction: column;
  width: min(100%, var(--wide-content-max));
}

.admin-menu-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.admin-menu-grid button {
  display: grid;
  min-height: 86px;
  place-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--blue);
  font-size: 1.9rem;
  box-shadow: var(--shadow);
}

.admin-menu-grid span {
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 900;
}

.logout-button {
  width: 100%;
  min-height: 54px;
  margin-top: auto;
  border: 1px solid var(--red);
  border-radius: 8px;
  background: #ffffff;
  color: var(--red);
  font-weight: 900;
}

.admin-list-body {
  width: min(100%, var(--wide-content-max));
}

.admin-list {
  display: grid;
  gap: 10px;
}

.admin-inline-form {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.admin-inline-form label {
  display: grid;
  gap: 6px;
  color: #4b5563;
  font-size: 0.82rem;
  font-weight: 900;
}

.admin-inline-form input {
  min-height: 46px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #f9fafb;
  color: var(--text);
  font: inherit;
}

.admin-inline-form button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font-weight: 900;
}

.admin-list-row {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.admin-list-row strong {
  font-size: 0.96rem;
}

.admin-list-row span {
  color: #4b5563;
  font-size: 0.82rem;
  line-height: 1.35;
}

.admin-list-action {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: #ffffff;
  color: var(--green);
  font-weight: 900;
}

.admin-list-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 5px;
}

.admin-list-action-danger {
  border-color: var(--red);
  color: var(--red);
}

.countdown-ring {
  display: grid;
  width: 68px;
  height: 68px;
  margin-bottom: 14px;
  place-items: center;
  border: 4px solid #dff1dc;
  border-top-color: var(--green);
  border-radius: 50%;
  font-size: 1.7rem;
  font-weight: 900;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  z-index: 10;
  max-width: 390px;
  margin: 0 auto;
  padding: 13px 16px;
  border-radius: 12px;
  background: #111827;
  color: #ffffff;
  font-weight: 800;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

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

@media (max-width: 359px) {
  .top-bar {
    grid-template-columns: 58px 1fr 58px;
    padding-right: 12px;
    padding-left: 12px;
  }

  .top-spacer {
    width: 58px;
  }

  .screen-body {
    padding-right: 12px;
    padding-left: 12px;
  }

  .summary-grid {
    gap: 6px;
  }

  .summary-card {
    padding-right: 4px;
    padding-left: 4px;
  }

  .summary-card b {
    font-size: 1.35rem;
  }

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

  .progress-track {
    display: none;
  }
}

@media (min-width: 680px) {
  .screen-body {
    padding-top: 24px;
    padding-bottom: 34px;
  }

  .summary-grid {
    gap: 14px;
  }

  .summary-card {
    min-height: 88px;
    padding: 14px 12px;
  }

  .category-row {
    min-height: 54px;
    padding-right: 16px;
    padding-left: 16px;
  }

  .task-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .task-card {
    min-height: 112px;
  }

  .admin-login-body {
    max-width: 520px;
  }

  .admin-menu-grid {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }
}

@media (min-width: 980px) {
  .top-bar {
    padding-right: max(24px, calc((100vw - var(--wide-content-max)) / 2 + 24px));
    padding-left: max(24px, calc((100vw - var(--wide-content-max)) / 2 + 24px));
  }

  .screen-body {
    width: min(100%, var(--wide-content-max));
    padding-right: 24px;
    padding-left: 24px;
  }

  #homeView .screen-body {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(360px, 1fr);
    align-content: start;
    gap: 18px 24px;
  }

  #homeView .summary-grid {
    grid-column: 1 / -1;
  }

  #homeView .helper-text,
  #homeView .category-panel,
  #homeView .view-tasks-button,
  #homeView .helper-note,
  #homeView .save-note {
    grid-column: 1 / -1;
    width: min(100%, 760px);
    justify-self: center;
  }

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

  .detail-layout {
    width: min(100%, 680px);
  }

  .admin-menu-grid {
    grid-template-columns: repeat(6, minmax(120px, 1fr));
  }
}
