:root {
  --card: #ffffff;
  --line: #d7e0e8;
  --text: #1f2937;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-2: #0b5f58;
  --danger: #b91c1c;
  --ok: #166534;
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(10px, env(safe-area-inset-left));
  --safe-right: max(10px, env(safe-area-inset-right));
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
}

body {
  font-family: "Cairo", sans-serif;
  color: var(--text);
  background: #fff;
  min-height: 100dvh;
  overflow-x: hidden;
}

.bg-shape,
.mobile-preview-toggle {
  display: none;
}

.layout {
  width: 100%;
  max-width: 420px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--safe-top) var(--safe-right) calc(var(--safe-bottom) + 10px) var(--safe-left);
}

.hidden {
  display: none !important;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.login-panel {
  margin-top: 10vh;
  padding: 18px 14px;
}

.panel-head h1,
.topbar h2,
.products-head h3,
.pages-panel h3 {
  margin: 0;
  font-size: 1.24rem;
  line-height: 1.35;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--primary);
}

.sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.6;
}

.form-grid {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

label {
  font-weight: 700;
  font-size: 0.96rem;
}

input,
textarea,
select,
button {
  font-family: inherit;
  font-size: 16px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  min-height: 46px;
  padding: 10px 12px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #14b8a6;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18);
}

.btn {
  border: none;
  border-radius: 12px;
  min-height: 46px;
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
}

.btn-ghost {
  background: #e6f4f3;
  color: #115e59;
}

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
}

.status {
  min-height: 1.4rem;
  margin-top: 8px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.92rem;
}

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--ok);
}

.dashboard,
.app-view {
  display: grid;
  gap: 10px;
}

.view-tabs {
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.view-tab {
  min-height: 40px;
  padding: 8px 6px;
  font-size: 0.8rem;
}

.view-tab.is-active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 8px 10px 8px 84px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.topbar-actions {
  position: absolute;
  left: 8px;
  top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "refresh logout"
    "store menu";
  align-items: center;
  justify-content: flex-start;
  column-gap: 8px;
  row-gap: 3px;
}

#refresh-btn { grid-area: refresh; }
#logout-btn { grid-area: logout; }
#open-store-link { grid-area: store; }
.menu-btn { grid-area: menu; }

#open-store-link {
  text-decoration: none;
}

.topbar > div:first-child {
  min-width: 0;
}

.topbar .eyebrow {
  margin: 0 0 2px;
  font-size: 0.7rem;
}

.topbar h2 {
  font-size: 1.07rem;
}

#current-user {
  margin-top: 2px;
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 10px;
  font-size: 16px;
  line-height: 1;
  position: relative;
}

.icon-btn > span {
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.icon-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 50%;
  bottom: calc(100% + 7px);
  transform: translateX(50%);
  background: #0f172a;
  color: #fff;
  font-size: 0.76rem;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.icon-btn:hover::after,
.icon-btn:focus-visible::after {
  opacity: 1;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 25;
}

.menu-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(280px, 82vw);
  height: 100dvh;
  background: #ffffff;
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(15, 23, 42, 0.18);
  z-index: 30;
  transform: translateX(110%);
  opacity: 0;
  pointer-events: none;
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1), opacity 180ms ease;
  padding: calc(var(--safe-top) + 8px) 12px 12px;
}

.menu-drawer.is-open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.menu-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.menu-drawer-head h3 {
  margin: 0;
  font-size: 1rem;
}

.menu-links {
  display: grid;
  gap: 8px;
}

.menu-links .btn {
  justify-content: flex-start;
  min-height: 42px;
}

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

.stat-card {
  padding: 10px;
}

.stat-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.stat-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.05rem;
}

.products-panel,
.pages-panel {
  padding: 12px;
}

.products-head {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.inline-tools,
.quick-actions {
  display: grid;
  gap: 8px;
}

.quick-actions {
  margin-top: 10px;
}

.quick-actions .btn {
  min-height: 42px;
}

.orders-overview-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 6px;
}

.order-mini-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  background: #fff;
  display: grid;
  gap: 2px;
}

.order-mini-card span {
  font-size: 0.74rem;
  color: var(--muted);
  font-weight: 700;
}

.order-mini-card strong {
  font-size: 0.92rem;
}

