:root {
  --bg: #f5f7f3;
  --paper: #ffffff;
  --paper-soft: #fbfaf6;
  --ink: #17231e;
  --muted: #65716c;
  --line: #dce3dc;
  --green: #164234;
  --mint: #e7f1ea;
  --orange: #d9833e;
  --orange-soft: #fff1e5;
  --blue: #2f5f87;
  --blue-soft: #e7eff6;
  --danger: #b54737;
  --danger-soft: #fff0ed;
  --shadow: 0 18px 42px rgba(25, 42, 34, .08);
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

*,
*::before,
*::after {
  max-width: 100%;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
  overflow-x: hidden;
}

html.modal-open,
body.modal-open {
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  max-width: 100vw;
  min-height: 100%;
  background: linear-gradient(180deg, rgba(22, 66, 52, .08), transparent 260px), var(--bg);
  overflow-x: clip;
  width: 100%;
}

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

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

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

input:focus, select:focus, textarea:focus {
  border-color: rgba(22, 66, 52, .65);
  box-shadow: 0 0 0 3px rgba(22, 66, 52, .12);
}

textarea {
  min-height: 230px;
  resize: vertical;
  line-height: 1.72;
}

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

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 7px;
  font-size: 27px;
  line-height: 1.22;
}

h3 { margin-bottom: 0; }

.app {
  min-height: 100vh;
  padding-top: 77px;
  overflow-x: hidden;
}

.topbar {
  position: fixed;
  z-index: 110;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 46px;
  gap: 12px;
  align-items: center;
  min-height: 76px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 250, 246, .92);
  backdrop-filter: blur(14px);
}

.menu-button,
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--mint);
  color: var(--green);
  font-weight: 900;
}

.menu-button {
  grid-column: 3;
  grid-row: 1;
}

.brand-lockup {
  grid-column: 1;
  grid-row: 1;
}

.brand-home-button {
  width: fit-content;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.sync-state {
  grid-column: 2;
  grid-row: 1;
}

.menu-button span {
  display: block;
  width: 19px;
  height: 2px;
  margin: 2px 0;
  border-radius: 99px;
  background: var(--green);
}

.brand-lockup {
  display: flex;
  gap: 11px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: #f2c84b;
  color: #17312a;
  font-weight: 900;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--green);
  font-size: 12px;
  font-weight: 850;
}

.sync-state {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.drawer {
  position: fixed;
  z-index: 140;
  top: 0;
  left: 0;
  width: min(340px, calc(100vw - 24px));
  height: 100vh;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--paper-soft);
  box-shadow: 28px 0 55px rgba(12, 25, 18, .18);
  transform: translateX(-105%);
  transition: transform .18s ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  z-index: 135;
  inset: 0;
  background: rgba(11, 25, 18, .32);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
}

.drawer-head h2 {
  margin: 0;
  font-size: 22px;
}

.drawer-nav {
  display: grid;
  gap: 8px;
}

.drawer-link {
  min-height: 48px;
  border-radius: var(--radius);
  padding: 0 14px;
  background: transparent;
  text-align: left;
  font-weight: 900;
}

.drawer-link:hover,
.drawer-link.active {
  background: #fff;
  box-shadow: inset 4px 0 0 var(--orange);
}

.drawer-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 18px;
}

.drawer-summary div,
.stat-card {
  min-height: 68px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.drawer-summary strong,
.stat-card strong {
  display: block;
  font-size: 23px;
  line-height: 1;
}

.drawer-summary span,
.stat-card span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.main {
  width: 100%;
  max-width: 1220px;
  margin: 0 auto;
  padding: 24px;
  overflow-x: hidden;
}

.view {
  display: none;
  min-width: 0;
}
.view.active { display: block; }

.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(300px, .82fr);
  gap: 16px;
  align-items: start;
}

.quick-memo-panel,
.mini-panel,
.settings-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.quick-memo-panel {
  padding: 18px;
}

.mini-panel,
.settings-panel {
  padding: 16px;
}

.home-side {
  display: grid;
  gap: 14px;
}

.section-heading,
.page-head,
.image-heading,
.steps-heading,
.accordion-action-row {
  min-width: 0;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.section-heading {
  margin-bottom: 14px;
}

.section-heading.compact {
  margin-bottom: 10px;
}

.section-heading.compact h2 {
  margin: 0;
  font-size: 19px;
}

.page-head {
  margin-bottom: 16px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.page-head p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.65;
}

.quick-form {
  display: grid;
  gap: 11px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.form-row.two {
  grid-template-columns: minmax(0, 1fr) minmax(180px, .38fr);
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

select,
.title-input,
.tag-input,
textarea,
.modal input,
.modal textarea,
.toolbar input,
.toolbar select,
.settings-panel input,
.category-editor input,
.category-editor textarea,
.company-inline-editor input,
.company-inline-editor textarea {
  min-height: 44px;
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 15px;
}

.title-input {
  font-size: 20px;
  font-weight: 900;
}

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

.primary-button,
.outline-button,
.soft-button,
.danger-button,
.add-wide-button,
.file-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  padding: 0 14px;
  font-weight: 900;
  text-decoration: none;
}

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

.outline-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--green);
}

