:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f3;
  --text: #17212b;
  --muted: #60707f;
  --line: #dbe4e7;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --accent: #b7791f;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(23, 33, 43, 0.08);
  --radius: 8px;
  font-family: Inter, "Segoe UI", Tahoma, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef3f3;
}

.auth-wrap {
  width: min(100%, 440px);
}

.login-card,
.panel,
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card {
  padding: 28px;
}

.login-brand,
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand {
  margin-bottom: 22px;
}

.login-brand h1,
.page-heading h1,
.panel-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-brand h1 {
  font-size: 24px;
  line-height: 1.15;
}

.login-brand p,
.brand small,
.eyebrow,
.empty-state {
  color: var(--muted);
}

.login-brand p {
  margin: 4px 0 0;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 8px;
  background: #0f766e;
  color: #fff;
  font-weight: 800;
}

.language-switch,
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.language-switch {
  margin-bottom: 18px;
}

.language-switch a,
.topbar-user a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 700;
}

.form-stack {
  display: grid;
  gap: 16px;
}

.form-stack label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

.form-stack input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

.form-stack input:focus,
.button:focus,
.icon-button:focus,
.nav-link:focus,
.topbar-user a:focus,
.language-switch a:focus {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
  white-space: nowrap;
}

.button-primary {
  min-height: 48px;
  background: var(--primary);
  color: #fff;
}

.button-primary:hover {
  background: var(--primary-strong);
}

.button-secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.alert {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.alert p {
  margin: 0;
}

.alert-danger {
  border: 1px solid rgba(180, 35, 24, 0.25);
  background: #fff2f0;
  color: var(--danger);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  background: #16252c;
  color: #f7fbfb;
  border-inline-end: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  min-height: 54px;
  margin-bottom: 20px;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 3px;
  color: #bfd0d1;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 8px;
  color: #d8e6e7;
  font-weight: 700;
}

.nav-link:hover,
.nav-link.is-active {
  background: #22383f;
  color: #fff;
}

.content-shell {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.icon-button {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 900;
}

.topbar-user {
  margin-inline-start: auto;
}

.main-content {
  width: min(100%, 1220px);
  margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 32px) 42px;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  font-weight: 800;
  text-transform: uppercase;
  font-size: 12px;
}

.page-heading h1 {
  font-size: 28px;
  line-height: 1.2;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  padding: 18px;
  min-height: 120px;
  display: grid;
  align-content: space-between;
}

.stat-card span {
  color: var(--muted);
  font-weight: 800;
}

.stat-card strong {
  font-size: 34px;
  line-height: 1;
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
}

.panel-stack {
  display: grid;
  gap: 26px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.panel-header h2 {
  font-size: 18px;
}

.empty-state {
  margin: 0;
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 13px 14px;
  text-align: start;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  background: #f1f6f6;
  color: #344653;
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(183, 121, 31, 0.12);
  color: #7c4d12;
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
}

.pill-muted {
  background: #edf2f4;
  color: #40525f;
}

[dir="rtl"] .sidebar {
  border-inline-start: 1px solid rgba(255, 255, 255, 0.08);
  border-inline-end: 0;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(84vw, 300px);
    z-index: 20;
    transform: translateX(-105%);
    transition: transform 160ms ease;
  }

  [dir="rtl"] .sidebar {
    transform: translateX(105%);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .icon-button {
    display: inline-grid;
    place-items: center;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .auth-page {
    padding: 14px;
  }

  .login-card,
  .panel {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-user {
    justify-content: flex-end;
  }

  .topbar-user span {
    width: 100%;
    text-align: end;
  }

  .main-content {
    padding-top: 20px;
  }

  .page-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   v2 additions
   ============================================================ */

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.user-avatar {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.user-meta {
  min-width: 0;
}

.user-meta strong,
.user-meta small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-meta small {
  color: #bfd0d1;
}

.topbar-user form {
  margin: 0;
}

.topbar-user a.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.flash-stack .alert {
  margin-bottom: 0;
}

.alert-success {
  border: 1px solid rgba(15, 118, 110, 0.3);
  background: #ecfdf5;
  color: #065f46;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
}

.filter-tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 7px;
  font-weight: 700;
  color: var(--muted);
}

.filter-tabs a.is-active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(23, 33, 43, 0.08);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid label {
  display: grid;
  gap: 7px;
  font-weight: 700;
  align-content: start;
}

.form-grid label small {
  color: var(--muted);
  font-weight: 500;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

.form-grid textarea {
  min-height: 110px;
  resize: vertical;
}

.form-check {
  display: flex !important;
  grid-auto-flow: column;
  align-items: center;
  gap: 10px;
}

.form-check input {
  width: 20px;
  min-height: 20px;
  height: 20px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
}

.pill-green {
  background: rgba(15, 118, 110, 0.14);
  color: #0b5f59;
}

.pill-amber {
  background: rgba(183, 121, 31, 0.14);
  color: #7c4d12;
}

.pill-red {
  background: rgba(180, 35, 24, 0.12);
  color: #98261c;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0;
}

.inline-form select,
.inline-form input {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 8px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
}

.inline-form .button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.button-small {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.button-danger {
  border: 1px solid rgba(180, 35, 24, 0.35);
  background: #fff2f0;
  color: var(--danger);
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.table-actions a,
.table-actions .button {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.table-actions a:hover {
  background: var(--surface-soft);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin: 0;
}

.detail-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
}

.detail-grid dd {
  margin: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.photo-grid a {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-soft);
}

.photo-grid img {
  display: block;
  width: 100%;
  height: 130px;
  object-fit: cover;
}

.section-title {
  margin: 26px 0 12px;
  font-size: 18px;
}

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.quick-actions .button {
  min-height: 44px;
}

.text-muted {
  color: var(--muted);
}

.low-stock td {
  background: #fff8f7;
}

@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .inline-form {
    width: 100%;
  }
}
