/* Decaweb Tools — editor chrome (screen only); tokens match decaweb.ir */
@font-face {
  font-family: "Modam";
  src: url("../../assets/fonts/Modam-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Modam";
  src: url("../../assets/fonts/Modam-Medium.ttf") format("truetype");
  font-weight: 500 600;
  font-display: swap;
}
@font-face {
  font-family: "Modam";
  src: url("../../assets/fonts/Modam-Bold.ttf") format("truetype");
  font-weight: 700 900;
  font-display: swap;
}

:root {
  --ui-bg: #0f0f10;
  --ui-panel: #171719;
  --ui-panel-2: #1d1d20;
  --ui-border: #29292c;
  --ui-border-strong: #343438;
  --ui-text: #f7f7f4;
  --ui-muted: #a2a2a6;
  --ui-accent: #e45d1a;
  --ui-accent-hover: #f06a24;
  --ui-input: #141416;
  --ui-radius: 0;
  --ui-font: "Modam", Tahoma, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased;
}
/* Lock viewport scroll only on the invoice tool, not the Tools hub */
@media (min-width: 981px) {
  html:has(body > .app),
  body:has(> .app) {
    height: 100%;
    overflow: hidden;
  }
}

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

.app {
  height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: rgb(15 15 16 / 95%);
  border-bottom: 1px solid var(--ui-border);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 0;
  background: var(--ui-accent);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  flex: 0 0 auto;
}

.brand-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand-sub {
  display: block;
  font-size: 11px;
  color: var(--ui-muted);
  font-weight: 500;
  margin-top: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  appearance: none;
  border: 1px solid var(--ui-border-strong);
  background: var(--ui-panel);
  color: var(--ui-text);
  border-radius: 0;
  min-height: 44px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.btn:hover { border-color: #5a5a60; background: var(--ui-panel-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 3px;
}
.btn-primary {
  background: var(--ui-accent);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover {
  background: var(--ui-accent-hover);
  border-color: transparent;
  transform: translateY(-2px);
}
.btn-primary:active { transform: translateY(0); }
.btn-ghost {
  background: transparent;
  border-color: var(--ui-border-strong);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 18px 0;
  border-bottom: 1px solid var(--ui-border);
  background: var(--ui-bg);
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ui-muted);
  padding: 10px 14px;
  border-radius: 0;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab[aria-selected="true"] {
  color: var(--ui-text);
  border-bottom-color: var(--ui-accent);
  background: var(--ui-panel);
}

.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.panel {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.editor-panel {
  background: var(--ui-panel);
  border-left: 1px solid var(--ui-border);
  padding: 18px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.preview-panel {
  background: #e8e8e8;
  padding: 24px 16px 48px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  position: sticky;
  top: 0;
}

.archive-panel {
  grid-column: 1 / -1;
  background: var(--ui-bg);
  padding: 24px 18px 48px;
  display: none;
}

.app[data-view="archive"] .app-body {
  grid-template-columns: 1fr;
}
.app[data-view="archive"] .editor-panel,
.app[data-view="archive"] .preview-panel { display: none; }
.app[data-view="archive"] .archive-panel { display: block; }

.app[data-view="preview"] .editor-panel { display: none; }
.app[data-view="preview"] .app-body { grid-template-columns: 1fr; }

.section {
  background: var(--ui-panel-2);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  padding: 14px;
  margin-bottom: 14px;
}

.section h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 800;
}

.field-grid {
  display: grid;
  gap: 10px;
}

.field-grid.two {
  grid-template-columns: 1fr 1fr;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ui-muted);
}

.field input,
.field textarea,
.field select {
  width: 100%;
  background: var(--ui-input);
  border: 1px solid var(--ui-border);
  border-radius: 0;
  padding: 9px 11px;
  outline: none;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--ui-accent);
}

.field textarea {
  min-height: 72px;
  resize: vertical;
  line-height: 1.6;
}

.item-card {
  border: 1px solid var(--ui-border);
  border-radius: 0;
  padding: 12px;
  background: var(--ui-input);
  margin-bottom: 10px;
}

.item-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.item-card-head span {
  font-size: 12px;
  font-weight: 700;
  color: var(--ui-muted);
}

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

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}

.toggle-row p {
  margin: 0;
  font-size: 12px;
  color: var(--ui-muted);
  line-height: 1.5;
}

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex: 0 0 auto;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.switch span {
  position: absolute;
  inset: 0;
  background: #2a3140;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.switch span::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  top: 3px;
  right: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
}

.switch input:checked + span { background: var(--ui-accent); }
.switch input:checked + span::after { transform: translateX(-18px); }

.archive-list {
  display: grid;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
}

.archive-empty {
  text-align: center;
  color: var(--ui-muted);
  padding: 48px 16px;
}

.archive-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--ui-panel);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
}

.archive-card strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}

.archive-card span {
  font-size: 12px;
  color: var(--ui-muted);
}

.archive-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.preview-scale-wrap {
  width: min(210mm, 100%);
  margin: 0 auto;
}

