/* Crocker Grocery — mobile-first */

:root {
  --green: #1f5132;
  --green-dark: #143820;
  --green-light: #e8f1eb;
  --red: #b32d2d;
  --gray-bg: #f4f4f1;
  --gray-line: #ddd;
  --gray-text: #666;
  --black: #1a1a1a;
  --white: #fff;
  --shadow: 0 2px 6px rgba(0,0,0,.1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--gray-bg);
  color: var(--black);
  font-size: 16px;
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input[type="text"], input[type="search"] {
  font-family: inherit;
  font-size: 16px;
  padding: 14px;
  border: 1px solid var(--gray-line);
  border-radius: 8px;
  width: 100%;
  background: var(--white);
}

input:focus {
  outline: none;
  border-color: var(--green);
}

.hidden { display: none !important; }

.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Name picker */
#name-picker {
  align-items: center;
  justify-content: center;
  background: var(--green);
  color: var(--white);
  padding: 24px;
}
.name-picker-inner {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.name-picker-inner h1 {
  font-size: 28px;
  text-align: center;
  margin: 0 0 12px;
}
.name-btn {
  background: var(--white);
  color: var(--green);
  font-size: 22px;
  font-weight: 700;
  padding: 22px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.name-btn:active { transform: scale(.97); }

/* Header */
header {
  background: var(--green);
  color: var(--white);
  padding: env(safe-area-inset-top) 12px 8px;
  display: grid;
  grid-template-columns: 60px 1fr 60px;
  align-items: center;
  min-height: 52px;
}
.header-left, .header-right { display: flex; align-items: center; }
.header-right { justify-content: flex-end; }
.header-title {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}
#current-user-badge {
  background: var(--white);
  color: var(--green);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}
.icon-btn {
  color: var(--white);
  font-size: 24px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* View tabs */
#view-tabs {
  display: flex;
  background: var(--green-dark);
  color: var(--white);
}
.view-tab {
  flex: 1;
  padding: 12px 0;
  color: var(--white);
  opacity: .65;
  font-weight: 600;
  font-size: 15px;
  border-bottom: 3px solid transparent;
}
.view-tab.active {
  opacity: 1;
  border-bottom-color: var(--white);
}

/* Views */
.view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.view.active { display: flex; }

/* Store tabs */
#store-tabs {
  display: flex;
  background: var(--white);
  border-bottom: 1px solid var(--gray-line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.store-tab {
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-text);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.store-tab.active {
  color: var(--green);
  border-bottom-color: var(--green);
}

/* Items list */
#items-container, #history-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 100px;
}

.item-row {
  display: flex;
  align-items: center;
  background: var(--white);
  margin: 6px 12px;
  padding: 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  gap: 12px;
}
.item-row.removing {
  opacity: .3;
  transform: translateX(40px);
  transition: opacity .25s, transform .25s;
}
.item-info { flex: 1; min-width: 0; }
.item-name {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 2px;
  word-break: break-word;
}
.item-meta {
  font-size: 13px;
  color: var(--gray-text);
}
.item-by-badge {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--green-light);
  color: var(--green);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.check-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--gray-line);
  background: var(--white);
  font-size: 22px;
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
}
.check-btn:active {
  background: var(--green);
  color: var(--white);
}

.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--gray-text);
  font-size: 15px;
}

/* History view */
.search-row {
  padding: 10px 12px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-line);
}

.history-row {
  background: var(--white);
  margin: 6px 12px;
  padding: 12px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
}
.history-info { flex: 1; min-width: 0; }
.history-item {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 2px;
}
.history-meta {
  font-size: 12px;
  color: var(--gray-text);
}
.readd-btn {
  background: var(--green-light);
  color: var(--green);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  flex-shrink: 0;
}
.readd-btn:active { background: var(--green); color: var(--white); }

/* FAB */
.fab {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: var(--green);
  color: var(--white);
  font-size: 16px;
  font-weight: 700;
  padding: 16px 22px;
  border-radius: 30px;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  z-index: 50;
}
.fab:active { background: var(--green-dark); }
.fab.hidden-fab { display: none; }

/* Footer */
footer {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--gray-text);
  background: var(--white);
  border-top: 1px solid var(--gray-line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
footer a {
  color: var(--gray-text);
  text-decoration: underline;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-card {
  background: var(--white);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
}
.modal-card h2 {
  margin: 0 0 14px;
  font-size: 20px;
}
.modal-card label {
  display: block;
  margin: 12px 0 6px;
  font-size: 13px;
  color: var(--gray-text);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.store-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.store-pick {
  background: var(--gray-bg);
  color: var(--black);
  padding: 14px;
  border-radius: 10px;
  font-weight: 600;
  border: 2px solid transparent;
}
.store-pick.selected {
  background: var(--green);
  color: var(--white);
  border-color: var(--green-dark);
}

.modal-buttons {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.btn-ghost, .btn-primary {
  flex: 1;
  padding: 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 16px;
}
.btn-ghost {
  background: var(--gray-bg);
  color: var(--black);
}
.btn-primary {
  background: var(--green);
  color: var(--white);
}
.btn-primary:disabled {
  opacity: .5;
}
.btn-primary:active { background: var(--green-dark); }

/* Toast */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--black);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 24px;
  z-index: 200;
  font-size: 14px;
  box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast.error { background: var(--red); }
