:root {
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-contrast: #ffffff;
  --accent-soft: #eff4ff;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-sunken: #f2f3f5;
  --text: #16181d;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --warning-bg: #fffbeb;
  --warning-border: #f59e0b;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent-soft: #16233f;
    --bg: #121317;
    --surface: #1c1e24;
    --surface-sunken: #24262d;
    --text: #edeef0;
    --text-muted: #9aa0a9;
    --border: #2d3039;
    --danger-soft: #2a1414;
    --warning-bg: #2e2510;
    --warning-border: #b8860b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 28px;
  width: 100%;
  max-width: 380px;
}

.login-title {
  margin: 0 0 28px;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.01em;
}

/* ---------- Form fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
}

.field input, .field select, .select, .search-input {
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 400;
  min-height: 44px;
  width: 100%;
  max-width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus, .field select:focus, .select:focus, .search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin: 8px 0 0;
  font-weight: 400;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:active { opacity: 0.85; }

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

.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

.btn-ghost:hover { background: var(--surface-sunken); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-block { width: 100%; }

/* ---------- App shell ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-email {
  color: var(--text-muted);
  font-size: 0.85rem;
  display: none;
}

@media (min-width: 480px) {
  .user-email { display: inline; }
}

.app-nav {
  display: flex;
  gap: 2px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.app-nav::-webkit-scrollbar { display: none; }

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0 14px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  min-height: 46px;
  transition: color 0.15s;
}

.nav-btn:hover { color: var(--text); }

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

.view.hidden { display: none; }

.app-main {
  padding: 20px;
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 480px) {
  .app-main { padding: 14px; }
  .app-header { padding: 0 14px; }
  .app-nav { padding: 0 14px; }
}

/* ---------- Dashboard ---------- */
.dash-greeting { margin-bottom: 18px; }

.dash-greeting-text {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.dash-date {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.quick-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 16px;
  min-height: 42px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s;
}

.quick-action-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.quick-action-icon {
  font-weight: 800;
  font-size: 1rem;
}

.stat-card-clickable {
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  width: 100%;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
}

.stat-card-warning { border-color: var(--warning-border); }

.stat-value {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 2px;
  font-weight: 500;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 24px 0 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.section-title:first-of-type { margin-top: 0; }

/* Low stock quick list */
.low-stock-list {
  background: var(--surface);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.low-stock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--warning-bg);
  border-bottom: 1px solid var(--border);
}

.low-stock-row:last-child { border-bottom: none; }

.low-stock-name { font-weight: 600; font-size: 0.9rem; }
.low-stock-meta { color: var(--text-muted); font-size: 0.78rem; margin-top: 1px; }

/* Activity feed */
.activity-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.activity-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.activity-row:last-child { border-bottom: none; }

.activity-icon {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--surface-sunken);
  color: var(--text-muted);
}

.activity-icon-create, .activity-icon-stock_in { background: #dcfce7; color: #16a34a; }
.activity-icon-delete, .activity-icon-stock_out { background: var(--danger-soft); color: var(--danger); }
.activity-icon-update { background: var(--accent-soft); color: var(--accent); }

@media (prefers-color-scheme: dark) {
  .activity-icon-create, .activity-icon-stock_in { background: #0f2e1b; color: #4ade80; }
}

.activity-body { flex: 1; min-width: 0; }
.activity-main { font-size: 0.88rem; }
.activity-main strong { font-weight: 700; }
.activity-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.search-input { flex: 1 1 220px; }
.select { flex: 0 1 160px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
  min-height: 44px;
  font-weight: 500;
}

/* ---------- Table ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.inventory-table {
  width: 100%;
  border-collapse: collapse;
}

.inventory-table th, .inventory-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  white-space: nowrap;
}

.inventory-table tbody tr:last-child td { border-bottom: none; }
.inventory-table tbody tr:hover { background: var(--surface-sunken); }

.inventory-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.row-low-stock { background: var(--warning-bg); }
.row-low-stock:hover { background: var(--warning-bg); filter: brightness(0.97); }

/* ---------- Cards (mobile item list) ---------- */
.card-list {
  display: none;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
}

.card-low-stock {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.item-card-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.item-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 5px 0;
  border-top: 1px solid var(--border);
}

.item-card-row:first-of-type { border-top: none; margin-top: 4px; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 36px 0;
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  #inventory-table-wrap { display: none; }
  .card-list { display: flex; }
}

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  font-size: 0.88rem;
  font-weight: 500;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-success { border-left: 3px solid var(--success); }

/* ---------- Row/card icon actions ---------- */
.row-actions {
  display: flex;
  gap: 4px;
  white-space: nowrap;
}

.btn-icon {
  min-width: 34px;
  min-height: 34px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover { background: var(--surface-sunken); color: var(--text); }
.btn-icon-danger { color: var(--danger); }
.btn-icon-danger:hover { background: var(--danger-soft); color: var(--danger); }

.item-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

/* ---------- Quantity stepper (one-click +/-) ---------- */
.qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-sunken);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.qty-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--surface);
  color: var(--text);
  border-radius: 5px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
  box-shadow: var(--shadow-sm);
}

.qty-btn:hover { background: var(--accent); color: #fff; }
.qty-btn:active { transform: scale(0.94); }

.qty-value {
  min-width: 42px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.qty-value:hover { text-decoration: underline; }

/* ---------- Categories & Locations management ---------- */
.manage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 700px) {
  .manage-grid { grid-template-columns: 1fr; }
}

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

.manage-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.manage-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
}

.manage-row:hover { background: var(--surface-sunken); }

.manage-row-text { font-size: 0.9rem; font-weight: 500; }
.manage-row-sub { color: var(--text-muted); font-weight: 400; }

.inline-add-form {
  display: flex;
  gap: 8px;
}

.inline-add-form input {
  flex: 1;
  min-width: 0;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  min-height: 40px;
}

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 18, 22, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 150;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 26px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-title {
  margin: 0 0 4px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin: 0 0 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.field-row {
  display: flex;
  gap: 12px;
}

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

.field textarea {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
}

.stock-direction {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

@media (max-width: 480px) {
  .field-row { flex-direction: column; gap: 0; }
  .modal-card { padding: 20px; }
}

/* ---------- Spinner ---------- */
.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 18, 22, 0.2);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.spinner-overlay.show { display: flex; }

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

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