:root {
  color-scheme: light;
  --bg: #f4f2ed;
  --surface: #fffefa;
  --surface-muted: #ebe8df;
  --ink: #20251f;
  --muted: #697068;
  --line: #d9d7ce;
  --brand: #163d2b;
  --brand-soft: #dbe9df;
  --danger: #a33b32;
  --high: #b84c3d;
  --medium: #a67724;
  --low: #668070;
  font-family: "Yu Gothic UI", "Hiragino Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(22, 61, 43, 0.08), transparent 28rem),
    var(--bg);
}

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

button {
  cursor: pointer;
}

.app-header,
main {
  width: min(100%, 920px);
  margin-inline: auto;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 18px 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.15em;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 7vw, 2.3rem);
  letter-spacing: -0.045em;
}

.task-summary {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.sync-status {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
}

.sync-status.is-online {
  color: var(--brand);
}

.sync-status.is-error {
  color: var(--danger);
}

.icon-button,
.close-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  min-width: 54px;
  padding: 10px 13px;
  font-size: 0.78rem;
  font-weight: 800;
}

main {
  padding: 0 14px 110px;
}

.entity-search-section {
  position: sticky;
  z-index: 5;
  top: 0;
  padding: 10px 0 6px;
  background: linear-gradient(var(--bg) 78%, transparent);
}

.entity-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.entity-search {
  position: relative;
  flex: 1;
  min-width: 0;
}

.entity-search::before {
  position: absolute;
  top: 50%;
  left: 13px;
  content: "⌕";
  transform: translateY(-52%);
  color: var(--muted);
  font-size: 1.25rem;
}

.entity-search input {
  border-radius: 999px;
  padding-left: 38px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(33, 40, 33, 0.04);
}

.entity-search-row .icon-button {
  flex: none;
  min-width: 0;
  padding-inline: 11px;
  white-space: nowrap;
}

.selected-scope {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 27px;
  padding: 6px 5px 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.selected-scope strong {
  color: var(--ink);
  font-size: 0.8rem;
}

.selected-scope small {
  margin-left: auto;
}

.scope-label {
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 900;
}

.entity-search-results {
  position: absolute;
  z-index: 12;
  top: 59px;
  right: 0;
  left: 0;
  max-height: min(420px, 60vh);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 7px;
  background: var(--surface);
  box-shadow: 0 18px 36px rgba(32, 37, 31, 0.16);
}

.entity-search-results button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.entity-search-results button:last-child {
  border-bottom: 0;
}

.entity-search-results button span:first-child {
  display: grid;
  gap: 2px;
}

.entity-search-results strong {
  color: var(--ink);
}

.entity-search-results small {
  color: var(--muted);
  font-size: 0.63rem;
  font-weight: 900;
}

.due-tabs-section {
  margin: 5px 0 14px;
}

.due-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 4px;
  background: var(--surface-muted);
}

.due-tabs button {
  min-width: 0;
  border: 0;
  border-radius: 9px;
  padding: 8px 4px;
  background: transparent;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 900;
  white-space: nowrap;
}

.due-tabs button.is-active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(22, 61, 43, 0.18);
}

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

.status-filter {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
}

.status-filter button {
  border: 0;
  border-radius: 9px;
  padding: 7px 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.status-filter button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 5px rgba(32, 37, 31, 0.1);
}

.sort-control {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
}

.sort-control select {
  max-width: 108px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.section-heading,
.subsection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-heading {
  margin: 0 4px 10px;
}

.section-heading h2,
.subsection-heading h3 {
  margin: 0;
}

.section-heading h2 {
  font-size: 0.92rem;
}

.count-badge {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

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

.client-task-group {
  display: grid;
  gap: 8px;
}

.client-task-group-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 0 4px 7px;
}

.client-task-group-header div {
  display: grid;
  gap: 1px;
}

.client-task-group-header small,
.client-task-group-header > span {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
}

.client-task-group-header h3 {
  margin: 0;
  font-size: 0.98rem;
}

.client-task-group-list {
  display: grid;
  gap: 9px;
}

.task-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 7px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 13px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(33, 40, 33, 0.035);
}

.completion-button {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-top: 1px;
  border: 2px solid #aeb6ad;
  border-radius: 8px;
  background: #fff;
  color: #fff;
  font-weight: 900;
}

.task-card.is-completed .completion-button {
  border-color: var(--brand);
  background: var(--brand);
}

