:root {
  --primary: #0f766e;
  --primary-hover: #115e59;
  --bg: #f5f5f3;
  --bg-soft: #f9fafb;
  --bg-grad-1: #e5f3ff;
  --bg-grad-2: #f5f5f3;
  --bg-grad-3: #f9fafb;
  --surface: #ffffff;
  --surface-alt: #fdfdfd;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 18px;
  --shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.12);
  --danger: #ef4444;
  --modal-overlay: rgba(0, 0, 0, 0.5);
  --card-hover-bg: #f3f4f6;
  --header-bg: linear-gradient(120deg, rgba(15,118,110,0.12), rgba(249,250,251,0.9));
  --input-bg: rgba(255,255,255,0.95);
  --pill-bg: #fef3c7;
  --pill-text: #92400e;
  --brand-icon-bg: rgba(255, 255, 255, 0.9);
  --font-main: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --bg-grad-1: #020617;
  --bg-grad-2: #0f172a;
  --bg-grad-3: #1e293b;
  --surface: #1e293b;
  --surface-alt: #0f172a;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --modal-overlay: rgba(0, 0, 0, 0.8);
  --card-hover-bg: #1e293b;
  --header-bg: linear-gradient(120deg, rgba(15,118,110,0.25), rgba(30,41,59,0.9));
  --input-bg: #1e293b;
  --pill-bg: #78350f;
  --pill-text: #fef3c7;
  --brand-icon-bg: #1e293b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.25s ease, border-color 0.25s ease, transform 0.15s ease, box-shadow 0.25s ease;
}

body {
  font-family: var(--font-main);
  background: radial-gradient(circle at top left, var(--bg-grad-1) 0, var(--bg-grad-2) 42%, var(--bg-grad-3) 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 32px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Header */
.main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 16px 18px;
  border-radius: 20px;
  background: var(--header-bg);
  border: 1px solid rgba(148,163,184,0.25);
  box-shadow: 0 18px 35px rgba(15,23,42,0.10);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-icon {
  font-size: 2rem;
  background: var(--brand-icon-bg);
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.brand-text h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.2;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
}

.status-indicator p {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-icon {
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.35);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: rgba(148,163,184,0.35);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.10);
}

.btn-secondary:hover {
  background: var(--card-hover-bg);
  border-color: var(--text-muted);
}

.btn-icon {
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

/* Admin restricted view */
.admin-only {
  display: none !important;
}

body.is-admin .admin-only {
  display: flex !important;
}

/* Fix for table cells: ensure they stay as table-cells to keep lines straight */
body.is-admin th.admin-only,
body.is-admin td.admin-only {
  display: table-cell !important;
}

/* Search Area */
.search-section {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  align-items: center;
}

.search-input-wrapper {
  flex: 1;
  position: relative;
  min-width: 250px;
}

.controls-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

.view-switcher {
  display: flex;
  background: var(--surface);
  border: 1px solid rgba(148,163,184,0.4);
  padding: 4px;
  border-radius: 999px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

.view-btn {
  background: none;
  border: none;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.view-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.3);
}

.view-btn:not(.active):hover {
  background: var(--bg);
  color: var(--text);
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrapper input {
  width: 100%;
  padding: 14px 16px 14px 48px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.4);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

.search-input-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
}

.filter-wrapper select {
  padding: 14px 16px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.4);
  background: var(--input-bg);
  color: var(--text);
  font-weight: 600;
  outline: none;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

/* Inventory Containers */
.inventory-container.view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}



/* Table View */
.inventory-table-wrapper {
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.inventory-table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: 0.9rem;
}

/* Ensure a single consistent horizontal rule by applying the border to cells,
   removing duplicate visuals and preventing gaps from spacing or rounding. */
.inventory-table th,
.inventory-table td {
  padding: 16px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}

/* Header styling kept separate for background and typography */
.inventory-table th {
  background: var(--bg-soft);
  text-align: left;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

/* Remove bottom border on last row so the wrapper border shows cleanly */
.inventory-table tr:last-child td {
  border-bottom: none;
}

.inventory-table tr:hover {
  background: var(--bg-soft);
}

.inventory-table .qty-pill {
  background: transparent;
  color: var(--text);
  padding: 0;
  border-radius: 0;
}

.table-price { font-weight: 800; color: var(--text); }
.table-stock { font-weight: 600; }

.card {
  background: var(--surface-alt);
  border-radius: 22px;
  padding: 22px;
  border: 1px solid rgba(148,163,184,0.25);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 16px 35px rgba(15, 23, 42, 0.10);
}

.card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-lg);
}

.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.08);
  color: var(--primary);
  letter-spacing: 0.09em;
  margin-bottom: 10px;
}

.card-title {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  margin-bottom: 4px;
}

