/* ==========================================================================
   TinyNetwork — Checkout Dialog Styles
   Adapted from Redesign (DeepSeek)
   ========================================================================== */

.order {
  /* Scoped tokens from Design System */
  --bg:        #080A0F;
  --surface:   #10141C;
  --surface-2: #161B26;
  --line:      #232A38;
  --line-soft: #1A2029;
  --text:      #EAF0FA;
  --text-2:    #AAB7CC;
  --text-3:    #7E8CA4;
  --text-off:  #5E6A7C;

  --acc:       #4C8DFF;
  --acc-hi:    #6BA2FF;
  --acc-ink:   #04101F;
  --acc-soft:  rgba(76, 141, 255, 0.12);

  --ok:        #2FD08A;
  --ok-soft:   rgba(47, 208, 138, 0.12);
  --warn:      #F0B429;
  --warn-soft: rgba(240, 180, 41, 0.12);
  --bad:       #F0685C;
  --bad-soft:  rgba(240, 104, 92, 0.12);

  --r-sm:   10px;
  --r-md:   14px;
  --r-lg:   20px;
  --r-pill: 999px;

  --s-1: 4px;   --s-2: 8px;   --s-3: 12px;  --s-4: 16px;
  --s-5: 24px;  --s-6: 32px;  --s-7: 48px;  --s-8: 64px;  --s-9: 96px;

  --font: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --sh-acc: 0 10px 30px -12px rgba(76, 141, 255, 0.5);

  font-family: var(--font);
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  direction: rtl;
  text-align: right;

  margin: auto;
  width: min(520px, calc(100vw - 24px));
  max-height: min(96dvh, 880px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  box-shadow: 0 40px 80px -32px rgba(0, 0, 0, 0.92);
  z-index: 9999;
}

.order[open] { display: flex; flex-direction: column; }
.order::backdrop { background: rgba(3, 5, 9, 0.72); }
html:has(dialog.order[open]) { overflow: hidden; }

@media (max-width: 560px) {
  .order {
    width: 100%; max-width: none;
    margin: 0;
    max-height: 100dvh; height: 100dvh;
    border: 0; border-radius: 0;
  }
  .order-body { padding: var(--s-5); }
}

.order-form { display: flex; flex-direction: column; min-height: 0; }

.order-head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) var(--s-4) var(--s-2) var(--s-5);
  border-bottom: 1px solid var(--line-soft);
}
.order-head h2 { font-size: 16px; font-weight: 700; margin: 0; }
.order-step { font-size: 12px; color: var(--text-3); margin-inline-start: auto; white-space: nowrap; }
.order-close {
  flex: none; width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.order-close:hover { color: var(--text); border-color: #35405a; }
.order-close svg { width: 15px; height: 15px; }

.order-progress { height: 3px; background: var(--line-soft); }
.order-progress i { display: block; height: 100%; width: 50%; background: var(--acc); transition: width 0.35s var(--ease); }

.order-body {
  min-height: 0; overflow-y: auto;
  padding: var(--s-3) var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-4);
}
.order-step-panel { display: flex; flex-direction: column; gap: var(--s-3); }
.order-step-panel[hidden] { display: none !important; }

/* ---- cart rows ---- */
.order-items { display: flex; flex-direction: column; gap: var(--s-3); }
.order-item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3);
  background: var(--surface);
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
}
.order-item img {
  flex: none; width: 52px; height: 52px; padding: 4px;
  object-fit: contain; background: #0D1119; border-radius: var(--r-sm);
}
.order-item .oi-info { flex: 1 1 auto; min-width: 0; }
.order-item .oi-info b { display: block; font-size: 13.5px; line-height: 1.5; color: var(--text); }
.order-item .oi-info small { font-size: 12.5px; color: var(--text-2); }
.order-item .oi-drop {
  flex: none; width: 44px; height: 44px;
  display: grid; place-items: center;
  background: none; border: 0; color: var(--text-3);
  font-size: 18px; cursor: pointer;
}
.order-item .oi-drop:hover { color: var(--bad); }

