:root {
  --ink: #0f172a;
  --muted: #5c6475;
  --primary: #2c4d7a;
  --primary-dark: #1b3557;
  --accent: #f5b642;
  --surface: #ffffff;
  --surface-alt: #f6f7fb;
  --border: #e1e4ee;
  --shadow: 0 20px 40px rgba(15, 23, 42, 0.12);
  --radius: 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top, #fdf2d0 0%, #f6f7fb 45%, #e8edf7 100%);
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

h1, h2, h3, h4 {
  font-family: 'Space Grotesk', sans-serif;
  margin: 0 0 0.5rem;
}

p {
  margin: 0.5rem 0;
}

.muted {
  color: var(--muted);
}

.page {
  padding: 2.5rem clamp(1.5rem, 4vw, 4rem) 4rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem clamp(1.5rem, 4vw, 4rem);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(140deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.2rem;
}

.brand-name {
  font-weight: 600;
  font-size: 1.1rem;
}

.brand-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
}

.nav-link {
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-radius: 999px;
}

.nav-link:hover {
  background: var(--surface-alt);
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.7rem 1.4rem;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-alt);
  color: var(--ink);
}

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

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

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

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

.inline {
  display: inline-flex;
  gap: 0.6rem;
  align-items: center;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.8rem;
  box-shadow: var(--shadow);
  margin-bottom: 2rem;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.6rem;
  border: 1px solid var(--border);
  box-shadow: 0 12px 25px rgba(15, 23, 42, 0.08);
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
  margin-bottom: 2rem;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  font-size: 1rem;
  font-family: inherit;
}

.field textarea {
  resize: vertical;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.search-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.search-bar input {
  flex: 1;
  min-width: 220px;
}

.table {
  display: grid;
  gap: 0.5rem;
}

.table-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 0.5rem;
  background: var(--surface-alt);
  padding: 0.8rem 1rem;
  border-radius: 14px;
  align-items: center;
}

.table-row.table-head {
  font-weight: 600;
  background: #e6ebf4;
}

.table-row div:last-child {
  text-align: right;
}

.tag {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  margin-left: 0.5rem;
}

.tag.green {
  background: #d8f6df;
  color: #0f6a2f;
}

.tag.gray {
  background: #e5e7eb;
  color: #4b5563;
}

.flash {
  padding: 0.8rem 1rem;
  border-radius: 14px;
  margin-bottom: 1rem;
  font-weight: 600;
}

.flash.toast {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 20;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.2);
  margin-bottom: 0;
  animation: toastIn 0.25s ease;
}

.flash.toast.hide {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.flash.error {
  background: #fee2e2;
  color: #7f1d1d;
}

.flash.success {
  background: #dcfce7;
  color: #14532d;
}

.flash.info {
  background: #dbeafe;
  color: #1e3a8a;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.auth-card {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: 24px;
  box-shadow: var(--shadow);
  width: min(480px, 92vw);
}

.auth-brand {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.5rem;
}

.badge {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: linear-gradient(140deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.3rem;
}

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

.notes-block {
  background: var(--surface-alt);
  border-radius: 18px;
  padding: 1rem;
}

.notes-header {
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.notes-empty {
  color: var(--muted);
  margin-bottom: 0.8rem;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.note {
  background: var(--surface-alt);
  border-radius: 16px;
  padding: 0.9rem 1rem;
}

.note-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--border);
}

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

.list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.8rem;
  background: var(--surface-alt);
  border-radius: 14px;
}

.tabs {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.tab {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.5rem 1.2rem;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}

.tab-panels {
  display: grid;
  gap: 1.5rem;
}

.tab-panel {
  display: none;
}

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

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

.mini-select {
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  background: #fff;
}

.ipad-form input,
.ipad-form select,
.ipad-form textarea {
  font-size: 1.05rem;
  padding: 1rem 1.2rem;
}

.scanner {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.scanner.active {
  display: flex;
}

.scanner-frame {
  background: #0f172a;
  border-radius: 20px;
  padding: 1rem;
  position: relative;
  width: min(520px, 92vw);
}

.scanner video {
  width: 100%;
  border-radius: 16px;
}

.scanner-overlay {
  position: absolute;
  inset: 1rem;
  border: 2px dashed rgba(245, 182, 66, 0.8);
  border-radius: 16px;
  pointer-events: none;
}

.scanner-line {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 50%;
  height: 2px;
  background: rgba(245, 182, 66, 0.9);
  animation: scan 2s infinite;
}

@keyframes scan {
  0% { transform: translateY(-40px); }
  50% { transform: translateY(40px); }
  100% { transform: translateY(-40px); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .table-row {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    grid-auto-rows: auto;
  }
}
