:root {
  --cream: #FAF6EF;
  --ink: #1A1A1A;
  --terracotta: #C2703E;
  --terracotta-hover: #D08452;
  --terracotta-tint: #F4E3D6;
  --surface: #FFFFFF;
  --line: #E4DACB;
  --line-strong: #CFC4B3;
  --muted: #6B645B;
  --danger: #9B2C2C;
  --danger-tint: #FBECEA;
  --radius: 10px;
  --focus: #1A1A1A;
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "Inter", "Noto Sans Ethiopic", system-ui, -apple-system, "Segoe UI", Roboto, "Nyala", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1 { font-size: 24px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 20px; font-weight: 600; margin: 0 0 16px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 6px;
  z-index: 10;
}
.skip-link:focus { left: 16px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Top bar ---------- */
.topbar { background: var(--ink); color: var(--cream); }
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.whoami { font-size: 13px; color: #D9D2C6; }
.topbar-link { color: var(--cream); font-size: 14px; }
.topbar-link:hover { text-decoration: underline; }
.btn-topbar {
  background: transparent;
  color: var(--cream);
  border: 1px solid #6B645B;
}
.btn-topbar:hover { background: #2C2C2C; }

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
}
.card-center { text-align: center; margin-top: 48px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.hint { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* ---------- Login ---------- */
.login-wrap { display: flex; justify-content: center; margin-top: 48px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.login-title { font-size: 22px; }
.login-card .hint { margin-top: -8px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 12px 14px;
  font: inherit;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
}
.tab.active { color: var(--ink); border-bottom-color: var(--terracotta); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn-primary { background: var(--terracotta); color: var(--ink); }
.btn-primary:hover:not(:disabled) { background: var(--terracotta-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { background: #F4EEE4; }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: #F1EBE0; }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #D9A7A1; }
.btn-danger:hover:not(:disabled) { background: var(--danger-tint); }
.btn-push { margin-left: auto; }

/* ---------- Toolbar + filters ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.toolbar .field { min-width: 160px; }
.toolbar .grow { flex: 1 1 240px; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label:not(.check) { font-weight: 500; font-size: 14px; }
input[type="text"],
input[type="search"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
textarea { min-height: 110px; resize: vertical; }
input.readonly { background: #F1EBE0; color: var(--muted); }
input[type="file"] { font: inherit; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
  cursor: pointer;
}
.check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--terracotta); margin: 0; }

.group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px 16px;
  margin: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface);
}
.group > legend { padding: 0 6px; font-weight: 600; font-size: 14px; }

.check-row { display: flex; flex-wrap: wrap; gap: 8px 20px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { background: #F4EEE4; }

.color-list { display: flex; flex-direction: column; gap: 8px; }
.color-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px auto;
  gap: 8px;
  align-items: center;
}
.color-hex {
  width: 56px;
  height: 44px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

/* ---------- Image control ---------- */
.image-control { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.image-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.image-row input[type="text"] { flex: 1 1 240px; }
.shipped-select { flex: 0 1 220px; }
.image-preview {
  min-height: 0;
}
.image-preview-img {
  display: block;
  width: 160px;
  max-width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: 8px;
  background: #F1EBE0;
  border: 1px solid var(--line);
}

/* ---------- Product form ---------- */
.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
.wide { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  margin-top: 8px;
}
.form-errors-slot:empty { display: none; }
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin: 0 0 4px;
}
.alert-error { background: var(--danger-tint); border: 1px solid #E8B4AE; color: #7A1F1F; }
.alert-title { margin: 0 0 4px; font-weight: 600; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-error + .alert-error { margin-top: 8px; }

.editor-back { margin-bottom: 8px; padding-left: 0; }

/* ---------- Product list ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.product-table { width: 100%; border-collapse: collapse; }
.product-table th,
.product-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 14px;
}
.product-table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.product-table tbody tr:last-child td { border-bottom: 0; }
.cell-name { display: block; font-weight: 600; }
.cell-sub { display: block; color: var(--muted); font-size: 12px; }
.cell-action { text-align: right; }
.thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  background: #F1EBE0;
  display: block;
}
.thumb-empty { border: 1px dashed var(--line-strong); }
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--terracotta-tint);
  font-size: 12px;
  font-weight: 600;
}

/* ---------- Site content ---------- */
.site-form { display: flex; flex-direction: column; gap: 20px; }
.item-list { display: flex; flex-direction: column; gap: 12px; }
.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #FDFBF7;
  padding: 0 14px 14px;
}
.item > summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 600;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.item-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.item-actions { display: flex; justify-content: flex-end; }
.item-add { display: flex; }
.check-field { justify-content: center; }

/* ---------- Languages ---------- */
.lang-switch {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 3px;
  background: var(--surface);
}
.lang-btn {
  min-height: 38px;
  padding: 6px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.lang-btn:hover:not(.active) { background: #F4EEE4; color: var(--ink); }
.lang-btn.active { background: var(--ink); color: var(--cream); }

.source-hint {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.source-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 0 5px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  vertical-align: 1px;
}

.i18n-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #FDFBF7;
  padding: 0 16px;
}
.i18n-section > summary {
  cursor: pointer;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  font-size: 14px;
}
.i18n-section[open] { padding-bottom: 16px; }
.i18n-summary-hint { margin: 0; font-weight: 400; }
.i18n-fields { background: var(--surface); }
.field-label { font-weight: 500; font-size: 14px; }
.am-color-list { display: flex; flex-direction: column; gap: 8px; }
.am-color-row {
  display: grid;
  grid-template-columns: minmax(0, 180px) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
}
@media (max-width: 479px) {
  .am-color-row { grid-template-columns: minmax(0, 1fr); gap: 4px; }
}

/* Ethiopic text: no uppercase transforms or wide tracking. */
:lang(am) { font-family: "Noto Sans Ethiopic", "Inter", "Nyala", sans-serif; letter-spacing: normal; text-transform: none; }
textarea:lang(am), input:lang(am) { line-height: 1.6; }

/* ---------- Password change, account, users, history ---------- */
.pw-card { max-width: 440px; }
.stack-form { display: flex; flex-direction: column; gap: 16px; }
.stack-form h2 { margin: 0; }
.stack-form > .hint { margin-top: -8px; }
.stack-form .form-actions { margin-top: 0; border-top: 0; padding-top: 0; }
.pw-row { display: flex; gap: 8px; align-items: center; }
.pw-row input { flex: 1 1 auto; min-width: 0; }
.pw-toggle { flex: 0 0 auto; min-width: 64px; min-height: 44px; }
.intro { margin: -8px 0 16px; }

.account-summary { margin-bottom: 20px; }
.facts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin: 0; }
.facts dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.facts dd { margin: 2px 0 0; font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.account-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start; }

.user-list, .history-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.user-row, .history-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.user-main, .history-main { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-left: auto; }
.badge-warn { background: #FBEBC8; color: #6B4A00; }
.badge-you { background: var(--ink); color: var(--cream); }
.add-user { margin-top: 8px; }
.add-user .form-grid { gap: 16px; }

.temp-box {
  background: #FFF6DC;
  border: 2px solid var(--terracotta);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
}
.temp-box h2 { margin-bottom: 8px; }
.temp-label { margin: 0 0 6px; font-size: 14px; font-weight: 500; }
.temp-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.temp-code {
  flex: 1 1 220px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.04em;
  user-select: all;
  overflow-wrap: anywhere;
}
.temp-note { margin: 12px 0 0; font-weight: 500; }
.temp-box .form-actions { margin-top: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--cream);
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-size: 14px;
  z-index: 20;
}
.toast-error { background: var(--danger); color: #FFFFFF; }

/* ---------- Wide screens ---------- */
@media (min-width: 720px) {
  .container { padding: 32px 24px 80px; }
  .form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px 20px; }
  .item-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .item-body > .wide,
  .item-body > .item-actions { grid-column: 1 / -1; }
  .login-wrap { margin-top: 80px; }
  .account-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .facts { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

/* ---------- Phone: product table becomes stacked cards ---------- */
@media (max-width: 719px) {
  .table-wrap { overflow: visible; background: transparent; border: 0; }
  .product-table, .product-table tbody { display: block; width: 100%; }
  .product-table thead { display: none; }
  .product-table tr {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 6px 12px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 12px;
  }
  .product-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: 0;
    padding: 0;
    text-align: right;
  }
  .product-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: left;
  }
  .product-table td.cell-thumb { grid-row: span 3; }
  .product-table td.cell-thumb::before,
  .product-table td[data-label="Name"]::before { display: none; }
  .product-table td[data-label="Name"] { display: block; text-align: left; }
  .product-table td.cell-action { grid-column: 1 / -1; justify-content: flex-end; }
  .product-table td.cell-action::before { display: none; }
  .toolbar .field { flex: 1 1 100%; }
  .btn-push { margin-left: 0; }
  .form-actions .btn { flex: 1 1 auto; }
  .card { padding: 18px; }
  .tab { padding: 10px 12px; }
  .user-actions { margin-left: 0; width: 100%; }
  .user-actions .btn { flex: 1 1 auto; }
  .history-row .btn { flex: 1 1 100%; }
  .temp-row .btn { flex: 1 1 100%; }
  .toast { left: 16px; right: 16px; }
}