.task-content {
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.task-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.task-title-row h3 {
  margin: 1px 0 0;
  font-size: 0.98rem;
  line-height: 1.45;
}

.task-card.is-completed h3 {
  color: var(--muted);
  text-decoration: line-through;
}

.priority-badge {
  flex: none;
  min-width: 25px;
  border-radius: 7px;
  padding: 3px 6px;
  color: #fff;
  font-size: 0.66rem;
  font-weight: 900;
  text-align: center;
}

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

.priority-medium {
  background: var(--medium);
}

.priority-low {
  background: var(--low);
}

.task-description {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.work-status {
  border-radius: 999px;
  padding: 2px 7px;
  background: var(--surface-muted);
  color: var(--muted);
}

.work-status-in_progress {
  background: var(--brand-soft);
  color: var(--brand);
}

.work-status-waiting {
  background: #f5ead1;
  color: #806020;
}

.due-date::before {
  content: "期限 ";
  font-weight: 500;
}

.due-date.is-overdue {
  color: var(--danger);
}

.due-date.is-soon {
  color: var(--medium);
}

.empty-state {
  border: 1px dashed #c8c7bf;
  border-radius: 16px;
  padding: 42px 24px;
  color: var(--muted);
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 900;
}

.empty-state h3 {
  margin: 0;
  color: var(--ink);
  font-size: 0.95rem;
}

.empty-state p {
  margin: 6px 0 0;
  font-size: 0.78rem;
}

.add-task-button {
  position: fixed;
  z-index: 10;
  right: max(18px, calc((100vw - 920px) / 2 + 18px));
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  padding: 13px 18px;
  background: var(--brand);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 900;
  box-shadow: 0 10px 28px rgba(22, 61, 43, 0.26);
}

.app-dialog {
  width: min(calc(100% - 22px), 610px);
  max-height: calc(100vh - 24px);
  border: 0;
  border-radius: 20px;
  padding: 0;
  background: transparent;
}

.app-dialog::backdrop {
  background: rgba(20, 26, 22, 0.55);
  backdrop-filter: blur(3px);
}

.dialog-card {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 19px;
  background: var(--surface);
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 3px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.close-button {
  width: 35px;
  height: 35px;
  font-size: 1.25rem;
}

.dialog-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
}

.task-project-search-field {
  position: relative;
}

.task-project-search-field > input[type="search"] {
  padding-left: 34px;
}

.task-project-search-field::before {
  position: absolute;
  z-index: 1;
  top: 32px;
  left: 12px;
  content: "⌕";
  color: var(--muted);
  font-size: 1.15rem;
}

.task-project-selection {
  display: flex;
  align-items: center;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 11px;
  background: var(--surface-muted);
}

.task-project-selection span {
  display: grid;
  gap: 2px;
}

.task-project-selection small {
  color: var(--muted);
  font-size: 0.62rem;
}

.task-project-selection strong {
  color: var(--ink);
  font-size: 0.78rem;
}

.task-project-results {
  position: absolute;
  z-index: 16;
  top: 69px;
  right: 0;
  left: 0;
  max-height: min(300px, 42vh);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  background: var(--surface);
  box-shadow: 0 14px 30px rgba(32, 37, 31, 0.18);
}

.task-project-results button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.task-project-results button:last-child {
  border-bottom: 0;
}

.task-project-results button.is-selected {
  background: var(--brand-soft);
  color: var(--brand);
}

.task-project-results button span:first-child {
  display: grid;
  gap: 2px;
}

.task-project-results button strong {
  color: var(--ink);
}

.task-project-results button small {
  color: var(--muted);
  font-size: 0.62rem;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  outline: none;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.field-row {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 10px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 5px;
}

.primary-button,
.secondary-button,
.danger-button,
.text-button {
  border-radius: 10px;
  font-weight: 900;
}

.primary-button,
.secondary-button,
.danger-button {
  border: 0;
  padding: 10px 17px;
}

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

.secondary-button {
  background: var(--brand-soft);
  color: var(--brand);
}

.danger-button {
  margin-right: auto;
  background: #f5e5e3;
  color: var(--danger);
}

.text-button {
  border: 0;
  padding: 5px;
  background: transparent;
  color: var(--brand);
  font-size: 0.75rem;
}

[hidden] {
  display: none !important;
}

.client-dialog-card {
  gap: 20px;
}

.wide-dialog {
  width: min(calc(100% - 22px), 820px);
}

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

.client-list-search {
  position: relative;
}

.client-list-search::before {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 13px;
  content: "⌕";
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 1.2rem;
}

.client-list-search input {
  border-radius: 999px;
  padding-left: 38px;
}

.client-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.client-summary > div,
.commission-preview {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  background: var(--brand-soft);
}

.client-summary small,
.commission-preview small,
.commission-preview span {
  color: var(--muted);
  font-size: 0.63rem;
  font-weight: 800;
}

.client-summary strong,
.commission-preview strong {
  color: var(--brand);
  font-size: 0.98rem;
}

.client-tables {
  display: grid;
  gap: 18px;
}

.client-table-section {
  display: grid;
  gap: 7px;
}

.client-table-section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding: 0 3px;
}

.client-table-section-header h3 {
  margin: 0;
  font-size: 0.92rem;
}

.client-table-section-header span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.client-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.client-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: #fff;
}

.client-table th:first-child {
  width: 27%;
}

.client-table th:nth-child(2) {
  width: 33%;
}

.client-table th:nth-child(3) {
  width: 40%;
}

.client-table th,
.client-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  font-size: 0.75rem;
  text-align: left;
  vertical-align: top;
}

