@import url("https://fonts.googleapis.com/css2?family=Kiwi+Maru:wght@400;500&display=swap");

:root {
  --ink: #151515;
  --muted: #646464;
  --line: #151515;
  --paper: #ffffff;
  --panel: #fbfaf7;
  --accent: #8eb1d1;
  --accent-dark: #1c2b48;
  --accent-soft: #edf5fb;
  --danger: #de6e74;
  --shadow: 5px 5px 0 #151515;
  --soft-shadow: 3px 3px 0 #151515;
  --ui-font: "Kiwi Maru", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  --body-font: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--body-font);
  font-size: 15px;
  line-height: 1.5;
}

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

.app-shell {
  width: min(1220px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 18px 96px;
}

.hero {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0 12px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--ink);
}

.hero h1, .section-head h2, .panel h3 { margin: 0; }
.hero h1 {
  font-family: var(--ui-font);
  font-size: 28px;
  letter-spacing: 0;
}
.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  font-family: var(--ui-font);
}

.sync-pill, .primary, .ghost, .danger {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  padding: 0 15px;
  font-weight: 900;
  font-family: var(--ui-font);
}

.sync-pill {
  background: var(--ink);
  color: white;
  box-shadow: var(--soft-shadow);
}

.primary {
  background: var(--ink);
  color: white;
  box-shadow: none;
}

.ghost {
  background: white;
  color: var(--ink);
  border: 2px solid var(--line);
}

.danger {
  background: #f8dcdf;
  color: #8b232a;
  border: 2px solid #8b232a;
}

.tabbar {
  position: sticky;
  top: 74px;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  margin: 0 0 12px;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.tabbar button {
  min-height: 42px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
  font-family: var(--ui-font);
}

.tabbar button.active {
  background: var(--ink);
  color: white;
}

.view { display: none; }
.view.active { display: block; }

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 12px;
}

.section-head > div {
  min-width: max-content;
}

.section-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.section-head > .section-actions {
  min-width: 0;
}

.section-head h2,
.composer summary,
.panel h3 {
  font-family: var(--ui-font);
}

.section-head select, .section-head input, input, select, textarea {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

.section-head select {
  width: 180px;
  min-width: 160px;
}

.section-head .search {
  width: min(360px, 42vw);
}

textarea {
  min-height: 82px;
  resize: vertical;
}

.search { max-width: 320px; }

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.metric {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  box-shadow: var(--shadow);
}

.metric span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
  font-family: var(--ui-font);
}

.metric b {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.notice {
  margin: 8px 0 12px;
  border: 2px dashed var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.sync-panel {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--soft-shadow);
  margin: 12px 0;
  padding: 12px;
}

.sync-panel summary {
  cursor: pointer;
  font-family: var(--ui-font);
  font-weight: 900;
}

.sync-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-top: 12px;
}

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

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

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

.activity-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  box-shadow: var(--soft-shadow);
}

.activity-row.done {
  opacity: .66;
}

.activity-main {
  min-width: 0;
}

.activity-title {
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
}

.activity-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.activity-tools,
.activity-actions,
.activity-edit-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.activity-tools {
  margin-top: 8px;
  flex-wrap: wrap;
}

.activity-done {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  grid-template-columns: none;
  gap: 7px;
  min-height: 42px;
  min-width: 84px;
  border: 2px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
}

.activity-done input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-dark);
}

.activity-edit-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  border-top: 2px solid var(--line);
  padding-top: 12px;
}

.activity-edit-actions {
  justify-content: flex-start;
}

.work-card, .panel, .composer {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.work-card {
  overflow: hidden;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 15px;
  background: var(--ink);
  border-bottom: 2px solid var(--line);
}

.card-top > div {
  min-width: 0;
}

.client {
  font-size: 18px;
  font-weight: 900;
  color: #fff;
}

.content {
  color: rgba(255,255,255,.74);
  font-size: 13px;
  font-weight: 800;
}

.pill, .pay-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 32px;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  border: 2px solid var(--ink);
  font-family: var(--ui-font);
  padding: 3px 8px;
  gap: 4px;
  white-space: nowrap;
}

.pay-check {
  flex: 0 0 auto;
  min-width: 94px;
}

.pill input, .pay-check input {
  width: 17px;
  height: 17px;
}

.card-top .pill,
.card-top .pay-check {
  border-color: #fff;
  background: #fff;
  color: var(--ink);
}

.pill.ok,
.pay-check.ok {
  background: var(--accent-soft);
  color: var(--ink);
}

.dates {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 15px 0;
}

.datebox {
  border: 2px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: white;
}

.datebox span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  font-family: var(--ui-font);
}

.datebox b {
  display: block;
  margin-top: 2px;
  font-size: 17px;
}

.details {
  display: grid;
  gap: 5px;
  padding: 12px 15px 0;
  color: var(--muted);
  font-size: 15px;
}

.details a {
  color: #246b99;
  font-weight: 900;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.stages {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 15px;
}

.stage {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--line);
  border-radius: 7px;
  background: white;
  padding: 9px 10px;
  font-weight: 900;
  font-size: 15px;
}

