:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #131a2a;
  --muted: #5d677c;
  --line: #dde2ec;
  --primary: #1f4fd8;
  --primary-text: #ffffff;
  --primary-soft: #e6edff;
  --ok: #12805c;
  --ok-soft: #dff5ec;
  --warn: #9a6200;
  --warn-soft: #fdf0d3;
  --bad: #c0362c;
  --bad-soft: #fde6e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 14px rgb(16 24 40 / 5%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1320;
    --surface: #171e2e;
    --surface-2: #1f283b;
    --text: #edf0f7;
    --muted: #9aa5bb;
    --line: #2a3449;
    --primary: #6f93ff;
    --primary-text: #0b1226;
    --primary-soft: #1c2a52;
    --ok: #4ed3a3;
    --ok-soft: #12362b;
    --warn: #f0be5a;
    --warn-soft: #3a2d10;
    --bad: #ff8a80;
    --bad-soft: #43201d;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

.shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- header and navigation ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  flex: 1;
  min-width: 0;
}

.brand img {
  width: 34px;
  height: 34px;
  border-radius: 9px;
}

.account {
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 45%;
  direction: ltr;
}

main {
  flex: 1;
  padding: 4px 16px 110px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tabs {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 5;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabs-inner {
  max-width: 560px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.tab {
  background: none;
  border: 0;
  padding: 9px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
  position: relative;
}

.tab svg {
  width: 24px;
  height: 24px;
}

.tab[aria-current="page"] {
  color: var(--primary);
  font-weight: 700;
}

.tab .dot {
  position: absolute;
  top: 6px;
  inset-inline-start: calc(50% + 8px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--primary);
  color: var(--primary-text);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 18px;
}

/* ---------- building blocks ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.grow {
  flex: 1;
  min-width: 0;
}

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

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}

.btn.big {
  width: 100%;
  min-height: 54px;
  font-size: 1.08rem;
  font-weight: 700;
}

.btn.ghost {
  border-color: transparent;
  background: none;
  color: var(--primary);
  padding-inline: 8px;
}

.btn.danger {
  color: var(--bad);
}

.btn.small {
  min-height: 36px;
  padding: 5px 12px;
  font-size: 0.87rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 8px 12px;
  font-weight: 400;
  color: var(--text);
}

:is(input, select, button, .choice, .file-pick):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}

.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.pill.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.pill.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill.bad {
  background: var(--bad-soft);
  color: var(--bad);
}

.pill.busy {
  background: var(--primary-soft);
  color: var(--primary);
}

.notice {
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  background: var(--warn-soft);
  color: var(--warn);
}

.empty {
  text-align: center;
  padding: 36px 16px;
}

.empty svg {
  width: 56px;
  height: 56px;
  color: var(--muted);
  margin-bottom: 8px;
}

.empty h2 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.empty .btn {
  margin-top: 16px;
}

/* ---------- print tab ---------- */

.file-pick {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px 16px;
  cursor: pointer;
  width: 100%;
  text-align: start;
}

.file-pick.has-file {
  border-style: solid;
  border-color: var(--primary);
  background: var(--primary-soft);
}

.file-pick svg {
  width: 36px;
  height: 36px;
  color: var(--primary);
  flex: none;
}

.file-pick strong {
  display: block;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: start;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 52px;
  cursor: pointer;
}

.choice[aria-checked="true"] {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.choice .radio {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  flex: none;
}

.choice[aria-checked="true"] .radio {
  border: 6px solid var(--primary);
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  min-height: 46px;
}

.stepper button {
  border: 0;
  background: var(--surface-2);
  width: 46px;
  align-self: stretch;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
}

.stepper output {
  flex: 1;
  text-align: center;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  min-height: 46px;
}

.segmented button {
  border: 0;
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.87rem;
  white-space: nowrap;
  padding: 0 4px;
  color: var(--muted);
}

.segmented button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--primary-text);
}

.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress i {
  display: block;
  height: 100%;
  background: var(--primary);
  transition: width 0.15s;
}

/* ---------- lists ---------- */

.item-title {
  font-weight: 700;
}

.printer-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.92rem;
}

.printer-list li {
  display: flex;
  gap: 8px;
  align-items: center;
}

.printer-list svg {
  width: 18px;
  height: 18px;
  color: var(--muted);
  flex: none;
}

.actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.code-input {
  direction: ltr;
  text-align: center;
  font: 700 1.5rem/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

ol.steps {
  margin: 0;
  padding-inline-start: 20px;
  font-size: 0.92rem;
  color: var(--muted);
}

.error-text {
  color: var(--bad);
  font-size: 0.87rem;
}

/* ---------- sign-in ---------- */

.auth {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 24px 20px;
}

.auth-head {
  text-align: center;
}

.auth-head img {
  width: 76px;
  height: 76px;
  border-radius: 20px;
}

.auth-head h1 {
  font-size: 1.6rem;
  margin-top: 8px;
}

/* ---------- toast ---------- */

#toast {
  position: fixed;
  inset-inline: 16px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

#toast span {
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.92rem;
  max-width: 480px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 25%);
}

@media (prefers-reduced-motion: no-preference) {
  .pill.busy::before {
    animation: pulse 1.2s ease-in-out infinite;
  }
  @keyframes pulse {
    50% {
      opacity: 0.25;
    }
  }
}

.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
}

.server-line {
  text-align: center;
}
