:root {
  --bg: #f3f5ee;
  --panel: #fffdf6;
  --ink: #1f2a1f;
  --muted: #5f695f;
  --accent: #2c7b5f;
  --accent-strong: #1b5d47;
  --danger: #a23535;
  --line: #d7ddd0;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #dde8d6 0%, transparent 35%),
    radial-gradient(circle at 90% 100%, #f5e9d8 0%, transparent 45%),
    var(--bg);
}

.app {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 18px;
}

.header h1 {
  margin: 0;
  font-size: 2rem;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
}

.profile.profile-manage-link {
  cursor: pointer;
}

.profile-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  object-fit: cover;
  background: #fff;
}

.profile-meta {
  display: grid;
  line-height: 1.25;
}

.profile-meta small {
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 8px 20px rgba(31, 42, 31, 0.05);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.2rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field-row {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  background: #fff;
}

.auth-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 2fr;
}

.auth-grid-single {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.management {
  margin-top: 0;
  padding-top: 0;
}

.management-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.manage-actions {
  display: flex;
  gap: 8px;
}

.user-list {
  display: grid;
  gap: 8px;
}

.user-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 8px;
  align-items: center;
}

.user-row-deleted {
  opacity: 0.76;
  background: #faf8f8;
}

.user-row-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
}

.user-row-main {
  display: grid;
  min-width: 0;
}

.user-row-main small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.user-row-actions {
  display: flex;
  gap: 6px;
}

.ok-text {
  color: #1d6a4e;
}

.danger-text {
  color: #8a3d3d;
}

.auth-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

.auth-card h3 {
  margin: 0 0 8px;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.avatar-option {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px;
  cursor: pointer;
  background: #fff;
  color: var(--ink);
}

.avatar-option.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(44, 123, 95, 0.3);
}

.avatar-option img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: cover;
  display: block;
}

.avatar-none {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px dashed var(--line);
  display: grid;
  place-items: center;
  color: var(--muted);
  background: #fafbf8;
  font-size: 0.84rem;
}

.login-user-list {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.login-user-card {
  width: 100%;
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  padding: 8px;
}

.login-user-card:hover {
  border-color: var(--accent);
}

.login-user-icon-wrap {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
}

.login-user-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
}

.login-user-icon-none {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px dashed var(--line);
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  color: var(--muted);
  background: #fafbf8;
}

.login-user-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.login-user-meta small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.icon-upload-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-upload-group input {
  flex: 1;
  min-width: 0;
}

.icon-upload-group button {
  flex-shrink: 0;
  white-space: nowrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(31, 42, 31, 0.5);
}

