/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #000000;
  --bg-surface: #0a0a0a;
  --bg-card: #111111;
  --bg-input: #0a0a0a;
  --text: #ffffff;
  --text-dim: #777777;
  --text-muted: #444444;
  --border: #222222;
  --red: #ff3b30;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --font: 'Space Mono', 'Courier New', monospace;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* === App Layout === */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  transition: transform 0.3s ease;
}

#app.shifted {
  transform: translate(var(--shift-x, 0), var(--shift-y, 0));
}

#app.dimmed {
  filter: brightness(0.3);
}

/* === Header === */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  flex-shrink: 0;
  min-height: 48px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#header-title {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.02em;
}

.header-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* === Icon Buttons === */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn:active {
  color: var(--text);
}

/* === Main Content === */
main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 16px 120px;
  -webkit-overflow-scrolling: touch;
}

/* Home view: even spacing on all sides */
main:has(.lists-grid),
main:has(.empty-state) {
  padding-top: 16px;
}

main::-webkit-scrollbar {
  width: 0;
}

/* === Home View: List Cards === */
.lists-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  cursor: pointer;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0;
  transition: opacity var(--transition), border-color var(--transition);
}

.list-card:active {
  opacity: 0.6;
}

.list-card-count {
  font-size: 2rem;
  font-weight: 700;
  min-width: 48px;
  letter-spacing: -0.04em;
}

.list-card-info {
  flex: 1;
  min-width: 0;
}

.list-card-info h3 {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.list-card-info p {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.list-card-actions .icon-btn {
  color: var(--text-muted);
}

/* === List Detail View === */
.category-group {
  margin-bottom: 24px;
}

.category-header {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  padding: 0 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.item-list {
  list-style: none;
}

.grocery-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #0e0e0e;
  min-height: 44px;
}

.grocery-item:active {
  opacity: 0.6;
}

.grocery-item.checked {
  opacity: 0.5;
}

.grocery-item.checked .item-name {
  text-decoration: line-through;
}

.item-checkbox {
  width: 22px;
  height: 22px;
  border: 1.5px solid var(--text-muted);
  border-radius: 5px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.item-checkbox.checked {
  background: var(--text);
  border-color: var(--text);
}

.item-checkbox.checked::after {
  content: '';
  width: 9px;
  height: 5px;
  border-left: 1.5px solid var(--bg);
  border-bottom: 1.5px solid var(--bg);
  transform: rotate(-45deg) translateY(-1px);
}

.item-details {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 0.9rem;
  font-weight: 400;
}

.item-quantity {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.item-delete {
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
}

@media (hover: none) {
  .item-delete {
    opacity: 0.3;
  }
}

.grocery-item:hover .item-delete {
  opacity: 1;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state h3 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--text-dim);
  font-weight: 400;
}

.empty-state p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* === Floating Action Buttons === */
.fab-group {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 24px;
  z-index: 50;
}

.fab {
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.fab-main {
  width: 96px;
  height: 96px;
  background: var(--text);
  color: var(--bg);
}

.fab-main svg {
  width: 42px;
  height: 42px;
}

.fab-main:active {
  transform: scale(0.92);
}

/* Listening state: pulsing red glow */
.fab-main.listening {
  box-shadow: 0 0 20px rgba(255, 59, 48, 0.7), 0 0 50px rgba(255, 59, 48, 0.35);
  animation: mic-glow 1.8s ease-in-out infinite;
  color: #ff3b30;
}

@keyframes mic-glow {
  0%, 100% {
    box-shadow: 0 0 18px rgba(255, 59, 48, 0.6), 0 0 40px rgba(255, 59, 48, 0.25);
  }
  50% {
    box-shadow: 0 0 30px rgba(255, 59, 48, 0.9), 0 0 60px rgba(255, 59, 48, 0.45);
  }
}

.fab-main.speaking {
  opacity: 0.5;
}

.fab-small {
  width: 66px;
  height: 66px;
  background: rgba(0, 0, 0, 0.75);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.fab-small svg {
  width: 30px;
  height: 30px;
}

.fab-small {
  position: relative;
}

.fab-small:active {
  background: var(--text);
  color: var(--bg);
}

.printer-dot {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 4px solid transparent;
  border-bottom-color: var(--text-muted);
  transition: border-bottom-color 0.3s;
  pointer-events: none;
  clip-path: inset(75% 30% 0% 30%);
}

.printer-dot.connected {
  border-bottom-color: #34c759;
}

/* New list FAB (home view) */
.fab-new-list {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
}

/* === Add Bar (expandable) === */
.add-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 60;
  transform: translateY(100%);
  transition: transform 0.25s ease;
}

.add-bar.visible {
  transform: translateY(0);
}

#add-input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--text-muted);
  padding: 8px 0;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  font-family: var(--font);
  transition: border-color var(--transition);
}

#add-input:focus {
  border-color: var(--text);
}

#add-input::placeholder {
  color: var(--text-muted);
}

/* === Settings Panel (swipe from right) === */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.settings-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 85%;
  max-width: 360px;
  background: var(--bg-surface);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  border-left: 1px solid var(--border);
}