.client-table th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.66rem;
}

.client-table tr:last-child td {
  border-bottom: 0;
}

.client-table small {
  color: var(--muted);
  font-size: 0.65rem;
}

.client-cell,
.table-item-list {
  display: grid;
  gap: 5px;
}

.project-table-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px;
  align-items: stretch;
}

.client-name-button,
.table-item-button {
  display: grid;
  gap: 2px;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.client-name-button {
  border: 0;
  padding: 2px 0;
  background: transparent;
}

.relationship-tag {
  width: max-content;
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 0.58rem;
  font-weight: 900;
}

.relationship-prospect {
  background: #f5ead1;
  color: #806020;
}

.relationship-existing {
  background: var(--brand-soft);
  color: var(--brand);
}

.table-item-button strong,
.client-name-button strong {
  overflow-wrap: anywhere;
}

.table-item-button:hover,
.table-item-button:focus-visible {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.task-table-button {
  border-color: #e2ddd2;
  background: #fbfaf6;
}

.project-task-add-button {
  border: 0;
  border-radius: 8px;
  padding: 4px 7px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.6rem;
  font-weight: 900;
  white-space: nowrap;
}

.project-task-add-button:hover,
.project-task-add-button:focus-visible {
  background: var(--brand);
  color: #fff;
}

.inline-add-button {
  width: max-content;
  max-width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 4px 7px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.62rem;
  font-weight: 900;
  text-align: left;
}

.table-empty {
  color: var(--muted);
  font-size: 0.65rem;
}

.project-status {
  flex: none;
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
}

.status-active {
  background: var(--brand-soft);
  color: var(--brand);
}

.status-on-hold {
  background: #f5ead1;
  color: #806020;
}

.status-completed {
  background: #e7e7e7;
}

.status-archived {
  background: #eee6e0;
  color: #7c6256;
}

.management-form {
  display: grid;
  gap: 13px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.subsection-heading h3 {
  font-size: 0.9rem;
}

.search-empty {
  margin: 0;
  padding: 14px;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 86px;
  transform: translate(-50%, 16px);
  min-width: 190px;
  border-radius: 999px;
  padding: 10px 16px;
  background: #20251f;
  color: #fff;
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
}

.toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.login-screen {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at top right, rgba(22, 61, 43, 0.22), transparent 30rem),
    var(--bg);
}

.login-card {
  display: grid;
  gap: 15px;
  width: min(100%, 390px);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 25px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(32, 37, 31, 0.16);
}

.login-card h2,
.login-card p {
  margin: 0;
}

.login-card h2 {
  font-size: 1.65rem;
}

.login-card p:not(.eyebrow, .login-error) {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.65;
}

.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.login-error {
  min-height: 1em;
  color: var(--danger);
  font-size: 0.72rem;
  font-weight: 800;
}

@media (min-width: 680px) {
  .app-header {
    padding: 34px 26px 16px;
  }

  main {
    padding-inline: 22px;
  }

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

@media (max-width: 420px) {
  .toolbar {
    align-items: flex-end;
  }

  .status-filter button {
    padding-inline: 8px;
  }

  .sort-control span {
    display: none;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .due-tabs {
    gap: 2px;
  }

  .due-tabs button {
    padding-inline: 2px;
    font-size: 0.65rem;
  }

  .entity-search-row > .text-button {
    flex: none;
    max-width: 68px;
  }

  .entity-search-row .icon-button {
    padding-inline: 9px;
    font-size: 0.7rem;
  }

  .management-actions > button {
    flex: 1;
    padding-inline: 8px;
    font-size: 0.72rem;
  }

  .client-summary {
    grid-template-columns: 1fr;
  }

  .client-table th,
  .client-table td {
    padding: 7px 4px;
    font-size: 0.65rem;
    white-space: normal;
  }

  .client-name-button,
  .table-item-button {
    padding: 5px;
    font-size: 0.66rem;
  }

  .project-table-item {
    grid-template-columns: 1fr;
  }

  .project-task-add-button {
    padding: 4px;
    font-size: 0.57rem;
  }

  .client-name-button {
    padding-inline: 0;
  }

  .inline-add-button {
    padding-inline: 5px;
    font-size: 0.58rem;
  }
}