.stepper { display: inline-flex; align-items: center; flex: none; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.stepper button {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--surface-2); border: 0; color: var(--text);
  font-size: 17px; line-height: 1; cursor: pointer;
}
.stepper button:hover:not(:disabled) { background: #1B2130; }
.stepper button:disabled { color: var(--text-off); cursor: not-allowed; }
.stepper output { min-width: 34px; text-align: center; font-size: 14px; font-weight: 700; color: var(--text); }

/* ---- add another device (disclosure, not a <select>) ---- */
.add-item { display: flex; flex-direction: column; gap: var(--s-2); }
.add-item[hidden] { display: none !important; }

.add-toggle {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; min-height: 48px; padding: 0 var(--s-4);
  background: transparent;
  border: 1px dashed #526180; border-radius: var(--r-md);
  color: var(--acc); font: inherit; font-size: 13.5px; font-weight: 700;
  cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.add-toggle:hover { border-color: var(--acc); background: var(--acc-soft); }
.add-toggle > svg:first-child { width: 16px; height: 16px; flex: none; }
.add-toggle .chev { margin-inline-start: auto; width: 16px; height: 16px; flex: none; color: var(--text-3); transition: transform 0.25s var(--ease); }
.add-toggle[aria-expanded='true'] .chev { transform: rotate(180deg); }

.add-list {
  display: flex; flex-direction: column; gap: var(--s-2);
  padding: var(--s-2);
  background: var(--surface-2);
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
}
.add-list[hidden] { display: none !important; }

.add-opt {
  display: flex; align-items: center; gap: var(--s-3);
  width: 100%; min-height: 56px; padding: var(--s-2) var(--s-3);
  background: var(--surface);
  border: 1px solid var(--line-soft); border-radius: var(--r-sm);
  color: var(--text); font: inherit; text-align: start; cursor: pointer;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.add-opt:hover { border-color: var(--acc); background: var(--acc-soft); }
.add-opt img {
  flex: none; width: 40px; height: 40px; padding: 3px;
  object-fit: contain; background: #0D1119; border-radius: 8px;
}
.add-opt .ao-info { flex: 1 1 auto; min-width: 0; }
.add-opt .ao-info b { display: block; font-size: 13px; line-height: 1.45; color: var(--text); }
.add-opt .ao-info small { font-size: 12px; color: var(--text-2); }
.add-opt .ao-plus {
  flex: none; width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  color: var(--acc);
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}
.add-opt:hover .ao-plus { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.add-opt .ao-plus svg { width: 14px; height: 14px; }
.add-empty { padding: var(--s-3); font-size: 12.5px; color: var(--text-3); text-align: center; }

/* ---- price breakdown ---- */
.bill {
  display: flex; flex-direction: column; gap: var(--s-2);
  margin: 0; padding: var(--s-4);
  background: var(--surface);
  border: 1px solid var(--line-soft); border-radius: var(--r-md);
}
.bill > div { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); font-size: 13.5px; }
.bill dt { color: var(--text-2); font-weight: normal; }
.bill dd { margin: 0; font-weight: 600; color: var(--text); }
.bill .ok { color: var(--ok); }
.bill-total { margin-top: var(--s-1); padding-top: var(--s-3); border-top: 1px solid var(--line-soft); }
.bill-total dt { color: var(--text); font-weight: 700; font-size: 14.5px; }
.bill-total dd { font-size: 19px; font-weight: 800; color: var(--text); }

.order-note { font-size: 12.5px; color: var(--text-3); margin: 0; line-height: 1.6; }

/* ---- step 2 recap ---- */
.order-recap {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: 3px var(--s-3);
  background: var(--surface-2); border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--text);
}
.order-recap b { font-weight: 700; }
.linkish {
  flex: none;
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px;
  background: none; border: 0;
  color: var(--acc); font: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer; border-radius: 6px;
}
.linkish:hover { text-decoration: underline; }

/* ---- fields ---- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--text-2); line-height: 1.4; }
.field > label .opt { font-weight: 400; color: var(--text-3); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px;
  padding: 10px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: 15px; line-height: 1.35;
  font-family: inherit;
  box-sizing: border-box;
  transition: border-color 0.2s var(--ease);
}
.field textarea { min-height: 60px; resize: vertical; line-height: 1.6; }
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); }
.field select { cursor: pointer; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #35405a; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  border-color: var(--acc); outline: 2px solid var(--acc); outline-offset: 1px;
}
.field .ltr { direction: ltr; text-align: end; }
.field-row { display: grid; gap: var(--s-4); grid-template-columns: 1fr; }
@media (min-width: 520px) { .field-row.cols-2 { grid-template-columns: 1fr 1fr; } }

.field.is-bad input, .field.is-bad select, .field.is-bad textarea { border-color: var(--bad); }
.field-err { font-size: 12.5px; line-height: 1.4; color: var(--bad); margin: 0; }
.field-err:empty { display: none; }

.form-alert {
  padding: var(--s-2) var(--s-4);
  background: var(--bad-soft);
  border: 1px solid rgba(240, 104, 92, 0.3);
  border-radius: var(--r-sm);
  font-size: 13.5px; line-height: 1.5; color: var(--bad);
}
.form-alert[hidden] { display: none !important; }
.form-alert p { margin: 0; font-weight: 700; }
.form-alert ul { margin: var(--s-1) 0 0; padding-inline-start: 18px; }
.form-alert li + li { margin-top: 2px; }
.form-alert a { text-decoration: underline; color: inherit; }

/* ---- buttons scoped to dialog ---- */
.order .btn {
  --btn-bg: transparent;
  --btn-fg: var(--text);
  --btn-line: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 48px; padding: 0 22px;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-line);
  border-radius: var(--r-sm);
  font-size: 15px; font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease),
              transform 0.12s var(--ease), box-shadow 0.2s var(--ease);
}
.order .btn:hover { transform: translateY(-1px); }
.order .btn:active { transform: translateY(0); }