.soft-button {
  background: var(--mint);
  color: var(--green);
}

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

.inline-add {
  min-width: 102px;
}

.company-action-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: end;
}

.toggle-line {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  margin-top: 6px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-weight: 850;
}

.toggle-line input {
  width: 18px;
  height: 18px;
  accent-color: var(--orange);
}

.steps-area,
.image-area {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-soft);
}

.steps-heading,
.image-heading {
  margin-bottom: 10px;
}

.steps-heading h3,
.image-heading h3 {
  margin: 0;
  font-size: 16px;
}

.steps-list,
.image-preview-list,
.recent-list,
.accordion-list,
.category-editor-list,
.company-board {
  display: grid;
  gap: 9px;
}

.step-row {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  gap: 8px;
  align-items: center;
}

.step-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  justify-self: center;
  accent-color: var(--green);
}

.step-row input[type="text"] {
  min-height: 40px;
  margin-top: 0;
  padding: 0 10px;
}

.step-row.done input[type="text"] {
  color: var(--muted);
  text-decoration: line-through;
}

.step-delete,
.thumb-remove {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 900;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.image-preview-list {
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
}

.image-thumb {
  position: relative;
  overflow: hidden;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.image-thumb img {
  display: block;
  width: 100%;
  height: 86px;
  object-fit: cover;
}

.thumb-remove {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 28px;
  height: 28px;
}

.composer-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: stretch;
}

.composer-actions.editing {
  grid-template-columns: 1fr 1fr;
}

.composer-actions button {
  width: 100%;
  min-width: 0;
  white-space: nowrap;
}

.save-button {
  min-width: 0;
}

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

.category-card,
.note-accordion,
.company-card,
.company-category-card,
.company-name-card,
.category-editor {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

details summary {
  list-style: none;
}

details summary::-webkit-details-marker {
  display: none;
}

.category-summary,
.note-summary,
.company-summary {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 13px;
  cursor: pointer;
}

.category-color,
.company-color {
  width: 10px;
  min-height: 44px;
  border-radius: 99px;
  background: var(--green);
}

.summary-title {
  display: block;
  font-weight: 950;
  overflow-wrap: anywhere;
}

.summary-sub {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.count-pill,
.type-pill,
.tag-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 99px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 900;
}

.count-pill {
  background: var(--mint);
  color: var(--green);
}

.type-pill {
  background: var(--blue-soft);
  color: var(--blue);
}

.tag-pill {
  background: var(--orange-soft);
  color: #92501f;
}

.accordion-body {
  min-width: 0;
  padding: 0 13px 13px 33px;
  color: #4c5a54;
  line-height: 1.7;
}

.accordion-body p {
  margin-bottom: 10px;
}

.accordion-body pre {
  overflow: hidden;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0 0 10px;
  color: var(--ink);
  font: inherit;
}

.accordion-action-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 10px;
}

.mini-note-button,
.recent-item {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 11px;
  border-radius: var(--radius);
  background: var(--paper-soft);
  text-align: left;
  min-width: 0;
}

.recent-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 900;
}

.recent-meta,
.note-meta-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.note-body-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 260px);
  gap: 9px;
  margin-bottom: 10px;
}

.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 4px;
}

.filter-chip {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: #fff;
  padding: 0 12px;
  color: var(--muted);
  font-weight: 900;
}

.filter-chip.active {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.note-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  margin: 10px 0;
}

.note-images img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  object-fit: cover;
}

.company-list-only,
.company-detail-panel {
  display: grid;
  gap: 10px;
}

.company-name-card {
  display: grid;
  gap: 9px;
  padding: 11px;
}

.company-open-button {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  align-items: center;
  padding: 0;
  background: transparent;
  text-align: left;
}