.stage input[type="checkbox"], .check-field input[type="checkbox"] {
  width: 19px;
  height: 19px;
  accent-color: var(--accent-dark);
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 15px 15px;
}

.composer {
  padding: 14px;
  margin-bottom: 12px;
}

.composer summary {
  cursor: pointer;
  font-weight: 900;
  font-size: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  font-family: var(--body-font);
}

.wide { grid-column: 1 / -1; }

.work-board {
  display: grid;
  gap: 14px;
}

.check-field {
  position: relative;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border: 2px dashed var(--line);
  border-radius: 7px;
  padding: 12px;
}

#stagePicker {
  padding-bottom: 54px;
}

.check-field legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  font-family: var(--ui-font);
}

.check-field label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 7px;
  background: white;
  padding: 8px 10px;
  color: var(--ink);
}

.check-field .format-other {
  flex: 1 1 190px;
  align-items: stretch;
}

.hidden { display: none !important; }

.stage-edit-toggle {
  position: absolute;
  top: auto;
  bottom: 10px;
  right: 8px;
}

.stage-editor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  padding-top: 6px;
}

.stage-editor label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.inline-add {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  grid-column: 1 / -1;
  align-items: center;
}

.stage-add-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.inline-add input {
  min-width: 0;
}

.tools, .inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.tools {
  align-items: center;
  justify-content: space-between;
}

.search-sort {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 1fr);
  gap: 8px;
  flex: 1 1 420px;
}

.filter-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex: 1 0 auto;
}

.searchbox {
  position: relative;
  display: block;
  color: var(--ink);
}

.searchbox span {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 20px;
  font-weight: 900;
}

.searchbox input {
  padding-left: 38px;
}

.filter-check {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 10px;
  border: 2px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
}

.filter-check input {
  width: 18px;
  height: 18px;
}

.inline-form input { flex: 1 1 180px; }
.inline-form select { width: auto; }

.asset-top {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 2fr);
  gap: 12px;
  margin: 12px 0;
}

.tax-panel {
  min-height: 260px;
}

.tax-toggle {
  width: fit-content;
  margin: 16px 0 10px;
}

.tax-list {
  display: grid;
  gap: 8px;
}

.empty {
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 26px;
  text-align: center;
  color: var(--muted);
  background: #fff;
  font-weight: 900;
}

#salesChart {
  width: 100%;
  height: auto;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.panel {
  padding: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.mini {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.edit-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0 15px 15px;
}

.edit-panel .check-field input[type="text"],
.edit-panel .check-field input[type="date"] {
  flex: 1 1 150px;
}

.mini-form, .mini-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.mini-item {
  border: 2px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: white;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  display: none;
  z-index: 20;
  max-width: calc(100% - 28px);
  border-radius: 8px;
  background: var(--ink);
  color: white;
  padding: 10px 16px;
  font-weight: 900;
  box-shadow: var(--shadow);
}

@media (min-width: 920px) {
  .app-shell {
    padding-left: 226px;
    padding-bottom: 28px;
  }

  .tabbar {
    left: max(18px, calc((100vw - 1220px) / 2 + 18px));
    top: 88px;
    bottom: auto;
    width: 176px;
    position: fixed;
    grid-template-columns: 1fr;
    border-radius: 7px;
    box-shadow: 4px 4px 0 #151515;
  }

  .tabbar button {
    text-align: left;
    min-height: 58px;
    padding-left: 18px;
    font-size: 17px;
  }

  .work-board {
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    align-items: start;
  }

  .composer {
    position: sticky;
    top: 88px;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

@media (max-width: 720px) {
  .app-shell { padding: 10px 10px calc(112px + env(safe-area-inset-bottom)); }
  .hero h1 { font-size: 24px; }
  .section-head h2 { font-size: 22px; }
  .metric-row, .form-grid, .ledger-grid, .asset-top, .search-sort { grid-template-columns: 1fr; }
  .dates { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .datebox { padding: 7px 5px; }
  .datebox b { font-size: 13px; }
  .stages { grid-template-columns: 1fr; }
  .tabbar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    top: auto;
    width: auto;
    z-index: 30;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    margin: 0;
    padding: 6px;
    border-radius: 8px;
    box-shadow: 4px 4px 0 #151515;
  }
  .tabbar button {
    min-height: 54px;
    padding: 0 2px;
    font-size: 13px;
    line-height: 1.12;
  }
  .stage-editor, .edit-panel { grid-template-columns: 1fr; }
  .filter-row { justify-content: flex-start; flex-wrap: wrap; }
  .search { max-width: none; }
  .section-head { align-items: stretch; flex-direction: column; }
  .section-head > div { min-width: 0; }
  .section-actions { width: 100%; justify-content: stretch; }
  .section-actions select { flex: 1 1 auto; min-width: 0; }
  .section-head select,
  .section-head .search { width: 100%; }
  .activity-row {
    align-items: stretch;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px;
  }
  .activity-title { font-size: 16px; }
  .activity-meta { font-size: 12px; }
  .activity-tools { gap: 6px; }
  .activity-edit-panel { grid-template-columns: 1fr; }
}
