:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --text: #2b2b2b;
  --text-muted: #7a756d;
  --accent: #3d5166;
  --accent-soft: #dde4ea;
  --done: #4f7a63;
  --done-soft: #e2ece5;
  --pending: #c97b63;
  --pending-soft: #f5e6e1;
  --border: #e7e3db;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(30, 30, 30, 0.06);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 17px;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 84px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.topbar-icon {
  font-size: 24px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-badge {
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
}

.admin-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  padding: 6px;
  cursor: pointer;
  line-height: 1;
}

#view-root {
  flex: 1;
  padding: 8px 20px 20px;
}

/* ---- 共通パーツ ---- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.big-button {
  display: block;
  width: 100%;
  border: none;
  border-radius: var(--radius);
  padding: 20px;
  font-size: 19px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
}

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

.text-input {
  width: 100%;
  font-size: 18px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.center-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 70vh;
  gap: 16px;
}

.headline {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 6px;
}

.sub {
  color: var(--text-muted);
  font-size: 15px;
  margin: 0 0 20px;
}

.gate-error {
  color: var(--pending);
  font-size: 14px;
  font-weight: 600;
  margin-top: 4px;
}

/* ---- ログイン画面 ---- */

.user-select-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-select-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- ダッシュボード ---- */

.today-date {
  color: var(--text-muted);
  font-size: 15px;
  margin: 4px 0 18px;
}

.past-hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 14px;
}

.record-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 14px;
}

.record-card.done {
  background: var(--done-soft);
}

.record-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.record-label {
  font-size: 20px;
  font-weight: 700;
}

.record-status {
  font-size: 14px;
  color: var(--text-muted);
}

.record-status.done {
  color: var(--done);
  font-weight: 600;
}

.record-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ---- 在庫管理 ---- */

.inventory-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 12px;
}

.inventory-name {
  font-size: 17px;
  font-weight: 700;
}

.inventory-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.inventory-step-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.inventory-count-input {
  width: 48px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 4px;
  font-size: 16px;
  font-weight: 700;
  background: var(--bg);
  color: var(--text);
}

.inventory-delete-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
  padding: 6px;
  margin-left: 4px;
  cursor: pointer;
}

.inventory-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.inventory-add-row .modal-text-input {
  flex: 1;
}

.inventory-add-row .big-button {
  width: auto;
  flex-shrink: 0;
  padding: 12px 20px;
}

.inventory-add-row .modal-text-input {
  min-width: 0;
}

.inventory-card-gauge {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.inventory-gauge-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.inventory-gauge-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-left: auto;
}

.inventory-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  outline: none;
  background: var(--border);
}

.inventory-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.inventory-slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.inventory-slider::-moz-range-track {
  height: 14px;
  border-radius: 999px;
  background: transparent;
}

.record-delete-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}

.record-action {
  border: none;
  border-radius: 999px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: var(--pending);
  cursor: pointer;
  white-space: nowrap;
}

.record-action.done {
  background: var(--done);
}

/* ---- 選択肢モーダル ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal-box {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
}

.modal-title {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 16px;
  text-align: center;
}

.modal-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.modal-choice-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 14px;
  padding: 16px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.modal-choice-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.modal-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.modal-text-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  margin-bottom: 14px;
  background: var(--bg);
  color: var(--text);
}

.modal-datetime-row {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.modal-date-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 10px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}

.modal-time-select-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.modal-time-select {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

.modal-time-colon {
  font-weight: 700;
  color: var(--text-muted);
}

/* ---- カレンダー ---- */

.admin-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.admin-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.log-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 6px;
  font-size: 13px;
}

.log-kind {
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--accent-soft);
  color: var(--accent);
}

.log-item.log-gate .log-kind {
  background: var(--pending-soft);
  color: var(--pending);
}

.log-item.log-login .log-kind {
  background: var(--done-soft);
  color: var(--done);
}

.log-message {
  flex: 1;
  min-width: 0;
  word-break: break-all;
}

.log-time {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.calendar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

.cal-nav-btn {
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 20px;
}

.calendar-cell {
  aspect-ratio: 1;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  padding: 2px;
}

.calendar-cell.empty {
  background: transparent;
  cursor: default;
}

.calendar-cell.disabled {
  opacity: 0.35;
  cursor: default;
}

.calendar-day-num {
  font-size: 14px;
  font-weight: 600;
}

.calendar-cell.today .calendar-day-num {
  color: var(--accent);
}

.calendar-cell.selected {
  background: var(--accent);
}

.calendar-cell.selected .calendar-day-num {
  color: #fff;
}

.calendar-dots {
  display: flex;
  gap: 3px;
  min-height: 8px;
}

.calendar-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

/* ---- 履歴 ---- */

.history-day {
  margin-bottom: 22px;
}

.history-date {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 8px;
  font-size: 15px;
}

.history-item-type {
  font-weight: 600;
}

.history-item-meta {
  color: var(--text-muted);
  font-size: 13px;
}

.history-item-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.delete-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 6px;
  cursor: pointer;
}

.delete-btn:hover {
  color: var(--pending);
}

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

/* ---- タブバー ---- */

.tabbar[hidden] {
  display: none;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px max(20px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom));
}

.tab-btn {
  flex: 1;
  max-width: 220px;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--accent);
}

.tab-icon {
  font-size: 18px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
  font-size: 15px;
}

.setup-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.setup-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 17px;
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --surface: #2a2a2d;
    --text: #f0efec;
    --text-muted: #a3a09a;
    --accent: #8fb0cf;
    --accent-soft: #33414d;
    --done: #7fbf9c;
    --done-soft: #26362d;
    --pending: #e0947d;
    --pending-soft: #3a2c27;
    --border: #3a3a3d;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  }
  .big-button { color: #1c1c1e; }
  .record-action { color: #1c1c1e; }
}
