:root {
  --color-bg: #f4f1ea;
  --color-surface: #ffffff;
  --color-primary: #2f4f3f;
  --color-primary-dark: #22392c;
  --color-accent: #b9895a;
  --color-text: #2a2a26;
  --color-muted: #6b6b63;
  --color-border: #e3ddd0;
  --color-danger: #b3413a;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(160px + var(--safe-bottom));
  min-height: 100vh;
}

.app-header {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: #fff;
  padding: 20px 16px 16px;
  text-align: center;
}

.header-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.app-logo {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.3));
}

.header-titles {
  text-align: left;
}

.app-header h1 {
  margin: 0;
  font-size: 1.4rem;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.85rem;
  opacity: 0.85;
}

@media (max-width: 360px) {
  .app-logo {
    width: 42px;
    height: 42px;
  }
}

.room-selector {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 12px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.room-chip {
  flex: 0 0 auto;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.room-chip .chip-total {
  font-weight: 400;
  font-size: 0.78rem;
  opacity: 0.75;
}

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

.room-chip.has-total:not(.active) {
  border-color: var(--color-accent);
}

#app-main {
  padding: 16px 12px 8px;
  max-width: 720px;
  margin: 0 auto;
}

.room-opened-info {
  display: inline-block;
  margin: 0 0 10px;
  padding: 4px 10px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--color-muted);
}

.room-opened-info[hidden] {
  display: none;
}

.items-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.item-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.item-info {
  min-width: 0;
}

.item-name {
  font-weight: 600;
  font-size: 1rem;
  display: block;
}

.item-price {
  color: var(--color-muted);
  font-size: 0.85rem;
}

.item-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.qty-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--color-bg);
  color: var(--color-primary);
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.qty-btn.plus {
  background: var(--color-primary);
  color: #fff;
}

.qty-btn:active {
  transform: scale(0.92);
}

.qty-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.qty-value {
  min-width: 22px;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
}

.item-line-total {
  min-width: 64px;
  text-align: right;
  font-weight: 600;
  color: var(--color-accent);
  font-size: 0.9rem;
}

.summary-section {
  margin-top: 12px;
}

.summary-section h2 {
  font-size: 1.05rem;
  margin: 4px 0 10px;
}

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

.summary-row {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.summary-room-name {
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.summary-room-date {
  font-weight: 400;
  font-size: 0.72rem;
  color: var(--color-muted);
}

.summary-room-total {
  color: var(--color-accent);
  font-weight: 700;
}

.summary-empty {
  color: var(--color-muted);
  text-align: center;
  padding: 20px;
  font-style: italic;
}

.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 10px 14px calc(10px + var(--safe-bottom));
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
  z-index: 20;
}

.footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.footer-row + .footer-row {
  margin-top: 8px;
}

.room-total {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.room-total span {
  font-size: 0.75rem;
  color: var(--color-muted);
}

.room-total strong {
  font-size: 1.35rem;
  color: var(--color-primary);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-ghost {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
  flex: 1;
}

.btn-danger-outline {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
  flex: 1;
}

.footer-actions .btn {
  flex: 1;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 340px;
  width: 100%;
  text-align: center;
}

.modal-card p {
  margin: 0 0 16px;
  font-size: 1rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions .btn {
  flex: 1;
}

.toast {
  position: fixed;
  bottom: calc(150px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary-dark);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 60;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

@media (min-width: 600px) {
  .items-list {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 720px) {
  .app-header h1 {
    font-size: 1.7rem;
  }
}