/* Hide editor chrome when printing — allow multi-page A4 flow */
@media print {
  html,
  body,
  .app {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }
  .app-header,
  .tabs,
  .editor-panel,
  .archive-panel,
  .deca-promo,
  .deca-promo--bar,
  .export-gate,
  .toast,
  .menu {
    display: none !important;
  }
  .app-body,
  .preview-panel,
  .panel {
    display: block !important;
    height: auto !important;
    max-height: none !important;
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    position: static !important;
    border: 0 !important;
  }
  .app[data-view="edit"] .preview-panel,
  .app[data-view="archive"] .preview-panel {
    display: block !important;
  }
  .app[data-view="archive"] .archive-panel,
  .app[data-view="edit"] .editor-panel,
  .app[data-view="preview"] .editor-panel {
    display: none !important;
  }
  .preview-scale-wrap {
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
  }
  .invoice-page {
    box-shadow: none !important;
  }
}

@media (min-width: 981px) {
  .app-header,
  .tabs {
    flex-shrink: 0;
  }
  /* Invoice column stays put while the edit form scrolls */
  .preview-panel {
    position: sticky;
    top: 0;
    align-self: stretch;
  }
}

@media (max-width: 980px) {
  .app {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }
  .app-body {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .editor-panel,
  .preview-panel {
    position: static;
    overflow: visible;
  }
  .editor-panel { border-left: 0; border-bottom: 1px solid var(--ui-border); }
  .app[data-view="edit"] .preview-panel { display: none; }
  .app[data-view="preview"] .editor-panel { display: none; }
  .field-grid.two { grid-template-columns: 1fr; }
}

/* Light theme for editor chrome — matches decaweb.ir light */
html[data-theme="light"] {
  --ui-bg: #f7f7f4;
  --ui-panel: #ffffff;
  --ui-panel-2: #f0efeb;
  --ui-border: #d9d8d3;
  --ui-border-strong: #c9c8c3;
  --ui-text: #171719;
  --ui-muted: #5d5d62;
  --ui-accent: #c84e12;
  --ui-accent-hover: #e45d1a;
  --ui-input: #ffffff;
}
html[data-theme="light"] .app-header {
  background: rgb(247 247 244 / 95%);
}
html[data-theme="light"] .preview-panel {
  background: #ecebe7;
}
html[data-theme="light"] .btn-primary {
  color: #fff;
  background: #e45d1a;
}
html[data-theme="light"] .btn-primary:hover {
  background: #f06a24;
}

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  min-width: 240px;
  padding: 6px;
  background: var(--ui-panel);
  border: 1px solid var(--ui-border);
  border-radius: 0;
  box-shadow: 0 12px 36px rgb(0 0 0 / 30%);
  z-index: 80;
  display: none;
}
.menu.open,
.menu:not([hidden]) {
  display: grid !important;
  gap: 2px;
}
.menu[hidden] {
  display: none !important;
}
.menu button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ui-text);
  text-align: right;
  padding: 9px 10px;
  border-radius: 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
.menu button:hover { background: var(--ui-panel-2); }

.brand-upload {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px dashed var(--ui-border);
  border-radius: 0;
  background: var(--ui-input);
}
.brand-upload-preview {
  width: 88px;
  height: 64px;
  border-radius: 0;
  border: 1px solid var(--ui-border);
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.brand-upload-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.brand-upload-preview span {
  font-size: 11px;
  color: var(--ui-muted);
  text-align: center;
  padding: 4px;
}
.brand-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.brand-upload input[type="file"] { display: none; }
.hint {
  margin: 0;
  font-size: 11px;
  color: var(--ui-muted);
  line-height: 1.5;
}
.section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: #171719;
  border: 1px solid var(--ui-border-strong);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0;
  font-size: 13px;
  font-weight: 700;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.toast.show { opacity: 1; }
/* Screen chrome helper; printed mark sizing lives in invoice-sheet.css */

/* —— Decaweb Tools hub / chrome —— */
.tools-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}
.tools-brand-logo {
  display: block;
  height: 14px;
  width: auto;
}
.tools-brand-logo--light { display: none; }
.tools-brand-logo--dark { display: block; }
html[data-theme="light"] .tools-brand-logo--light { display: block; }
html[data-theme="light"] .tools-brand-logo--dark { display: none; }
.tools-brand-divider {
  width: 1px;
  height: 16px;
  background: var(--ui-border);
  flex: 0 0 auto;
}
.tools-brand-product {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--ui-muted);
}
.tools-brand--compact .tools-brand-logo { height: 12px; }
.tools-brand--compact .tools-brand-product { font-size: 12px; }

.brand--tools {
  gap: 12px;
  align-items: center;
}
.brand-crumb {
  color: var(--ui-border);
  font-weight: 700;
}
.brand-tool { min-width: 0; }

.tools-hub-body {
  overflow: auto !important;
  height: auto !important;
}
.tools-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--ui-bg);
}
.tools-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--ui-border);
  background: rgb(15 15 16 / 95%);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}
