:root {
  --navy: #102536;
  --navy-soft: #18394f;
  --ink: #17242c;
  --muted: #68777f;
  --green: #18b765;
  --green-soft: #e6f7ee;
  --orange: #ef8d3d;
  --red: #d96060;
  --cream: #f6f2e9;
  --card: #ffffff;
  --line: #e7e4dc;
  --shadow: 0 14px 40px rgba(30, 49, 60, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--cream);
  font-family: Tahoma, Arial, sans-serif;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 250px minmax(0, 1fr);
  direction: ltr;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 26px;
  padding: 30px 22px;
  color: white;
  background:
    radial-gradient(circle at 20% 10%, rgba(40, 111, 136, 0.3), transparent 32%),
    var(--navy);
  direction: rtl;
}

.brand,
.auth-brand {
  color: white;
  font-family: Arial, sans-serif;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -1px;
}

.brand::after,
.auth-brand::after {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--green);
  content: "";
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 11px;
  padding: 0 14px;
  border-radius: 11px;
  color: #b9c7ce;
  text-decoration: none;
  transition: 0.18s ease;
}

.nav-item:hover,
.nav-item.active {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.nav-item.active {
  box-shadow: inset -3px 0 var(--green);
}

.printer-card {
  display: grid;
  gap: 7px;
  margin-top: auto;
  padding: 17px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.printer-card span,
.printer-card small {
  color: #a9bbc4;
  font-size: 11px;
}

.printer-card strong {
  font-size: 15px;
}

.logout-button {
  width: 100%;
  cursor: pointer;
  padding: 11px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 10px;
  color: #d6e0e5;
  background: transparent;
}

.workspace {
  min-width: 0;
  padding: 32px clamp(22px, 4vw, 58px) 50px;
  direction: rtl;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.today,
.topbar h1,
.topbar span {
  margin: 0;
}

.today {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.topbar h1 {
  font-size: clamp(25px, 3vw, 35px);
  letter-spacing: -0.7px;
}

.topbar > div:first-child > span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.connections {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  direction: ltr;
}

.connection-badge {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  direction: rtl;
}

.connection-badge i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a6afb3;
  box-shadow: 0 0 0 4px rgba(104, 119, 127, 0.09);
}

.connection-badge.connected i {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(24, 183, 101, 0.11);
}

.connection-badge span {
  color: var(--muted);
  font-size: 10px;
}

.connection-badge strong {
  font-size: 12px;
}

.actions-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 12px;
  margin: 26px 0 22px;
}

.search-box {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 10px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: white;
}

.search-box span {
  color: var(--muted);
  font-size: 22px;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.primary-button,
.download-button,
.secondary-button {
  display: inline-flex;
  min-height: 46px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border-radius: 12px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.primary-button {
  border: 1px solid var(--green);
  color: white;
  background: var(--green);
  box-shadow: 0 9px 22px rgba(24, 183, 101, 0.19);
}

.download-button {
  border: 1px solid var(--navy);
  color: white;
  background: var(--navy);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: white;
}

.primary-button:hover,
.download-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.full {
  width: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 15px;
  margin-bottom: 22px;
}

.stat-card {
  display: flex;
  min-height: 112px;
  align-items: center;
  gap: 15px;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 7px 25px rgba(30, 49, 60, 0.04);
}

.stat-icon {
  display: grid;
  width: 43px;
  height: 43px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  font-weight: 800;
}

.stat-icon.green {
  color: #0a9550;
  background: var(--green-soft);
}

.stat-icon.navy {
  color: white;
  background: var(--navy);
}

.stat-icon.orange {
  color: #b96724;
  background: #fff0e2;
}

.stat-icon.red {
  color: var(--red);
  background: #fdeaea;
}

.stat-card div {
  display: grid;
  gap: 5px;
}

.stat-card small {
  color: var(--muted);
  font-size: 11px;
}

.stat-card strong {
  font-family: Arial, sans-serif;
  font-size: 28px;
}

.orders-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px 17px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.panel-head h2 {
  margin: 5px 0 0;
  font-size: 21px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 4px;
  border-radius: 10px;
  background: #f3f1ec;
}

.filter {
  cursor: pointer;
  padding: 7px 11px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
}

.filter.active {
  color: var(--ink);
  background: white;
  box-shadow: 0 3px 10px rgba(30, 49, 60, 0.08);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
}

th {
  padding: 13px 17px;
  color: var(--muted);
  background: #faf9f6;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

td {
  padding: 15px 17px;
  border-top: 1px solid #efede8;
  vertical-align: middle;
  font-size: 12px;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: #fbfcfa;
}

td > strong,
td > small {
  display: block;
}

td > small,
.customer-cell small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
}

.order-number {
  color: var(--navy);
  font-family: Arial, sans-serif;
}

.customer-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.customer-cell > div {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.customer-cell strong {
  display: block;
}

.customer-cell small {
  display: block;
  margin-top: 0;
  direction: rtl;
  text-align: right;
  white-space: nowrap;
}

.customer-cell small b {
  display: inline-block;
  font-family: Arial, sans-serif;
  font-weight: 700;
  unicode-bidi: isolate;
}

.customer-cell .customer-number {
  color: #087c45;
  font-weight: 800;
}

.customer-cell > span {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #087c45;
  background: var(--green-soft);
  font-weight: 800;
}

.status-pill {
  display: inline-flex;
  padding: 6px 9px;
  border-radius: 999px;
  color: #6d7478;
  background: #eef0f1;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.new {
  color: #087c45;
  background: var(--green-soft);
}

.status-pill.preparing {
  color: #aa5d21;
  background: #fff0e2;
}

.status-pill.printed {
  color: #243a49;
  background: #e8eff3;
}

.status-pill.review {
  color: #b34848;
  background: #fdeaea;
}

.print-button {
  min-width: 72px;
  cursor: pointer;
  padding: 8px 11px;
  border: 1px solid #c9d4d9;
  border-radius: 9px;
  color: var(--navy);
  background: white;
  font-size: 11px;
  font-weight: 700;
}

.print-button:hover {
  color: white;
  background: var(--navy);
}

.print-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.empty-state {
  height: 150px;
  color: var(--muted);
  text-align: center;
}

.error-text {
  color: var(--red);
}

.modal-backdrop {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  padding: 20px;
  place-items: center;
  background: rgba(9, 24, 34, 0.58);
  backdrop-filter: blur(5px);
}

.hidden {
  display: none !important;
}

.order-modal {
  width: min(620px, 100%);
  padding: 23px;
  border-radius: 18px;
  background: white;
  box-shadow: 0 30px 90px rgba(10, 27, 38, 0.3);
}

.print-preview-dialog {
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 23px;
  border-radius: 18px;
  background: #f7f5ef;
  box-shadow: 0 30px 90px rgba(10, 27, 38, 0.3);
}

.print-preview-dialog header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.print-preview-dialog h2 {
  margin: 5px 0 0;
}

.print-preview-dialog header button {
  width: 38px;
  height: 38px;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: white;
  font-size: 24px;
}

.label-preview-wrap {
  display: grid;
  padding: 24px;
  place-items: center;
  border-radius: 15px;
  background:
    linear-gradient(45deg, #eceae4 25%, transparent 25%),
    linear-gradient(-45deg, #eceae4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eceae4 75%),
    linear-gradient(-45deg, transparent 75%, #eceae4 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.label-preview {
  width: min(80mm, 100%);
  min-height: 86mm;
  overflow: hidden;
  padding: 7mm 6mm;
  border: 1px solid #d6d3cc;
  color: #000;
  background: #fff;
  box-shadow: 0 12px 35px rgba(13, 29, 39, 0.16);
  font-family: Arial, Tahoma, sans-serif;
  direction: rtl;
}

.label-preview .label-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 3mm;
  border-bottom: 2px solid #000;
  direction: ltr;
}

.label-preview .label-brand span {
  font-size: 14px;
  font-weight: 800;
}

.label-preview .label-brand strong {
  font-size: 22px;
  font-weight: 900;
}

.label-preview small {
  display: block;
  margin-bottom: 1.5mm;
  font-size: 10px;
  font-weight: 700;
}

.label-destination {
  margin-top: 4mm;
  padding: 4mm;
  border: 2px solid #000;
  text-align: center;
}

.label-destination strong {
  display: block;
  max-width: 100%;
  font-size: 24px;
  font-weight: 900;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.label-item {
  padding: 5mm 0;
  border-bottom: 2px solid #000;
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
}

.label-item strong {
  display: block;
  min-height: 15mm;
  font-size: 21px;
  font-weight: 900;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
}

td[data-label="تفاصيل الطلب"] strong,
td[data-label="المنطقة والدفع"] strong {
  max-width: 340px;
  direction: rtl;
  text-align: right;
  unicode-bidi: plaintext;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.label-contact {
  display: grid;
  grid-template-columns: 1fr;
}

.label-customer-phone {
  margin-top: 4mm;
  padding: 4mm;
  border: 2px solid #000;
  text-align: center;
}

.label-customer-phone strong {
  display: block;
  font-size: 25px;
  font-weight: 900;
}

.label-agent {
  display: grid;
  gap: 1.5mm;
  padding: 3mm 0;
  border-bottom: 1px dashed #777;
}

.label-agent strong {
  font-size: 14px;
}

.label-agent span {
  font-size: 14px !important;
}

.label-contact > div {
  padding: 3mm 0;
  border-bottom: 1px dashed #777;
}

.label-contact strong {
  display: block;
  font-size: 15px;
}

.label-preview .label-phone {
  font-family: Arial, sans-serif;
  font-size: 18px;
  direction: ltr;
  text-align: right;
}

.label-payment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4mm;
  padding: 3mm 4mm;
  color: #fff;
  background: #000;
}

.label-payment span {
  font-size: 12px;
  font-weight: 700;
}

.label-payment strong {
  font-size: 18px;
}

.label-preview .label-date {
  padding-top: 3mm;
  color: #333;
  font-size: 11px;
  text-align: center;
}

.preview-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.order-modal header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.order-modal h2 {
  margin: 5px 0 0;
}

.order-modal header button {
  width: 38px;
  height: 38px;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: #f3f1ec;
  font-size: 24px;
}

.order-modal form,
.install-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: #4d5e67;
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #dcdedb;
  border-radius: 10px;
  outline: none;
  color: var(--ink);
  background: #fff;
}

input,
select {
  min-height: 43px;
  padding: 0 12px;
}

textarea {
  min-height: 90px;
  resize: vertical;
  padding: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(24, 183, 101, 0.09);
}

.wide {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 5px;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 24px;
  bottom: 24px;
  max-width: min(380px, calc(100vw - 48px));
  padding: 14px 18px;
  border-radius: 12px;
  color: white;
  background: var(--navy);
  box-shadow: 0 14px 40px rgba(11, 28, 39, 0.25);
  font-size: 13px;
}

.toast.error {
  background: #a83f3f;
}

.auth-body {
  display: grid;
  min-height: 100vh;
  padding: 24px;
  place-items: center;
  background:
    radial-gradient(circle at 16% 12%, rgba(24, 183, 101, 0.15), transparent 25%),
    radial-gradient(circle at 86% 84%, rgba(16, 37, 54, 0.12), transparent 25%),
    var(--cream);
}

.auth-card {
  width: min(430px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: white;
  box-shadow: var(--shadow);
}

.install-card {
  width: min(760px, 100%);
}

.auth-brand {
  margin-bottom: 34px;
  color: var(--navy);
}

.auth-card h1 {
  margin: 7px 0 8px;
  font-size: 27px;
}

.auth-subtitle {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

.auth-form {
  display: grid;
  gap: 15px;
}

.error-box,
.success-box {
  margin-bottom: 18px;
  padding: 13px 15px;
  border-radius: 11px;
  font-size: 12px;
  line-height: 1.7;
}

.error-box {
  color: #9d3333;
  background: #fdeaea;
}

.success-box {
  color: #176642;
  background: var(--green-soft);
}

.success-box h1 {
  color: var(--ink);
}

.connection-card {
  width: min(850px, 100%);
}

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

.info-grid article {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #faf9f6;
}

.info-grid article > strong {
  display: block;
  margin-bottom: 9px;
  font-size: 12px;
}

.info-grid pre {
  overflow-x: auto;
  margin: 0;
  padding: 11px;
  border-radius: 8px;
  color: #e4edf2;
  background: var(--navy);
  direction: ltr;
  font-family: Consolas, monospace;
  font-size: 11px;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
}

.info-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

@media (max-width: 1050px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .actions-row {
    grid-template-columns: 1fr 1fr;
  }

  .search-box {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 18px;
  }

  .sidebar nav {
    display: flex;
    overflow-x: auto;
  }

  .nav-item {
    flex: 0 0 auto;
  }

  .printer-card {
    margin-top: 0;
  }

  .workspace {
    padding: 24px 16px 40px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .connections {
    direction: rtl;
  }

  .panel-head {
    display: flex;
  }
}

@media (max-width: 620px) {
  .actions-row,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .search-box {
    grid-column: auto;
  }

  .order-modal form,
  .install-form {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: auto;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    overflow: visible;
  }

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

  thead {
    display: none;
  }

  tbody {
    padding: 10px;
  }

  tbody tr {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 13px;
  }

  td {
    display: grid;
    grid-template-columns: 105px 1fr;
    gap: 12px;
    padding: 9px 4px;
    border-top: 1px dashed #ece9e2;
  }

  td:first-child {
    border-top: 0;
  }

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

  .empty-state {
    display: block;
    height: auto;
    padding: 40px 12px;
  }

  .empty-state::before {
    display: none;
  }
}