.status-new { background: #eff6ff; }
.status-preparing { background: #fff7ed; }
.status-transit { background: #f0fdfa; }
.status-done { background: #ecfccb; }
.status-finished { background: #f5f3ff; }
.status-cancelled { background: #fef2f2; }

.orders-list-wrap {
  margin-top: 10px;
}

.orders-list-wrap h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.orders-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.orders-list-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  display: grid;
  gap: 5px;
}

.orders-list-main {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.orders-list-code {
  font-weight: 800;
  font-size: 0.88rem;
}

.orders-list-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.orders-list-empty {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.table-wrap {
  border: none;
  background: transparent;
}

table,
thead,
tbody,
tr,
td {
  display: block;
  width: 100%;
}

thead {
  display: none;
}

tbody {
  display: grid;
  gap: 8px;
}

tr {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  padding: 8px;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
}

td {
  border: none;
  border-bottom: 1px dashed #e8eef2;
  padding: 8px 4px;
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  align-items: start;
  gap: 6px;
  font-size: 0.98rem;
}

td:last-child {
  border-bottom: none;
}

td::before {
  content: attr(data-label);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.85rem;
}

.empty-row {
  text-align: center;
  color: var(--muted);
  padding: 10px 4px;
}

.empty-row::before {
  content: none;
}

.tag {
  display: inline-block;
  border-radius: 999px;
  font-size: 0.82rem;
  padding: 4px 10px;
}

.tag-active { background: #dcfce7; color: #166534; }
.tag-deleted { background: #fef3c7; color: #92400e; }
.tag-status-new { background: #dbeafe; color: #1d4ed8; }
.tag-status-preparing { background: #ffedd5; color: #c2410c; }
.tag-status-transit { background: #ccfbf1; color: #0f766e; }
.tag-status-done { background: #dcfce7; color: #166534; }
.tag-status-finished { background: #ede9fe; color: #5b21b6; }
.tag-status-cancelled { background: #fee2e2; color: #b91c1c; }

.row-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.row-actions .btn {
  width: 100%;
  min-height: 44px;
}

/* Compact mode for product cards only */
#products-body {
  gap: 4px;
}

#products-body tr {
  border-radius: 10px;
  padding: 5px 6px;
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.05);
}

#products-body td {
  grid-template-columns: 58px minmax(0, 1fr);
  padding: 5px 1px;
  gap: 3px;
  font-size: 0.9rem;
}

#products-body td::before {
  font-size: 0.74rem;
}

#products-body .tag {
  font-size: 0.7rem;
  padding: 2px 7px;
}

#products-body .row-actions {
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}

#products-body .row-actions .btn {
  min-height: 30px;
  padding: 4px 7px;
  font-size: 0.78rem;
  border-radius: 8px;
}

.products-pagination {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
}

.products-pagination .btn {
  min-height: 34px;
  font-size: 0.84rem;
  padding: 6px 8px;
}

.products-page-info {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.product-dialog {
  width: min(420px, 100vw);
  max-width: 100vw;
  margin: 0 auto;
  border: none;
  border-radius: 16px 16px 0 0;
  padding: 0;
  background: transparent;
}

.product-dialog[open] {
  position: fixed;
  inset: auto 0 0 0;
}

.product-dialog::backdrop {
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(3px);
}

.dialog-card {
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}

.dialog-head {
  margin-bottom: 10px;
}

.dialog-head h3 {
  margin: 0;
  font-size: 1.18rem;
}

.dialog-actions {
  position: sticky;
  bottom: -14px;
  margin: 10px -14px -14px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: #fff;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

@media (min-width: 600px) {
  .layout {
    max-width: 430px;
  }
}

/* ── Order Dialog ─────────────────────────────────── */

.order-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.order-dialog-header h3 {
  margin: 0 0 2px;
  font-size: 1.1rem;
}

.order-change-wrap {
  margin-top: 14px;
  display: grid;
  gap: 6px;
}

.order-timeline-wrap {
  margin-top: 14px;
}

.order-stepper {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(92px, 1fr);
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 6px;
  margin-bottom: 6px;
  scrollbar-width: thin;
}

.order-step {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
}

.order-step::after {
  content: '';
  position: absolute;
  top: 8px;
  left: -50%;
  width: 100%;
  height: 2px;
  background: var(--line);
  z-index: 0;
}

.order-step:first-child::after {
  display: none;
}

.order-step-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #fff;
  z-index: 1;
}

.order-step.is-done .order-step-dot {
  border-color: var(--ok);
  background: var(--ok);
}

.order-step.is-current .order-step-dot {
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.14);
}

.order-step-label {
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--text);
}

.order-step-time {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
}

.order-step.is-pending .order-step-label,
.order-step.is-pending .order-step-time {
  opacity: 0.7;
}

.order-timeline-title {
  margin: 0 0 10px;
  font-size: 0.9rem;
  color: var(--muted);
}

.order-timeline {
  list-style: none;
  margin: 0;
  padding: 0 18px 0 0;
  position: relative;
}

.order-timeline::before {
  content: '';
  position: absolute;
  right: 6px;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--line);
}

.order-timeline-item {
  position: relative;
  padding-bottom: 14px;
}

.order-timeline-item:last-child {
  padding-bottom: 0;
}

.order-timeline-dot {
  position: absolute;
  right: -18px;
  top: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--line);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--line);
}

.order-timeline-item--current .order-timeline-dot {
  background: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

.order-timeline-content {
  display: grid;
  gap: 2px;
}

.order-timeline-label {
  display: flex;
  align-items: center;
}

.tag--small {
  font-size: 0.75rem;
  padding: 2px 8px;
}

.order-timeline-at {
  font-size: 0.78rem;
  color: var(--muted);
}

.order-timeline-note {
  font-size: 0.82rem;
  color: var(--text);
}

.order-timeline-empty {
  font-size: 0.88rem;
  color: var(--muted);
}

.orders-list-item--clickable {
  cursor: pointer;
  transition: background 0.15s ease;
}

.orders-list-item--clickable:active {
  background: #f0fdfa;
}

.pages-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 4px;
}

.pages-actions .btn {
  min-height: 36px;
  font-size: 0.82rem;
  padding: 6px 8px;
}

@media (max-width: 360px) {
  .topbar {
    padding: 8px;
    gap: 6px;
  }

  .topbar h2 {
    font-size: 1rem;
  }

  #current-user {
    font-size: 0.8rem;
  }

  .topbar-actions {
    gap: 6px;
  }

  .view-tabs {
    grid-template-columns: 1fr 1fr;
  }

  .view-tab {
    font-size: 0.78rem;
  }

  .icon-btn {
    width: 30px;
    min-width: 30px;
    height: 30px;
    min-height: 30px;
    font-size: 16px;
  }

  .icon-btn > span {
    font-size: 16px;
  }
}