html[data-theme="light"] .tools-topbar {
  background: rgb(247 247 244 / 95%);
}
.tools-hero {
  width: min(1080px, calc(100% - 40px));
  margin: 0 auto;
  padding: 56px 0 40px;
  flex: 1;
}
.tools-kicker {
  margin: 0 0 10px;
  color: var(--ui-accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tools-hero h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.tools-lead {
  margin: 14px 0 0;
  max-width: 54ch;
  color: var(--ui-muted);
  font-size: 15px;
  line-height: 1.75;
  font-weight: 500;
}
.tools-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 36px;
}
.tool-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 18px;
  border-radius: 0;
  border: 1px solid var(--ui-border);
  background: var(--ui-panel);
  text-decoration: none;
  color: inherit;
  min-height: 132px;
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}
a.tool-card:hover {
  border-color: var(--ui-border-strong);
  transform: translateY(-2px);
  background: var(--ui-panel-2);
}
.tool-card--soon {
  opacity: 0.72;
}
.tool-card-icon {
  width: 44px;
  height: 44px;
  border-radius: 0;
  display: grid;
  place-items: center;
  background: rgb(228 93 26 / 14%);
  color: var(--ui-accent);
  flex: 0 0 auto;
}
.tool-card--soon .tool-card-icon {
  background: rgb(154 163 181 / 12%);
  color: var(--ui-muted);
}
.tool-card-body { min-width: 0; flex: 1; }
.tool-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.tool-card h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}
.tool-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ui-muted);
  font-weight: 500;
}
.tool-badge {
  font-size: 11px;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 0;
  background: rgb(228 93 26 / 16%);
  color: var(--ui-accent);
  white-space: nowrap;
}
.tool-badge--muted {
  background: rgb(154 163 181 / 14%);
  color: var(--ui-muted);
}
.tools-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 18px;
  color: var(--ui-muted);
  font-size: 12px;
  font-weight: 600;
  border-top: 1px solid var(--ui-border);
}
@media (max-width: 900px) {
  .tools-grid { grid-template-columns: 1fr; }
  .tools-hero { padding-top: 36px; }
  .brand--tools { flex-wrap: wrap; }
}

/* —— Decaweb Shop Builder promo banner —— */
.deca-promo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 28px;
  padding: 22px 24px;
  border-radius: 0;
  border: 1px solid var(--ui-border);
  background: var(--ui-panel-2);
}
.deca-promo-copy {
  min-width: 0;
  flex: 1;
}
.deca-promo-eyebrow {
  margin: 0 0 6px;
  color: var(--ui-accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.deca-promo h2 {
  margin: 0;
  font-size: clamp(18px, 2.4vw, 24px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.35;
}
.deca-promo-copy > p:last-child {
  margin: 8px 0 0;
  color: var(--ui-muted);
  font-size: 13px;
  line-height: 1.7;
  font-weight: 500;
  max-width: 62ch;
}
.deca-promo-cta {
  flex: 0 0 auto;
  white-space: nowrap;
}

.deca-promo--bar {
  margin: 0;
  padding: 10px 18px;
  border-radius: 0;
  border: 0;
  border-bottom: 1px solid rgb(228 93 26 / 28%);
  flex-shrink: 0;
  gap: 12px;
}
.deca-promo--bar .deca-promo-copy {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  font-size: 13px;
  line-height: 1.5;
}
.deca-promo--bar .deca-promo-copy strong {
  font-weight: 800;
}
.deca-promo--bar .deca-promo-copy span {
  color: var(--ui-muted);
  font-weight: 500;
}
.deca-promo-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.deca-promo--bar[hidden] {
  display: none !important;
}

/* Export gate — Decaweb shop promo before download */
.export-gate[hidden] {
  display: none !important;
}
.export-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(15 15 16 / 72%);
  backdrop-filter: blur(8px);
}
.export-gate-card {
  width: min(440px, 100%);
  background: var(--ui-panel);
  border: 1px solid var(--ui-border-strong);
  padding: 28px 24px;
  box-shadow: 0 24px 70px rgb(0 0 0 / 40%);
}
.export-gate-eyebrow {
  margin: 0 0 10px;
  color: var(--ui-accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.export-gate-card h2 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.45;
  color: var(--ui-text);
}
.export-gate-card p {
  margin: 14px 0 0;
  color: var(--ui-muted);
  font-size: 0.95rem;
  line-height: 1.75;
}
.export-gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}
.export-gate-actions .btn {
  flex: 1 1 140px;
}
.export-gate-actions .btn-ghost {
  flex: 0 1 auto;
}

@media print {
  .deca-promo,
  .deca-promo--bar,
  .export-gate {
    display: none !important;
  }
}

@media (max-width: 900px) {
  .deca-promo {
    flex-direction: column;
    align-items: stretch;
  }
  .deca-promo-cta,
  .deca-promo-actions {
    width: 100%;
  }
  .deca-promo-actions .btn {
    flex: 1;
  }
  .deca-promo--bar {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 14px;
  }
}