.settings-panel.visible {
  transform: translateX(0);
}

.settings-handle {
  width: 32px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 2px;
  margin: 12px auto;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 40px;
}

.panel-body h2 {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 24px;
  letter-spacing: -0.01em;
}

.setting-group {
  margin-bottom: 24px;
}

.setting-group h3 {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
}

.setting-row input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 40px;
  height: 22px;
  background: var(--text-muted);
  border-radius: 11px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition);
  border: none;
  outline: none;
}

.setting-row input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--bg);
  border-radius: 50%;
  transition: transform var(--transition);
}

.setting-row input[type="checkbox"]:checked {
  background: var(--text);
}

.setting-row input[type="checkbox"]:checked::after {
  transform: translateX(18px);
}

.setting-row input[type="time"] {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.75rem;
}

.setting-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--font);
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
  transition: background var(--transition);
}

.btn:active {
  background: var(--bg-card);
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 0.8rem;
  color: var(--text);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast-action {
  background: none;
  border: none;
  color: var(--red);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 700;
  margin-left: 12px;
  padding: 0;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* === Idle / Ambient Mode === */
.idle-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 20px;
}

.idle-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin-bottom: 16px;
  opacity: 0.6;
}

.idle-clock {
  font-size: 4rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
  letter-spacing: -0.04em;
}

.idle-date {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 40px;
}

.idle-summary {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.idle-summary strong {
  color: var(--text);
}

/* === Edit Dialog === */
.edit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.edit-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 360px;
}

.edit-dialog h3 {
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.edit-dialog input, .edit-dialog select {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
  font-size: 0.85rem;
  color: var(--text);
  font-family: var(--font);
  margin-bottom: 12px;
  outline: none;
}

.edit-dialog input:focus, .edit-dialog select:focus {
  border-color: var(--text);
}

.edit-dialog select {
  appearance: none;
  cursor: pointer;
  border-radius: 0;
}

.edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.edit-actions button {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: opacity var(--transition);
}

.btn-save {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text) !important;
}

.btn-cancel {
  background: transparent;
  color: var(--text);
}

.confirm-dialog p {
  margin-bottom: 20px;
  font-size: 0.9rem;
  text-align: center;
}

.btn-danger {
  background: transparent;
  color: #ff4444;
  border-color: #ff4444 !important;
}

/* === Voice Transcript Overlay === */
.voice-overlay {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 45;
  width: 90%;
  max-width: 500px;
  pointer-events: none;
}

.voice-overlay-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.voice-status {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.voice-transcript {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.4;
  min-height: 1.2em;
  word-break: break-word;
}

/* === Uncertain Items === */
.grocery-item.uncertain {
  border-left: 3px solid #f5a623;
  padding-left: 9px;
}

.grocery-item.uncertain .item-name::after {
  content: '?';
  display: inline-block;
  margin-left: 6px;
  font-size: 0.7rem;
  color: #f5a623;
  font-weight: 700;
}

/* === Item Notes === */
.item-notes {
  font-size: 0.65rem;
  color: var(--text-muted);
  display: block;
  margin-top: 1px;
  font-style: italic;
}

/* === Password Gate === */
.password-gate {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-gate-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 80%;
  max-width: 300px;
}

.password-logo {
  width: 80px;
  height: 80px;
}

.password-gate h2 {
  font-family: var(--font);
  font-size: 1.2rem;
  letter-spacing: 0.05em;
  color: var(--text);
}

.password-gate input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text);
  text-align: center;
  outline: none;
}

.password-gate input:focus {
  border-color: var(--text-dim);
}

.password-gate .btn {
  width: 100%;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  letter-spacing: 0.05em;
}

/* === Utility === */
.hidden {
  display: none !important;
}

/* === Responsive === */
@media (max-width: 360px) {
  html { font-size: 15px; }
}

@media (min-width: 768px) {
  .idle-clock { font-size: 6rem; }
}