.card-price {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  margin: 8px 0 10px;
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.card-qty {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.qty-pill {
  background: var(--pill-bg);
  color: var(--pill-text);
  padding: 2px 10px;
  border-radius: 99px;
}

.price-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 6px;
}

.price-col {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
}

.price-label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.price-value {
  font-weight: 700;
  color: var(--text);
}

.price-value.profit {
  color: #15803d;
}

.card-meta-row {
  margin-top: 10px;
}

.card-notes {
  margin-top: 4px;
  font-size: 0.83rem;
  color: var(--text-muted);
}

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

.card-footer {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.card-action {
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
}

.card-action.edit:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.card-action.delete:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
  opacity: 1;
  visibility: visible;
  transition: all 0.2s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-content {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(1);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .modal-content {
  transform: scale(0.95);
}

.modal-header {
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 1.25rem; font-weight: 800; }

.close-modal {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body { padding: 24px; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 700; margin-bottom: 8px; color: var(--text-muted); }
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 12px 16px; border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text); font-family: inherit; font-size: 1rem;
  appearance: none;
}

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 40px;
}

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

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

.modal-footer { padding: 20px 24px; background: var(--bg); display: flex; justify-content: flex-end; gap: 12px; }

/* PIN Modal Special Styles */
.settings-modal { max-width: 600px; }
.settings-body { padding: 20px; }

.tabs-container {
  display: flex;
  background: var(--bg);
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 12px 20px;
  background: none;
  border: none;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.owner-item {
  border-left: 4px solid var(--primary);
}

.owner-badge {
  font-size: 0.6rem;
  font-weight: 800;
  padding: 2px 6px;
  background: var(--primary);
  color: white;
  border-radius: 4px;
}

.settings-section {
  margin-bottom: 32px;
}

.settings-section h3 {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: 16px;
  color: var(--text);
}

.inline-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-soft);
  border-radius: 14px;
  border: 1px solid rgba(148,163,184,0.35);
}

.cat-info {
  display: flex;
  flex-direction: column;
}

.cat-name {
  font-weight: 700;
  color: var(--text);
}

.cat-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.cat-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.delete-cat-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  align-items: center;
}

.delete-cat-btn:hover {
  color: var(--danger);
}

.voice-input-wrapper {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.btn-mic {
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-mic.recording {
  background: #fee2e2;
  color: var(--danger);
  border-color: var(--danger);
  animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.voice-status {
  font-size: 0.7rem;
  font-weight: 600;
  margin-top: 4px;
  color: var(--primary);
  height: 1rem;
}

.utang-badge {
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.85rem;
}

.utang-positive {
  background: #fee2e2;
  color: #991b1b;
}

.utang-zero {
  background: #f3f4f6;
  color: #6b7280;
}

.suki-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-sm-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-weight: 800;
}

.btn-sm-circle:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.icon-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pin-modal { max-width: 320px; text-align: center; }
.modal-desc { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 20px; }
.pin-input-container input {
  font-size: 2rem; letter-spacing: 0.5em; text-align: center; width: 100%;
}

/* Spinner */
.loading-state { text-align: center; padding: 100px 0; color: var(--text-muted); }
.spinner {
  width: 48px; height: 48px; border: 4px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; margin: 0 auto 16px; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Side Drawer Styles */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(4px);
  z-index: 2000;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.drawer-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.side-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 280px;
  height: 100%;
  background: var(--surface);
  box-shadow: -10px 0 30px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.drawer-overlay.hidden .side-drawer {
  transform: translateX(100%);
}

.drawer-header {
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 12px;
  text-align: left;
  transition: background 0.2s;
}

.drawer-item:hover {
  background: var(--bg-soft);
}

.drawer-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 4px;
}

.drawer-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hidden { display: none !important; }

.app-footer {
  margin-top: auto;
  padding: 32px 0 18px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

@media (max-width: 600px) {


  .inventory-table-wrapper {
    overflow-x: auto;
  }

  .app {
    padding: 12px 10px 24px;
  }

  .main-header {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 16px;
    margin-bottom: 16px;
  }

  .brand {
    justify-content: space-between;
    width: 100%;
  }

  .brand-icon {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
    border-radius: 14px;
  }

  .brand-text h1 {
    font-size: 1.25rem;
  }

  .header-actions {
    display: flex;
    justify-content: flex-end;
    width: auto;
  }

  .header-actions .btn-label {
    display: none;
  }

  .btn-primary, .btn-secondary, .btn-icon {
    padding: 10px;
    min-height: 44px;
    min-width: 44px;
    flex-direction: row;
    border-radius: 12px;
  }

  .brand-text .status-indicator {
    display: none; /* Hide sync text on mobile to save vertical space */
  }

  .search-section {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
  }

  .search-input-wrapper {
    min-width: 100%;
  }

  .search-input-wrapper input {
    padding: 12px 12px 12px 42px;
    font-size: 0.9rem;
  }

  .filter-wrapper {
    width: 100%;
  }

  .filter-wrapper select {
    width: 100%;
    padding: 12px;
    font-size: 0.9rem;
  }

  .card {
    padding: 16px;
    border-radius: 18px;
  }

  .card-price {
    font-size: 1.4rem;
  }

  .modal-content {
    max-height: 90vh;
    display: flex;
    flex-direction: column;
  }

  .modal-body {
    overflow-y: auto;
    padding: 16px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}