:root {
  --ink: var(--platform-text, #e8eaef);
  --muted: var(--platform-text-muted, #94a3b8);
  --line: var(--platform-border, #2a3140);
  --paper: var(--platform-bg, #0b0d12);
  --panel: var(--platform-surface, #161a22);
  --accent: var(--platform-accent, #0284c7);
  --accent-soft: var(--platform-accent-soft, rgba(2, 132, 199, 0.14));
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 14px;
  --ok: #34d399;
  --bad: #fb7185;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(2, 132, 199, 0.18), transparent 55%),
    radial-gradient(ellipse 40% 35% at 0% 100%, rgba(52, 211, 153, 0.07), transparent 50%),
    linear-gradient(168deg, #0b1016 0%, var(--paper) 50%, #0c1218 100%);
  background-attachment: fixed;
}

.shell {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0 3rem;
}

.app-top {
  margin-bottom: 0.85rem;
}

.app-top a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.app-top a:hover {
  text-decoration: underline;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(18, 23, 31, 0.7);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}

.btn:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.btn.primary:hover {
  background: var(--platform-accent-hover, #0369a1);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  border-color: rgba(251, 113, 133, 0.45);
  color: #fda4af;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 23, 31, 0.72);
  backdrop-filter: blur(8px);
  padding: 1rem 1.05rem 1.15rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar .spacer {
  flex: 1;
}

.tabs {
  display: inline-flex;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.2);
  margin-bottom: 1rem;
}

.tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--ink);
}

label.field {
  display: grid;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0f131a;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  padding: 0.65rem 0.75rem;
}

textarea {
  min-height: 8rem;
  resize: vertical;
  line-height: 1.45;
  font-family: var(--font);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-grid {
  display: grid;
  gap: 0.75rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

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

.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.85rem;
}

.hub-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 1.05rem 1.1rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid rgba(58, 74, 96, 0.85);
  border-top: 3px solid var(--card-accent, var(--accent));
  background: rgba(18, 23, 31, 0.65);
  color: inherit;
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.hub-card:hover {
  transform: translateY(-2px);
  border-color: var(--card-accent, var(--accent));
}

.hub-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.hub-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 650;
}

.status-pill.ok {
  color: var(--ok);
  border-color: rgba(52, 211, 153, 0.4);
}

.status-pill.warn {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.4);
}

.layout-2 {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.list button,
.list .row {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(42, 49, 64, 0.9);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  color: inherit;
  font: inherit;
  padding: 0.7rem 0.8rem;
  cursor: pointer;
}

.list button.active {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
  background: var(--accent-soft);
}

.list strong {
  display: block;
  font-size: 0.92rem;
}

.list span {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  text-align: left;
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid rgba(42, 49, 64, 0.75);
  vertical-align: top;
}

.table th {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.badge.sent,
.badge.ok {
  color: var(--ok);
  border-color: rgba(52, 211, 153, 0.4);
}

.badge.failed,
.badge.bad {
  color: var(--bad);
  border-color: rgba(251, 113, 133, 0.4);
}

.preview {
  white-space: pre-wrap;
  font-family: var(--font);
  line-height: 1.5;
  padding: 0.85rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(42, 49, 64, 0.8);
  min-height: 8rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 50;
  background: #1a2230;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
}

.toast[hidden] {
  display: none;
}

.hint-box {
  margin: 0 0 1rem;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid rgba(2, 132, 199, 0.35);
  background: rgba(2, 132, 199, 0.08);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.hint-box code {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink);
}

.layout-editor {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.doc-sheet {
  background: #f8fafc;
  color: #0f172a;
  border-radius: 12px;
  padding: 1.5rem 1.6rem;
  min-height: 20rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.doc-sheet h2,
.doc-sheet h3 {
  margin: 0 0 0.5rem;
  color: #0f172a;
  font-family: "Libre Baskerville", Georgia, serif;
}

.doc-sheet p,
.doc-sheet li {
  color: #1e293b;
  line-height: 1.5;
}

.doc-sheet .muted-ink {
  color: #64748b;
  font-size: 0.88rem;
}

.doc-sheet table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.doc-sheet th,
.doc-sheet td {
  border-bottom: 1px solid #cbd5e1;
  padding: 0.45rem 0.35rem;
  text-align: left;
}

.doc-sheet th {
  color: #64748b;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.doc-sheet .totals {
  margin-left: auto;
  width: min(16rem, 100%);
}

.doc-sheet .totals td {
  border: 0;
  padding: 0.25rem 0;
}

.doc-sheet .totals tr:last-child td {
  font-weight: 700;
  font-size: 1.05rem;
  padding-top: 0.45rem;
}

.num {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.86rem;
}

.line-actions {
  display: flex;
  gap: 0.35rem;
}

.line-actions .btn {
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  padding: 0.75rem 0.85rem;
}

.stat .label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat .value {
  margin-top: 0.25rem;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.sig-preview {
  background: #fff;
  color: #111;
  border-radius: 10px;
  padding: 1rem 1.1rem;
  min-height: 8rem;
}

.table input,
.table select {
  min-width: 0;
  padding: 0.4rem 0.5rem;
  font-size: 0.88rem;
}

.table .narrow {
  width: 5.5rem;
}

.table .mid {
  width: 7.5rem;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid rgba(42, 49, 64, 0.6);
}

.check-row input[type="checkbox"] {
  width: auto;
  margin-top: 0.2rem;
}

@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }

  .platform-chrome,
  .app-top,
  .platform-page-intro,
  .toolbar,
  .tabs,
  .no-print,
  .layout-editor > .panel:first-child,
  .layout-2 > .panel:first-child {
    display: none !important;
  }

  .shell {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .doc-sheet,
  .sig-preview {
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    background: #fff;
    color: #000;
  }

  .print-only-block {
    display: block !important;
  }
}

@media (max-width: 860px) {
  .layout-2,
  .layout-editor,
  .form-row {
    grid-template-columns: 1fr;
  }
}