.company-name-actions,
.company-detail-head {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.company-detail-head {
  justify-content: space-between;
}

.static-summary {
  cursor: default;
}

.company-detail-memo {
  margin: -4px 13px 13px 33px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.company-card details + details {
  border-top: 1px solid var(--line);
}

.company-inline-editor,
.category-editor {
  display: grid;
  gap: 9px;
  padding: 13px;
}

.category-editor {
  grid-template-columns: 10px minmax(140px, .8fr) minmax(180px, 1.1fr) 120px 170px;
  align-items: center;
}

.category-editor input,
.category-editor textarea {
  margin-top: 0;
}

.category-editor textarea {
  min-height: 44px;
}

.add-wide-button {
  width: 100%;
  margin-top: 10px;
  border: 1px dashed rgba(22, 66, 52, .45);
  background: var(--mint);
  color: var(--green);
}

.settings-panel + .settings-panel {
  margin-top: 14px;
}

.settings-panel p {
  color: var(--muted);
  line-height: 1.65;
}

.settings-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.modal {
  width: min(540px, calc(100dvw - 20px));
  max-width: calc(100dvw - 20px);
  max-height: calc(100dvh - 20px);
  margin: 0;
  padding: 16px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 22px 70px rgba(0, 0, 0, .18);
}

.modal[open] {
  position: fixed;
  z-index: 220;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  right: auto;
  bottom: auto;
  transform: translateX(-50%);
}

.modal::backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 25, 18, .34);
}

.modal form {
  display: grid;
  gap: 11px;
  min-width: 0;
  padding: 0;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}

.note-viewer {
  width: min(720px, calc(100dvw - 16px));
  max-height: calc(100dvh - 20px);
  padding: 0;
  overflow: hidden;
}

.note-viewer-panel {
  display: grid;
  gap: 12px;
  max-height: calc(100dvh - 26px);
  overflow: auto;
  padding: 16px;
}

.viewer-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.viewer-head h3 {
  margin-bottom: 0;
  overflow-wrap: anywhere;
  line-height: 1.38;
}

.viewer-meta {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.45;
}

.viewer-body {
  max-width: 100%;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-soft);
  color: var(--ink);
  font: inherit;
  line-height: 1.78;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
}

.action-dialog {
  width: min(430px, calc(100dvw - 20px));
}

.action-dialog p {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.viewer-steps:empty,
.viewer-tags:empty {
  display: none;
}

.color-row {
  display: flex;
  gap: 10px;
}

.color-row label {
  cursor: pointer;
}

.color-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.color-row span {
  display: block;
  width: 34px;
  height: 34px;
  border: 3px solid #fff;
  border-radius: 99px;
  background: var(--swatch);
  box-shadow: 0 0 0 1px var(--line);
}

.color-row input:checked + span {
  box-shadow: 0 0 0 3px rgba(22, 66, 52, .25);
}

.empty-state {
  padding: 28px 16px;
  color: var(--muted);
  line-height: 1.7;
  text-align: center;
}

.hold-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.danger-hold {
  box-shadow: inset 0 0 0 2px rgba(181, 71, 55, .35);
}

@media (max-width: 980px) {
  .home-grid {
    grid-template-columns: 1fr;
  }

  .category-editor {
    grid-template-columns: 10px 1fr;
  }

  .category-editor textarea,
  .category-editor select,
  .category-editor .accordion-action-row {
    grid-column: 2;
  }
}

@media (max-width: 680px) {
  .app {
    padding-top: 101px;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) 42px;
    padding: 12px 14px;
  }

  .brand-lockup {
    grid-column: 1;
  }

  .menu-button {
    grid-column: 2;
  }

  .sync-state {
    grid-column: 1 / -1;
    grid-row: 2;
    padding-left: 0;
  }

  .main {
    padding: 14px 10px;
  }

  .quick-memo-panel,
  .mini-panel,
  .page-head,
  .settings-panel {
    padding: 14px;
  }

  h2 {
    font-size: 23px;
  }

  .page-head,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .form-row,
  .form-row.two,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .inline-add,
  .save-button {
    width: 100%;
  }

  .settings-actions,
  .modal-actions {
    justify-content: stretch;
  }

  .settings-actions > *,
  .modal-actions button {
    flex: 1 1 auto;
    min-width: 0;
  }

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

  .company-name-actions,
  .company-detail-head {
    justify-content: stretch;
  }

  .company-name-actions button,
  .company-detail-head button {
    flex: 1 1 auto;
  }

  .note-viewer {
    width: calc(100dvw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .note-viewer-panel {
    padding: 12px;
    max-height: calc(100dvh - 12px);
  }

  .viewer-head {
    grid-template-columns: 1fr;
  }

  textarea {
    min-height: 210px;
  }

  input,
  select,
  textarea,
  button {
    font-size: 16px;
  }

  .modal {
    width: calc(100dvw - 16px);
    max-width: calc(100dvw - 16px);
    max-height: calc(100dvh - 16px);
    padding: 12px;
  }

  .accordion-body {
    padding-left: 13px;
  }

  .category-summary,
  .note-summary,
  .company-summary,
  .company-open-button {
    grid-template-columns: 10px minmax(0, 1fr) 34px;
  }

  .count-pill {
    justify-self: end;
    padding: 0 7px;
  }
}