.order .btn-primary {
  --btn-bg: var(--acc); --btn-fg: var(--acc-ink); --btn-line: transparent;
  box-shadow: var(--sh-acc);
}
.order .btn-primary:hover { --btn-bg: var(--acc-hi); }

.order .btn-ghost { --btn-bg: var(--surface-2); --btn-line: var(--line); }
.order .btn-ghost:hover { --btn-line: #35405a; --btn-bg: #1B2130; }

.order .btn[aria-busy="true"], .order .btn:disabled { opacity: 0.7; cursor: not-allowed; }

/* ---- footer ---- */
.order-foot {
  display: flex; gap: var(--s-3);
  padding: var(--s-2) var(--s-5);
  border-top: 1px solid var(--line-soft);
  background: var(--surface);
}
.order-foot .btn { flex: 1 1 0; min-width: 0; }
.order-foot .btn-primary { flex: 2 1 0; }
.order-foot [hidden] { display: none !important; }

.order-gateway {
  display: flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 0 var(--s-5) var(--s-2);
  margin: 0;
  font-size: 12px; color: var(--text-3);
  background: var(--surface);
}
.order-gateway svg { width: 15px; height: 15px; flex: none; color: var(--ok); }

/* ---- local demo result ---- */
.order-demo {
  padding: var(--s-4);
  background: var(--warn-soft);
  border: 1px solid rgba(240, 180, 41, 0.3);
  border-radius: var(--r-sm);
  font-size: 13.5px;
}
.order-demo p + p { margin-top: var(--s-2); }
.order-demo code {
  font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: rgba(0, 0, 0, 0.35);
  padding: 1px 5px; border-radius: 4px;
}
.order-payload {
  margin: 0; padding: var(--s-4);
  background: #0A0D13;
  border: 1px solid var(--line-soft); border-radius: var(--r-sm);
  font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.7;
  color: var(--text-2);
  direction: ltr; text-align: start;
  overflow-x: auto; white-space: pre;
}

.sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
