:root {
  color-scheme: dark;
  --bg: #0b0b0f;
  --fg: #f2f2f5;
  --muted: #9a9aa5;
  --accent: #6ea8fe;
  --danger: #ff6b6b;
  --panel: #1c1c22;
  --border: #2c2c34;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Respect the notch / home indicator / status bar in standalone mode */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.app-header {
  padding: 1rem 1.25rem 0.5rem;
  flex-shrink: 0;
}

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

.app-main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 1.25rem 1.25rem;
}

code {
  background: var(--panel);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.loading {
  color: var(--muted);
  padding: 1rem 0;
}

/* ---- tab bar ---- */

.tab-bar {
  flex-shrink: 0;
  display: flex;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
}

.tab-bar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.5rem 0 0.4rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.7rem;
}

.tab-bar a span {
  font-size: 1.2rem;
}

.tab-bar a.active {
  color: var(--accent);
}

/* ---- home ---- */

.cards {
  display: flex;
  gap: 0.75rem;
  margin: 1rem 0;
}

.card {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
  text-align: center;
}

.card-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.card-label {
  color: var(--muted);
  font-size: 0.8rem;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin: 1rem 0;
}

.quick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.8rem 0.4rem;
  color: var(--fg);
  text-decoration: none;
  font-size: 0.8rem;
}

.quick-btn span:first-child {
  font-size: 1.4rem;
}

.section-title {
  font-size: 1rem;
  margin: 1.25rem 0 0.5rem;
}

/* ---- lists ---- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.list-row, .nav-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.2rem;
  border-bottom: 1px solid var(--border);
}

.nav-list a {
  color: var(--fg);
  text-decoration: none;
}

/* ---- segmented control ---- */

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0 1rem;
}

.seg-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.seg-btn.active {
  color: var(--bg);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---- forms ---- */

.form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.form label, label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input, select, textarea {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font-size: 1rem;
  font-family: inherit;
}

.search-box {
  width: 100%;
  margin: 0.75rem 0;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.btn-primary:disabled {
  opacity: 0.6;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  padding: 0.3rem;
}

.back-link {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

/* ---- inventory ---- */

.variety-group {
  border-bottom: 1px solid var(--border);
}

.variety-group summary {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 0.2rem;
  cursor: pointer;
  list-style: none;
}

.variety-group summary::-webkit-details-marker {
  display: none;
}

.variety-group .list {
  border-top: none;
  padding-bottom: 0.5rem;
}

.variety-group .list-row {
  padding-left: 1rem;
  border-bottom: none;
  font-size: 0.9rem;
}

.variety-detail {
  padding: 0 0 0.75rem 1rem;
}

.price-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.5rem 0;
}

.price-form .price-size {
  flex: 1;
}

.price-form .price-value {
  width: 6rem;
}

.variety-actions {
  display: flex;
  gap: 1rem;
  margin-top: 0.4rem;
}

.btn-link.danger {
  color: var(--danger);
}

/* ---- filters ---- */

.filters {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.filters select {
  flex: 1;
}

/* ---- data table (reports) ---- */

.table-scroll {
  overflow-x: auto;
  margin: 0.75rem 0;
}

.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.data-table th, .data-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: right;
  white-space: nowrap;
}

.data-table th:first-child, .data-table td:first-child {
  text-align: left;
}

/* ---- toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(4.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.toast-error {
  border-color: var(--danger);
  color: var(--danger);
}
