:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --input-bg: #ffffff;
  --row-hover: rgba(15, 23, 42, 0.035);
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-2: #0d9488;
  --warn: #d97706;
  --bad: #ef4444;
  --good: #10b981;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  --tag-warn-bg: #fef3c7; --tag-warn-ink: #b45309;
  --tag-bad-bg: #fee2e2; --tag-bad-ink: #b91c1c;
  --tag-good-bg: #dcfce7; --tag-good-ink: #15803d;
  --tag-blue-bg: #e0f2fe; --tag-blue-ink: #0369a1;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0a1120;
    --panel: #121c2e;
    --input-bg: #0e1728;
    --row-hover: rgba(255, 255, 255, 0.04);
    --ink: #e7edf6;
    --muted: #93a4bd;
    --line: #223049;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.35), 0 2px 4px -2px rgb(0 0 0 / 0.35);
    --shadow-lg: 0 10px 20px -4px rgb(0 0 0 / 0.45), 0 4px 8px -4px rgb(0 0 0 / 0.4);
    --tag-warn-bg: rgba(217, 119, 6, 0.18); --tag-warn-ink: #fbbf24;
    --tag-bad-bg: rgba(239, 68, 68, 0.18); --tag-bad-ink: #f87171;
    --tag-good-bg: rgba(16, 185, 129, 0.18); --tag-good-ink: #34d399;
    --tag-blue-bg: rgba(56, 189, 248, 0.18); --tag-blue-ink: #38bdf8;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  transition: background-color 0.2s ease, color 0.2s ease;
}

button, input, select, textarea {
  font: inherit;
}

button {
  font-family: inherit;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 2px;
}

.primary-button:active {
  transform: translateY(1px);
}

/* Sidebar Styling */
.sidebar {
  min-height: 100vh;
  background: #0f172a;
  color: #f1f5f9;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  border-right: 1px solid #1e293b;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--brand);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 18px;
}

.brand strong {
  display: block;
  font-size: 15px;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  background: transparent;
  border: 0;
  color: #cbd5e1;
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  border-radius: 6px;
}

.sidebar-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: white;
}

.menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  box-shadow: var(--shadow);
}

.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0 auto;
  background: var(--ink);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.sidebar-backdrop {
  display: none;
}

.brand small, .sync-card small {
  color: #94a3b8;
  display: block;
  margin-top: 2px;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-button {
  color: #cbd5e1;
  background: transparent;
  text-align: left;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.15s ease;
}

.nav-button.active, .nav-button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: white;
}

.sync-card {
  margin-top: auto;
  display: grid;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid #1e293b;
}

.status-pill {
  width: fit-content;
  padding: 6px 12px;
  border-radius: 999px;
  background: #334155;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

.status-pill.online { background: var(--good); }
.status-pill.offline { background: var(--warn); }

.ghost-button {
  background: transparent;
  color: white;
  border: 1px solid #334155;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.15s ease;
}

.ghost-button:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: #475569;
}

/* Main Area Shell */
.app-shell {
  min-width: 0;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.topbar p {
  color: var(--muted);
  margin-top: 4px;
  font-size: 14px;
}

.date-chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  box-shadow: var(--shadow);
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

/* Metric Cards */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.metric::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--brand);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric strong {
  display: block;
  font-size: 24px;
  margin-top: 8px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.5px;
}

/* Panels and Grids */
.grid {
  display: grid;
  gap: 20px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid {
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 16px;
}

.form {
  display: grid;
  gap: 16px;
  align-content: start;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  padding: 10px 12px;
  min-height: 42px;
  transition: all 0.15s ease;
  font-size: 14px;
}

input[readonly] {
  opacity: 0.65;
  cursor: not-allowed;
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

input:focus, select:focus, textarea:focus {
  outline: 0;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.primary-button {
  background: var(--brand);
  color: white;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-button:hover {
  background: var(--brand-2);
}

/* POS Layout */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}

.pos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 6px;
}

.pos-product-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.pos-product-card:hover {
  border-color: var(--brand);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.pos-product-card small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.pos-product-card h3 {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
}

.pos-product-card .price {
  font-size: 15px;
  font-weight: 800;
  color: var(--brand);
  margin-top: 4px;
}

/* Cart Styles */
.cart-items-wrap {
  display: grid;
  gap: 10px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 4px;
}

.empty-cart-msg {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 20px 0;
}

.cart-item {
  display: grid;
  grid-template-columns: 1fr 70px 70px auto;
  gap: 8px;
  align-items: center;
  background: var(--bg);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
}

.cart-item strong {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cart-item input {
  padding: 4px 6px;
  min-height: 28px;
  text-align: center;
}

.cart-item .btn-remove {
  background: transparent;
  border: 0;
  color: var(--bad);
  cursor: pointer;
  font-weight: 700;
}

/* Tabs System */
.tabs-container {
  display: flex;
  gap: 8px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 12px;
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab-button {
  background: transparent;
  border: 0;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.tab-button.active {
  background: var(--brand);
  color: white;
}

.tab-button:hover:not(.active) {
  background: rgba(15, 118, 110, 0.05);
  color: var(--brand);
}

.tab-content {
  display: none;
}

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

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 650px;
}

th, td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

th {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  background: var(--bg);
}

tr:hover td {
  background: var(--row-hover);
}

/* Lists and Items */
.list {
  display: grid;
  gap: 10px;
}

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.list-item div {
  display: grid;
  gap: 4px;
}

.list-item strong {
  font-size: 14px;
}

.list-item small {
  color: var(--muted);
  font-size: 12px;
}

/* Tags / Badges */
.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.tag.warn { background: var(--tag-warn-bg); color: var(--tag-warn-ink); }
.tag.bad { background: var(--tag-bad-bg); color: var(--tag-bad-ink); }
.tag.good { background: var(--tag-good-bg); color: var(--tag-good-ink); }
.tag.blue { background: var(--tag-blue-bg); color: var(--tag-blue-ink); }

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: var(--panel);
  width: 90%;
  max-width: 480px;
  padding: 24px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  animation: scaleUp 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-cancel {
  border: 1px solid var(--line) !important;
  color: var(--muted) !important;
  background: transparent !important;
}

.btn-cancel:hover {
  background: var(--bg) !important;
  color: var(--ink) !important;
}

.action-buttons {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.btn-action {
  border: 0;
  background: transparent;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-action:hover {
  background: var(--bg);
}

.btn-action.btn-edit { color: var(--brand); }
.btn-action.btn-delete { color: var(--bad); }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleUp {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Toast Messages */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  background: #0f172a;
  color: white;
  padding: 14px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 0.2s ease;
  font-size: 13px;
  font-weight: 600;
  z-index: 3000;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* User Permissions and Form Layout */
.permissions-checkboxes label {
  font-weight: 500;
}

/* Responsive Rules */
@media (max-width: 1024px) {
  body {
    grid-template-columns: 1fr;
  }

  .menu-toggle {
    display: flex;
  }

  .sidebar-close {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    max-width: 85vw;
    min-height: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1500;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1400;
  }

  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .pos-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid.two, .form-grid {
    grid-template-columns: 1fr;
  }
  .app-shell {
    padding: 16px;
  }
  .topbar h1 {
    font-size: 20px;
  }
}

@media (max-width: 480px) {
  .metrics {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-wrap: wrap;
  }
  .date-chip {
    order: 3;
    width: 100%;
  }
}
