:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --ink: #18202f;
  --muted: #667085;
  --line: #dde3ec;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-rgb: 15, 118, 110;
  --accent-soft-rgb: 245, 158, 11;
  --warm: #f59e0b;
  --danger: #c2410c;
  --shadow: 0 18px 45px rgba(24, 32, 47, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(var(--accent-rgb), 0.12), transparent 34%),
    linear-gradient(225deg, rgba(var(--accent-soft-rgb), 0.14), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.settings {
  position: relative;
  flex: 0 0 auto;
}

.settings-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 84px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 850;
  box-shadow: 0 10px 24px rgba(24, 32, 47, 0.08);
}

.settings-button:hover,
.settings-button.active {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.08);
}

.settings-panel {
  position: absolute;
  top: 52px;
  right: 0;
  z-index: 20;
  display: none;
  width: min(300px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.settings-panel.open {
  display: block;
}

.settings-panel h2 {
  margin: 14px 0 12px;
  font-size: 0.95rem;
}

.settings-panel h2:first-child {
  margin-top: 0;
}

.settings-fields {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

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

.palette-button {
  display: grid;
  gap: 7px;
  min-height: 72px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
}

.palette-button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.14);
}

.palette-swatch {
  display: block;
  height: 24px;
  border-radius: 6px;
}

.top-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 20px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.tab-button {
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 850;
}

.tab-button.active {
  background: var(--accent);
  color: #ffffff;
}

.tab-panel,
.month-view {
  display: none;
}

.tab-panel.active,
.month-view.active {
  display: block;
}

.summary {
  display: grid;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: clamp(2rem, 4vw, 4rem);
}

.month-title {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  font-weight: 850;
}

h2 {
  font-size: 1.1rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr 0.8fr;
  gap: 12px;
}

.metric,
.panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(221, 227, 236, 0.85);
  box-shadow: var(--shadow);
}

.metric {
  min-width: 0;
  border-radius: 8px;
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.metric.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: transparent;
}

.metric.primary span {
  color: rgba(255, 255, 255, 0.82);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(300px, 0.75fr);
  gap: 20px;
}

.annual {
  margin-top: 20px;
}

.panel {
  border-radius: 8px;
  padding: 22px;
}

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

.panel-head.compact {
  margin: 22px 0 12px;
}

.annual-head {
  align-items: end;
}

.panel-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.ghost-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.ghost-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.detail-button {
  width: 100%;
  min-height: 48px;
  margin-top: 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-weight: 850;
}

.detail-button:hover {
  background: var(--accent-dark);
}

.add-row-button {
  margin-top: 12px;
}

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

.compact-grid {
  max-width: 640px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  min-height: 1.3em;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.field small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.field input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfe;
  color: var(--ink);
  outline: none;
}

.field select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcfe;
  color: var(--ink);
  outline: none;
}

.date-combo {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.85fr) minmax(0, 0.85fr);
  gap: 8px;
}

.date-combo[data-month-picker] {
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.78fr);
}

.field input[readonly] {
  background: #eef3f7;
  color: var(--accent-dark);
  font-weight: 800;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.14);
}

.year-field {
  width: min(180px, 100%);
}

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

.month-table-wrap {
  margin-top: 16px;
  overflow-x: auto;
}

.month-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

.month-table th,
.month-table td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.month-table th:first-child,
.month-table td:first-child {
  text-align: left;
}

.month-table th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.month-table td {
  font-weight: 750;
}

.month-table .empty {
  color: var(--muted);
  font-weight: 650;
}

.month-link {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 800;
}

.month-link:hover {
  border-color: var(--accent);
}

.shift-editor {
  margin-top: 4px;
}

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

.shift-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.fixed-cost-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

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

.fixed-cost-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 0.6fr) 40px;
  gap: 8px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.paid-use-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(110px, 0.4fr) 40px;
  gap: 8px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.shift-row .field span {
  font-size: 0.78rem;
}

.fixed-cost-row .field span {
  font-size: 0.78rem;
}

.paid-use-row .field span {
  font-size: 0.78rem;
}

.shift-times {
  align-self: center;
  color: var(--muted);
  font-weight: 850;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

.icon-button:hover {
  border-color: rgba(194, 65, 12, 0.4);
  background: rgba(194, 65, 12, 0.06);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.status.warning {
  background: rgba(245, 158, 11, 0.14);
  color: #92400e;
}

.status.danger {
  background: rgba(194, 65, 12, 0.12);
  color: var(--danger);
}

.paid-breakdown {
  max-width: 640px;
  margin-top: 18px;
}

.breakdown {
  display: grid;
  gap: 10px;
  margin: 0;
}

.breakdown div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

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

.breakdown dt {
  color: var(--muted);
  font-weight: 700;
}

.breakdown dd {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 850;
  text-align: right;
  overflow-wrap: anywhere;
}

@media (max-width: 840px) {
  .summary,
  .workspace,
  .summary-grid,
  .annual-grid {
    grid-template-columns: 1fr;
  }

  .annual-head {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 20px, 1120px);
    padding: 20px 0;
  }

  .panel,
  .metric {
    padding: 16px;
  }

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

  .top-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    padding: 0;
    overflow: hidden;
    border-color: rgba(102, 112, 133, 0.28);
    background: #ffffff;
  }

  .tab-button {
    min-height: 58px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: #ffffff;
  }

  .tab-button:nth-child(2n) {
    border-right: 0;
  }

  .tab-button:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .tab-button.active {
    border-color: rgba(var(--accent-rgb), 0.24);
    background: var(--accent);
  }

  .month-table-wrap {
    overflow-x: hidden;
  }

  .month-table {
    min-width: 0;
    table-layout: fixed;
  }

  .month-table th,
  .month-table td {
    padding: 12px 4px;
    font-size: 0.74rem;
    line-height: 1.25;
  }

  .month-table th:nth-child(1),
  .month-table td:nth-child(1) {
    width: 12%;
  }

  .month-table th:nth-child(2),
  .month-table td:nth-child(2),
  .month-table th:nth-child(3),
  .month-table td:nth-child(3) {
    width: 29%;
  }

  .month-table th:nth-child(4),
  .month-table td:nth-child(4) {
    width: 18%;
  }

  .month-table th:nth-child(5),
  .month-table td:nth-child(5) {
    width: 12%;
    padding-right: 0;
  }

  .month-link {
    min-height: 30px;
    width: 32px;
    padding: 0;
    font-size: 0;
  }

  .month-link::after {
    content: "開";
    font-size: 0.72rem;
  }

  .app-header {
    align-items: flex-start;
  }

  .shift-row {
    grid-template-columns: 1fr 24px 1fr 40px;
  }

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

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

  .date-combo,
  .date-combo[data-month-picker] {
    grid-template-columns: 1fr;
  }

  .fixed-cost-row .icon-button {
    width: 100%;
  }

  .paid-use-row .icon-button {
    width: 100%;
  }
}
