:root {
  /* Premium Slate & Indigo Palette */
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --panel: #ffffff;
  --paper: #f8fafc;
  
  /* Sidebar */
  --sidebar: #0b1120;
  --sidebar-soft: #1e293b;
  --sidebar-border: rgba(255, 255, 255, 0.05);
  
  /* Brand Accents */
  --teal: #0f766e;
  --teal-hover: #0d9488;
  --teal-soft: #ccfbf1;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --rose: #e11d48;
  --rose-soft: #ffe4e6;
  --green: #059669;
  --green-soft: #d1fae5;
  --blue: #2563eb;
  --blue-soft: #dbeafe;

  /* Elevations */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-glass: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
  
  /* Radii */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

button {
  cursor: pointer;
}

img {
  max-width: 100%;
}

.hidden {
  display: none !important;
}

/* --- Login Screen with Glassmorphism --- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  /* Premium animated background gradient */
  background: linear-gradient(-45deg, #0b1120, #0f766e, #1e293b, #2563eb);
  background-size: 400% 400%;
  animation: gradientBG 15s ease infinite;
}

@keyframes gradientBG {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.login-panel {
  width: min(100%, 480px);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  box-shadow: var(--shadow-xl);
  padding: 40px;
  transform: translateY(0);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.login-panel:hover {
  transform: translateY(-4px);
  box-shadow: 0 30px 60px -12px rgba(0, 0, 0, 0.25);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  margin-bottom: 32px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--panel);
  border: 2px solid var(--line);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
}

.brand-mark-large {
  width: 88px;
  height: 88px;
  border: 4px solid #fff;
  box-shadow: var(--shadow-lg);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

h1, h2, h3 {
  margin: 0;
  letter-spacing: -0.02em;
  color: var(--ink);
}

h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.5rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 600; }

.login-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.login-form {
  display: grid;
  gap: 20px;
}

/* --- Forms & Inputs --- */
label {
  display: grid;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #334155;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  box-shadow: var(--shadow-sm);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.1);
  background: #fff;
}

input::placeholder {
  color: #94a3b8;
}

/* --- Buttons --- */
.login-actions, .action-row, .table-actions, .toolbar, .form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn, .icon-btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn {
  padding: 10px 18px;
}

.btn svg, .icon-btn svg, .nav-link svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.btn-primary {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 2px 4px rgba(15, 118, 110, 0.2);
}

.btn-primary:hover {
  background: var(--teal-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(15, 118, 110, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--rose);
  color: #fff;
  box-shadow: 0 2px 4px rgba(225, 29, 72, 0.2);
}

.btn-danger:hover {
  background: #be123c;
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: var(--line);
  color: var(--ink);
}

.icon-btn {
  width: 42px;
  height: 42px;
  color: var(--muted);
  background: #fff;
  border-color: var(--line);
  box-shadow: var(--shadow-sm);
}

.icon-btn:hover {
  color: var(--ink);
  border-color: #cbd5e1;
  background: #f8fafc;
  transform: translateY(-1px);
}

/* --- Layout Shell --- */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

/* --- Premium Sidebar --- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--sidebar);
  color: #fff;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 24px 16px;
  z-index: 30;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 32px;
}

.sidebar-brand strong {
  display: block;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}

.sidebar-brand span {
  display: block;
  margin-top: 4px;
  color: #94a3b8;
  font-size: 0.8rem;
  font-weight: 500;
}

.sidebar-nav {
  display: grid;
  align-content: start;
  gap: 4px;
  overflow-y: auto;
}

.nav-link {
  width: 100%;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: transparent;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.nav-link:hover {
  background: var(--sidebar-soft);
  color: #fff;
}

.nav-link.active {
  background: rgba(15, 118, 110, 0.2);
  color: var(--teal-soft);
  border-left: 3px solid var(--teal);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.nav-link.active svg {
  color: var(--teal);
}

.sidebar-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 12px 0;
  margin-top: 20px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-footer span {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
}

.sidebar-footer small {
  display: block;
  margin-top: 4px;
  color: #94a3b8;
  text-transform: capitalize;
  font-size: 0.75rem;
}

.sidebar-footer .icon-btn {
  background: var(--sidebar-soft);
  border-color: transparent;
  color: #94a3b8;
  box-shadow: none;
}

.sidebar-footer .icon-btn:hover {
  background: var(--rose);
  color: #fff;
}

/* --- Main Area & Topbar --- */
.main-area {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  /* Glassmorphism topbar */
  background: rgba(248, 250, 252, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  min-height: 88px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 16px 32px;
}

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

.menu-toggle {
  display: none;
}

/* --- Content & Layout Grids --- */
.content {
  padding: 32px;
  display: grid;
  gap: 24px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(200px, 1fr));
  gap: 20px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.metric:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.metric-top span {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.9rem;
}

.metric-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}

.metric-icon svg {
  width: 22px;
  height: 22px;
}

.metric strong {
  font-size: 2.25rem;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.metric > span:last-child {
  font-size: 0.8rem;
  color: #94a3b8;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(350px, 0.8fr);
  gap: 24px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}

/* --- Panels (Cards) --- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 0;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- Tables --- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

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

th, td {
  padding: 16px 20px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 0.75rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

tbody tr {
  transition: background-color 0.15s ease;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.compact-btn {
  width: 36px;
  height: 36px;
}

.selected-row {
  background: var(--teal-soft) !important;
  border-left: 3px solid var(--teal);
}

/* --- Badges & Status --- */
.badge, .status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--radius-full);
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.badge.books { color: #1e40af; background: #dbeafe; }
.badge.uniform { color: #b45309; background: #fef3c7; }
.badge.accessories { color: #9f1239; background: #ffe4e6; }

.badge.good, .status-connected { color: var(--green); background: var(--green-soft); }
.badge.low, .status-demo { color: var(--amber); background: var(--amber-soft); }
.badge.zero, .status-offline { color: var(--rose); background: var(--rose-soft); }

/* Pulsing effect for live connection */
.status-connected {
  position: relative;
}
.status-connected::before {
  content: '';
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(5, 150, 105, 0); }
  100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

/* --- Utilities --- */
.qty-input { width: 100px; min-height: 40px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.form-grid .span-2 { grid-column: 1 / -1; }

.toolbar { margin-bottom: 20px; justify-content: space-between; }
.search-input { min-width: 320px; border-radius: var(--radius-full); padding-left: 18px; }

/* --- Modals --- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal {
  width: min(760px, 100%);
  max-height: min(90vh, 850px);
  overflow: hidden;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  animation: modalFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header, .modal-footer {
  padding: 20px 24px;
  background: #f8fafc;
}

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

.modal-footer {
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

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

/* --- Mini Lists & Health Bars --- */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
  color: var(--muted);
  font-weight: 500;
}

.mini-list { display: grid; gap: 12px; }
.mini-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 12px;
}
.mini-row:last-child { border-bottom: 0; padding-bottom: 0; }

.stock-health { display: grid; gap: 14px; }
.health-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 10px;
  align-items: center;
  font-size: 0.9rem;
}
.health-bar {
  grid-column: 1 / -1;
  height: 6px;
  background: #e2e8f0;
  border-radius: var(--radius-full);
  overflow: hidden;
}
.health-bar span {
  display: block;
  height: 100%;
  background: var(--teal);
  width: var(--value, 0%);
  border-radius: var(--radius-full);
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Tabs --- */
.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  background: #f1f5f9;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 10px 16px;
  font-weight: 600;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* --- Toasts --- */
.toast-root {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 200;
  display: grid;
  gap: 12px;
  width: min(400px, calc(100vw - 48px));
}

.toast {
  border-radius: var(--radius-sm);
  padding: 16px;
  background: #fff;
  border-left: 4px solid var(--teal);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-weight: 600;
  font-size: 0.95rem;
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--rose); color: var(--rose); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast svg { width: 20px; height: 20px; flex: 0 0 auto; }
.muted { color: var(--muted); }
.danger-text { color: var(--rose); font-weight: 700; margin-top: 16px; font-size: 0.9rem;}

/* --- Responsiveness --- */
.drawer-open .sidebar { transform: translateX(0); }

@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(200px, 1fr)); }
  .grid-2, .set-details-layout { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-xl);
  }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 16px 20px; }
  .content { padding: 20px; }
  .form-grid, .grid-3, .stats-grid { grid-template-columns: 1fr; }
  .status-pill { display: none; }
}