@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary: #BC7C67;
  --primary-dark: #A66A56;
  --primary-ghost: rgba(188,124,103,0.12);
  --primary-light: rgba(188,124,103,0.15);
  --success: #1e8e3e;
  --success-light: #e6f4ea;
  --error: #d93025;
  --error-light: #fce8e6;
  --warning: #f29900;
  --warning-light: #fef7e0;
  --surface: #ffffff;
  --bg: #121212;
  --nav-bg: #1A1A1A;
  --border: #E0D4CE;
  --text: #2D2D2D;
  --text-muted: #9E9E9E;
  --radius: 20px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --shadow: 0 2px 8px rgba(0,0,0,0.18);
  --shadow-md: 0 6px 20px rgba(0,0,0,0.22);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ── Login Screen ── */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
}

.login-card .form-section {
  gap: 14px;
}

/* ── App Shell ── */
.app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 72px; /* space for bottom nav */
}

.app.hidden {
  display: none;
}

/* ── Header ── */
.app-header {
  background: #ffffff;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 #f0e8e4, 0 2px 8px rgba(0,0,0,0.06);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.1px;
}

.btn-icon-header {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.btn-icon-header:hover {
  background: var(--primary-ghost);
  color: var(--primary);
}

/* ── Bottom Navigation ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: var(--nav-bg);
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 8px 12px;
  background: transparent;
  color: #555;
  border: none;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s;
}

.nav-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  transition: fill 0.15s;
}

.nav-btn.active {
  color: var(--primary);
  font-weight: 700;
}

.nav-btn:not(.active):hover {
  color: #aaa;
}

/* ── Main Content ── */
.app-main {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tab-panel { display: none; flex-direction: column; gap: 12px; }
.tab-panel.active { display: flex; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.card-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -8px;
}

/* ── Badge ── */
.badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* ── Image Grid ── */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  min-height: 0;
}

.thumb-wrap {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  aspect-ratio: 9/16;
  background: #f5f0ee;
  border: 2px solid var(--border);
}

.thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: 10px;
  text-align: center;
  padding: 3px 4px;
  line-height: 1.3;
}

.thumb-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius-pill);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:not(:disabled):hover { background: #137333; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-outline:not(:disabled):hover {
  background: var(--primary-ghost);
}

.btn-danger-outline {
  background: transparent;
  color: var(--error);
  border: 1.5px solid var(--border);
  font-size: 13px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
}


.btn-icon {
  background: transparent;
  border: none;
  color: var(--error);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.btn-icon:hover { background: var(--error-light); }

.full-width { width: 100%; }

.btn-row {
  display: flex;
  gap: 8px;
}

.btn-row .btn { flex: 1; }

/* ── Loading ── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Form Fields ── */
.form-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group textarea {
  resize: vertical;
  min-height: 72px;
}

.form-group input.unclear,
.form-group textarea.unclear,
.form-group select.unclear {
  border-color: var(--warning);
  background: var(--warning-light);
}

.form-group input.unclear:focus,
.form-group textarea.unclear:focus,
.form-group select.unclear:focus {
  box-shadow: 0 0 0 3px rgba(242, 153, 0, 0.2);
}

.calc-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  text-transform: uppercase;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ── Item Card ── */
.item-card {
  border: 2px solid var(--border);
  position: relative;
}

.item-card:first-of-type {
  border-color: var(--primary);
}

.item-number {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* ── Sync Status ── */
.sync-status {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.sync-status.success {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid #a8d5b5;
}

.sync-status.error {
  background: var(--error-light);
  color: var(--error);
  border: 1px solid #f5a9a3;
}

.sync-icon {
  font-size: 20px;
  flex-shrink: 0;
  margin-top: -1px;
}

/* ── Config Tab ── */
#system-prompt-input {
  width: 100%;
  min-height: 320px;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  line-height: 1.6;
}

#system-prompt-input:focus {
  outline: none;
  border-color: var(--primary);
}

.config-status {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
}

/* ── Divider ── */
.section-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Toggle Switch ── */
.toggle-group {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}

.toggle-label-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ── Utilities ── */
.hidden { display: none !important; }
.mt-4 { margin-top: 4px; }
.text-muted { color: var(--text-muted); font-size: 13px; }

/* ── Scrollbar (desktop) ── */
@media (min-width: 600px) {
  ::-webkit-scrollbar { width: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

  .bottom-nav {
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
  }
}
