:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #dfe4ec;
  --text: #18202c;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.1);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --checked-bg: #f1f5f9;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  --radius: 10px;
  --item-font-size: 16px;
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #162032;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.16);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --checked-bg: #172033;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-badge {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: var(--text);
}

.tool-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tool-tab.is-active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: transparent;
}

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

.container {
  max-width: 820px;
  margin: 20px auto;
  padding: 0 16px 40px;
}

.tool-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 4px 6px;
  margin-left: -6px;
  margin-right: -6px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.panel-header:hover {
  background: var(--surface-alt);
}

.panel-header:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: transform 0.18s ease;
}

.panel-chevron svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panel-header.is-collapsed .panel-chevron {
  transform: rotate(-90deg);
}

.panel-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
}

.list-counter {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 999px;
}

.storage-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}

.storage-bar.is-collapsed {
  display: none;
}

.storage-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.font-control {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.font-val-btn {
  min-width: 48px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.control-select,
.control-input {
  height: 34px;
  padding: 0 10px;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  outline: none;
}

.control-select {
  min-width: 150px;
  max-width: 200px;
}

.control-input {
  width: 160px;
}

.control-select:focus,
.control-input:focus {
  border-color: var(--primary);
}

.icon-btn {
  height: 34px;
  min-width: 34px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-alt);
  border-color: var(--text-muted);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.primary-btn:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.accept-btn {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.accept-btn:hover:not(:disabled) {
  background: var(--success);
  color: #ffffff;
}

.danger-hover:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.shopping-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s;
}

.list-row.is-locked {
  cursor: pointer;
  user-select: none;
}

.list-row.is-locked:hover {
  border-color: var(--primary);
}

.list-row.is-checked {
  background: var(--checked-bg);
}

.list-row.is-editing {
  border-color: var(--primary);
  background: var(--surface-alt);
}

.row-check {
  width: 18px;
  height: 18px;
  margin-top: 7px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.row-num {
  min-width: 24px;
  margin-top: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
}

.row-content {
  flex: 1;
  min-width: 0;
}

.item-text {
  display: block;
  padding: 4px 4px;
  font-size: var(--item-font-size);
  line-height: 1.4;
  word-break: break-word;
}

.list-row.is-checked .item-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.edit-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-input {
  width: 100%;
  min-height: 36px;
  padding: 4px 10px;
  font-size: var(--item-font-size);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--primary);
  border-radius: 7px;
  outline: none;
}

.item-input.is-invalid {
  border-color: var(--danger);
}

.emoji-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.emoji-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.95rem;
  cursor: pointer;
  line-height: 1.3;
}

.emoji-btn:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
}

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

@media (max-width: 600px) {
  .tool-panel {
    padding: 12px;
  }

  .storage-group {
    width: 100%;
  }

  .control-select,
  .control-input {
    flex: 1;
    width: auto;
    max-width: none;
  }

  .io-group {
    justify-content: flex-end;
  }

  .list-row {
    padding: 8px;
    gap: 7px;
  }

  .icon-btn {
    height: 32px;
    min-width: 32px;
    padding: 0 6px;
  }
}