.modal-content {
  position: relative;
  z-index: 1001;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  max-width: 500px;
  width: 90%;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(31, 42, 31, 0.15);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.close-button {
  appearance: none;
  border: none;
  background: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-button:hover {
  color: var(--ink);
}

.uploads-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.upload-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.upload-item img {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
}

.upload-item-meta {
  flex: 1;
  display: grid;
  gap: 2px;
  min-width: 0;
}

.upload-item-name {
  font-size: 0.9rem;
  word-break: break-all;
  color: var(--muted);
}

.upload-item-delete {
  padding: 6px 10px;
  font-size: 0.85rem;
  background: #e8c4c4;
  color: var(--danger);
  flex-shrink: 0;
}

.upload-item-delete:hover {
  background: #dab1b1;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

button {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: #dde4da;
  color: var(--ink);
}

button.secondary:hover {
  background: #d0dacf;
}

.status {
  min-height: 20px;
  color: var(--muted);
  margin: 0 0 8px;
}

.error {
  min-height: 20px;
  color: var(--danger);
  margin: 0 0 8px;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.item-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  margin-left: auto;
}

.item-meta {
  display: grid;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.item-title {
  font-weight: 700;
}

.item-editing {
  background: #f8fbf6;
}

.item-inline-edit {
  display: grid;
  gap: 4px;
  margin-bottom: 6px;
}

.item-inline-edit .field-row {
  margin-bottom: 0;
}

.item-sub {
  color: var(--muted);
  font-size: 0.9rem;
}

.item-sub-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.creator-badge {
  display: inline-block;
  font-size: 0.78rem;
  background: #ece8fb;
  color: #4d3f76;
  border-radius: 100px;
  padding: 2px 8px;
  border: 1px solid #d8cff6;
}

.completer-badge {
  display: inline-block;
  font-size: 0.78rem;
  background: #e4f3e3;
  color: #2f5d35;
  border-radius: 100px;
  padding: 2px 8px;
  border: 1px solid #c8e6c7;
}

.completed-head {
  margin-top: 16px;
}

.completed-item {
  opacity: 0.92;
}

.history-filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  margin-bottom: 12px;
}

.history-filter-actions {
  display: flex;
  align-items: end;
  gap: 8px;
}

.history-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.history-table th,
.history-table td {
  border-bottom: 1px solid #ecefe8;
  padding: 8px 10px;
  text-align: left;
  font-size: 0.92rem;
  white-space: nowrap;
}

.history-table th {
  background: #f6f8f2;
  color: var(--muted);
  font-weight: 700;
}

.history-pager {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.badge {
  display: inline-block;
  font-size: 0.78rem;
  background: #d6ebde;
  color: #1f5d3e;
  border-radius: 100px;
  padding: 3px 8px;
}

@media (max-width: 640px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
  }

  .profile {
    width: 100%;
  }

  .profile-meta {
    flex: 1;
    min-width: 0;
  }

  #logout-button {
    margin-left: auto;
  }

  .auth-grid {
    grid-template-columns: 1fr;
  }

  .management-grid {
    grid-template-columns: 1fr;
  }

  .management-grid .auth-card:first-child {
    order: 2;
  }

  .management-grid .auth-card:last-child {
    order: 1;
  }

  .avatar-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .user-row {
    grid-template-columns: 1fr;
  }

  .user-row-actions {
    width: 100%;
  }

  .user-row-actions button {
    width: 100%;
  }

  .item {
    flex-direction: row;
    align-items: flex-start;
  }

  .item-actions {
    width: auto;
    align-self: flex-start;
  }

  .item-actions button {
    width: auto;
  }

  .login-user-card {
    grid-template-columns: 44px 1fr;
  }

  .login-user-icon-wrap,
  .login-user-icon,
  .login-user-icon-none {
    width: 44px;
    height: 44px;
  }

  .icon-upload-group {
    flex-direction: column;
    align-items: stretch;
  }

  .history-filter-grid {
    grid-template-columns: 1fr;
  }

  .history-filter-actions {
    width: 100%;
  }

  .history-filter-actions button {
    width: 100%;
  }

  .history-pager {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .history-pager button {
    flex: 1;
  }
}

/* レシート（購入単位） */
.receipt-panel {
  margin-bottom: 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fbfcf8;
}

.receipt-panel h3 {
  margin: 0 0 8px;
}

.receipt-toggle-row {
  margin: 6px 0 8px;
}

.receipt-toggle-row button {
  width: fit-content;
}

.receipt-upload-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.receipt-upload-grid .field-row {
  min-width: 0;
}

.receipt-upload-grid input[type="file"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.receipt-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.receipt-preview {
  margin-top: 10px;
  min-height: 100px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  display: grid;
  place-items: center;
  padding: 10px;
}

.receipt-preview img {
  max-width: 100%;
  max-height: 300px;
  object-fit: contain;
}

.receipt-matching-panel {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.receipt-flow-toggle {
  margin-bottom: 10px;
}

.receipt-lines {
  display: grid;
  gap: 8px;
}

.receipt-lines-scroll {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.receipt-lines-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

.receipt-lines-table th,
.receipt-lines-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  vertical-align: top;
  font-size: 0.92rem;
}

.receipt-lines-table th {
  position: sticky;
  top: 0;
  background: #f8faf4;
  z-index: 1;
  text-align: left;
}

.receipt-line {
  background: #fff;
}

.receipt-line-editing {
  background: #f8fbf6;
}

.receipt-line-editing .receipt-line-actions {
  min-width: 120px;
}

.receipt-line-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.receipt-line-header strong {
  flex: 1;
}

.receipt-line-btns {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.receipt-line-btns button {
  padding: 4px 8px;
  font-size: 0.85rem;
}

.receipt-line-main {
  display: grid;
  gap: 3px;
}

.receipt-cell-label {
  display: grid;
  gap: 4px;
  font-size: 0.84rem;
  color: var(--muted);
}

.receipt-cell-label input,
.receipt-cell-label select {
  width: 100%;
  font-size: 0.9rem;
}

.receipt-line-main span {
  color: var(--muted);
  font-size: 0.92rem;
}

.receipt-line-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.receipt-line-actions label {
  display: grid;
  gap: 4px;
}

.receipt-line-manual-actions {
  display: flex;
  justify-content: flex-end;
}

.receipt-confirm-label {
  display: flex !important;
  align-items: center;
  gap: 6px;
  white-space: normal;
  margin-top: 0;
}

.receipt-suggest {
  color: var(--accent) !important;
  font-weight: 600;
}

.receipt-suggest.muted {
  color: var(--muted) !important;
  font-weight: 500;
}

.receipt-candidates {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 860px) {
  .receipt-upload-grid {
    grid-template-columns: 1fr;
  }

  .receipt-lines-scroll {
    max-height: 360px;
  }

  .receipt-confirm-label {
    margin-top: 0;
  }
}

/* STEP8-1: 音声入力UI */
.voice-input {
  margin: 0 0 16px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #f7faf3;
}

.voice-mic-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.voice-mic-button .voice-mic-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.voice-mic-button.listening {
  background: var(--danger);
  animation: voice-pulse 1.2s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.voice-status {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.voice-transcript {
  margin: 6px 0 0;
  min-height: 20px;
  color: var(--ink);
  font-weight: 600;
}

