/* Bilans OZE — professional B2B desktop tool styling.
   Graphite/navy workspace, amber accent, white A4 document preview. */

:root {
  --graphite-950: #0f1218;
  --graphite-900: #14181f;
  --graphite-850: #191e27;
  --graphite-800: #1e2430;
  --graphite-700: #2a3140;
  --graphite-600: #3a4254;
  --graphite-500: #545e73;
  --ink-100: #e9ecf1;
  --ink-300: #b7bfcc;
  --ink-500: #8791a3;

  --amber: #d99a3d;
  --amber-dark: #a9741f;
  --amber-soft: rgba(217, 154, 61, 0.16);

  --danger: #c0554a;
  --success: #3f8f5f;

  --font-ui: "Segoe UI", system-ui, -apple-system, "Noto Sans", sans-serif;
  --font-mono: "Consolas", "Cascadia Mono", "SFMono-Regular", Menlo, monospace;

  --radius-sm: 2px;
  --radius-md: 3px;
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must always win, even against classes further down
   this file that set their own `display` (e.g. .modal-overlay, .license-gate
   use display:flex when visible — without this rule they would show even
   while [hidden] is set, since specificity ties resolve by source order). */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink-100);
  background: var(--graphite-900);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

button {
  font-family: inherit;
}

/* ------------------------------------------------------------------ */
/* License gate                                                        */
/* ------------------------------------------------------------------ */
.license-gate {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, var(--graphite-850), var(--graphite-950));
}

.license-gate-card {
  width: 440px;
  padding: 40px 36px;
  background: var(--graphite-800);
  border: 1px solid var(--graphite-700);
  border-radius: var(--radius-md);
  text-align: center;
}

.license-gate-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--amber);
  margin-bottom: 6px;
}

.license-gate-subtitle {
  color: var(--ink-300);
  margin: 0 0 24px;
}

.license-gate-message {
  color: var(--ink-100);
  font-weight: 600;
  margin-bottom: 20px;
}

.license-gate-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.license-gate-note {
  color: var(--ink-500);
  font-size: 11.5px;
  line-height: 1.5;
  margin: 0;
}

/* ------------------------------------------------------------------ */
/* Topbar                                                              */
/* ------------------------------------------------------------------ */
.topbar {
  height: 52px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--graphite-950);
  border-bottom: 1px solid var(--graphite-700);
}

.topbar-brand {
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 15px;
  color: var(--ink-100);
}
.topbar-brand span {
  color: var(--amber);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */
.btn {
  appearance: none;
  border: 1px solid var(--graphite-600);
  background: var(--graphite-800);
  color: var(--ink-100);
  padding: 7px 14px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover {
  background: var(--graphite-700);
  border-color: var(--graphite-500);
}
.btn:active {
  transform: translateY(1px);
}
.btn-sm {
  padding: 5px 10px;
  font-size: 11.5px;
}
.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #1a1204;
  font-weight: 600;
}
.btn-primary:hover {
  background: #e5a94f;
  border-color: #e5a94f;
}
.btn-ghost {
  background: transparent;
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

/* ------------------------------------------------------------------ */
/* Workspace layout                                                    */
/* ------------------------------------------------------------------ */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.left-panel {
  width: 400px;
  min-width: 340px;
  max-width: 420px;
  background: var(--graphite-900);
  border-right: 1px solid var(--graphite-700);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-panel {
  flex: 1;
  background: #3d4148;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 28px 20px;
}

@media (max-width: 1100px) {
  .workspace {
    flex-direction: column;
  }
  .left-panel {
    width: 100%;
    max-width: none;
    border-right: none;
    border-bottom: 1px solid var(--graphite-700);
  }
}

/* ------------------------------------------------------------------ */
/* Tabs                                                                */
/* ------------------------------------------------------------------ */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 10px 10px 0;
  border-bottom: 1px solid var(--graphite-700);
  flex-shrink: 0;
}

.tab-btn {
  position: relative;
  background: transparent;
  border: none;
  color: var(--ink-300);
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tab-btn:hover {
  color: var(--ink-100);
  background: var(--graphite-800);
}
.tab-btn.active {
  color: var(--amber);
  background: var(--graphite-800);
  box-shadow: inset 0 -2px 0 var(--amber);
}

.tab-dot {
  display: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  margin-left: 6px;
  vertical-align: middle;
}
.tab-dot.visible {
  display: inline-block;
}

.tab-panels {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

/* ------------------------------------------------------------------ */
/* Form fields                                                         */
/* ------------------------------------------------------------------ */
.field {
  margin-bottom: 14px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-500);
  margin-bottom: 5px;
}

input[type="text"],
input[type="number"],
input[type="date"],
textarea,
select {
  width: 100%;
  background: var(--graphite-800);
  border: 1px solid var(--graphite-600);
  color: var(--ink-100);
  padding: 7px 9px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  font-family: inherit;
}
textarea {
  resize: vertical;
  min-height: 64px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--amber);
}

input[type="color"] {
  width: 100%;
  height: 33px;
  padding: 2px;
  background: var(--graphite-800);
  border: 1px solid var(--graphite-600);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.mono {
  font-family: var(--font-mono);
}

.field-hint {
  font-size: 11px;
  color: var(--ink-500);
  margin: 5px 0 0;
  line-height: 1.4;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  font-size: 12.5px;
  color: var(--ink-100);
  cursor: pointer;
}
.checkbox-label input {
  width: auto;
}

.financing-fields {
  border-top: 1px solid var(--graphite-700);
  padding-top: 12px;
  margin-top: 4px;
}

/* Logo */
.logo-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-preview {
  width: 84px;
  height: 84px;
  background: var(--graphite-800);
  border: 1px dashed var(--graphite-600);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  color: var(--ink-500);
  overflow: hidden;
  flex-shrink: 0;
}
.logo-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.logo-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Cost / tranches editor tables */
.cost-editor {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
}
.cost-editor th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--ink-500);
  padding: 4px 4px;
  font-weight: 500;
}
.cost-editor td {
  padding: 3px 3px;
  vertical-align: middle;
}
.cost-editor input {
  padding: 6px 7px;
  font-size: 12px;
}
.row-total {
  white-space: nowrap;
  font-size: 12px;
  color: var(--ink-300);
  padding-left: 8px;
}
.btn-icon-remove {
  background: transparent;
  border: none;
  color: var(--ink-500);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 6px;
}
.btn-icon-remove:hover {
  color: var(--danger);
}

.summary-preview {
  font-size: 11px;
  color: var(--ink-300);
  background: var(--graphite-800);
  border: 1px solid var(--graphite-700);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  line-height: 1.6;
}

.warning-inline {
  background: var(--amber-soft);
  border: 1px solid var(--amber-dark);
  color: var(--amber);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  margin-top: 4px;
}

/* License panel */
.license-info {
  background: var(--graphite-800);
  border: 1px solid var(--graphite-700);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 12px;
}
.license-info-title {
  font-weight: 700;
  color: var(--amber);
  margin-bottom: 10px;
  font-size: 14px;
}
.license-actions {
  display: flex;
  gap: 8px;
}

/* ------------------------------------------------------------------ */
/* Toasts                                                              */
/* ------------------------------------------------------------------ */
.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}
.toast {
  background: var(--graphite-800);
  border: 1px solid var(--graphite-600);
  color: var(--ink-100);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.toast-visible {
  opacity: 1;
  transform: translateY(0);
}
.toast-error {
  border-color: var(--danger);
}

/* ------------------------------------------------------------------ */
/* PWA update banner                                                   */
/* ------------------------------------------------------------------ */
.update-banner {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--graphite-800);
  border: 1px solid var(--amber);
  color: var(--ink-100);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  z-index: 1000;
  max-width: calc(100vw - 24px);
}

/* ------------------------------------------------------------------ */
/* Confirm modal                                                       */
/* ------------------------------------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}
.modal-card {
  background: var(--graphite-800);
  border: 1px solid var(--graphite-600);
  border-radius: var(--radius-md);
  padding: 20px;
  width: 360px;
}
.modal-card p {
  margin: 0 0 16px;
  color: var(--ink-100);
  font-size: 13px;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ==================================================================== */
/* A4 DOCUMENT PREVIEW                                                   */
/* ==================================================================== */
.a4-page-wrap {
  height: fit-content;
}

.a4-page {
  position: relative;
  width: 794px;
  min-height: 1123px;
  background: #ffffff;
  color: #1c1f26;
  padding: 44px 48px;
  font-family: var(--font-ui);
  font-size: 12.5px;
  line-height: 1.45;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.doc-body {
  position: relative;
  z-index: 1;
}

.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #1c1f26;
  padding-bottom: 16px;
  margin-bottom: 18px;
}
.doc-header-left {
  display: flex;
  gap: 14px;
  align-items: center;
}
.company-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
}
.company-logo-placeholder {
  border-radius: 4px;
}
.company-name {
  font-size: 16px;
  font-weight: 700;
}
.company-address {
  font-size: 11px;
  color: #444b57;
  white-space: pre-line;
  margin-top: 3px;
}
.doc-header-right {
  text-align: right;
}
.offer-badge {
  display: inline-block;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 2px;
  margin-bottom: 8px;
}
.offer-meta {
  font-size: 11px;
  color: #444b57;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}
.offer-meta strong {
  color: #1c1f26;
  font-family: var(--font-mono);
}

.doc-title-block {
  margin-bottom: 18px;
}
.doc-title-block h1 {
  font-size: 20px;
  margin: 0 0 4px;
}
.doc-subtitle {
  margin: 0;
  color: #5a6270;
  font-size: 12.5px;
}

.doc-section {
  margin-bottom: 20px;
}
.doc-section h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #5a6270;
  border-bottom: 1px solid #d8dce2;
  padding-bottom: 5px;
  margin: 0 0 10px;
}
.avoid-break {
  break-inside: avoid;
  page-break-inside: avoid;
}

.parties-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.party-name {
  font-weight: 700;
  font-size: 13px;
}
.party-detail {
  color: #444b57;
  font-size: 11.5px;
  margin-top: 2px;
}

.spec-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 20px;
}
.spec-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px dotted #e2e5ea;
  font-size: 12px;
}
.spec-label {
  color: #5a6270;
}
.spec-value {
  font-weight: 600;
}

table.cost-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}
table.cost-table thead {
  display: table-header-group;
}
table.cost-table th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  color: #5a6270;
  border-bottom: 1px solid #1c1f26;
  padding: 5px 6px;
}
table.cost-table td {
  padding: 5px 6px;
  border-bottom: 1px solid #eceef1;
  font-size: 12px;
}
table.cost-table tr {
  break-inside: avoid;
  page-break-inside: avoid;
}
.num {
  text-align: right;
}

.summary-block {
  margin-top: 6px;
  max-width: 340px;
  margin-left: auto;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px dotted #e2e5ea;
}
.summary-row.total {
  border-top: 1px solid #1c1f26;
  border-bottom: none;
  padding-top: 7px;
  margin-top: 4px;
  font-size: 13.5px;
  font-weight: 700;
}

.warning-box {
  background: #fbeee0;
  border: 1px solid #d99a3d;
  color: #7a4a13;
  padding: 8px 10px;
  border-radius: 2px;
  font-size: 11.5px;
  margin-top: 6px;
}

.fine-note {
  font-size: 10.5px;
  color: #6b7280;
  margin: 8px 0 0;
  line-height: 1.5;
}

.chart-wrap {
  width: 100%;
}
.chart-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}
.chart-caption {
  text-align: center;
  font-size: 10.5px;
  color: #6b7280;
  margin: 4px 0 10px;
}

.warranty-text {
  font-size: 12px;
  white-space: pre-line;
  color: #333a44;
}

.assumptions ul {
  margin: 0 0 10px;
  padding-left: 18px;
  font-size: 11.5px;
  color: #333a44;
}
.assumptions li {
  margin-bottom: 3px;
}
.disclaimer {
  font-size: 10px;
  color: #6b7280;
  line-height: 1.5;
  margin: 8px 0 6px;
}
.legal-note {
  font-size: 10px;
  color: #6b7280;
  font-style: italic;
  margin: 0;
}

/* Demo watermark */
.watermark-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}
.watermark-text {
  position: absolute;
  font-size: 52px;
  font-weight: 800;
  color: rgba(190, 60, 40, 0.14);
  transform: rotate(-32deg);
  white-space: nowrap;
  letter-spacing: 0.08em;
}
.demo-footer {
  position: absolute;
  bottom: 14px;
  right: 20px;
  font-size: 9.5px;
  color: #9aa1ad;
  z-index: 1;
}

/* ------------------------------------------------------------------ */
/* Mobile Edytuj/Podgląd toggle (PWA — phones show one panel at a time) */
/* Placed after the base .a4-page/.topbar rules above so these narrow-  */
/* viewport overrides actually win the cascade (same specificity, later */
/* source order), instead of being shadowed by them.                    */
/* ------------------------------------------------------------------ */
.mobile-view-toggle {
  display: none;
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .topbar-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  .topbar-actions .btn {
    flex-shrink: 0;
  }

  .mobile-view-toggle {
    display: flex;
    gap: 2px;
    padding: 8px 10px;
    background: var(--graphite-950);
    border-bottom: 1px solid var(--graphite-700);
    flex-shrink: 0;
  }
  .mobile-toggle-btn {
    flex: 1;
    appearance: none;
    border: 1px solid var(--graphite-600);
    background: var(--graphite-800);
    color: var(--ink-300);
    padding: 10px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
  }
  .mobile-toggle-btn.active {
    background: var(--amber);
    border-color: var(--amber);
    color: #1a1204;
  }

  .workspace.mode-edit .left-panel {
    display: flex;
  }
  .workspace.mode-edit .preview-panel {
    display: none;
  }
  .workspace.mode-preview .left-panel {
    display: none;
  }
  .workspace.mode-preview .preview-panel {
    display: flex;
    padding: 12px 8px;
  }

  .a4-page-wrap {
    width: 100%;
  }
  .a4-page {
    width: 100%;
    min-width: 0;
  }

  /* Comfortable touch targets for form controls (spec section 11: >=44px). */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  textarea,
  select,
  .btn {
    min-height: 44px;
  }
  input[type="color"] {
    min-height: 44px;
  }
}

/* ==================================================================== */
/* PRINT                                                                 */
/* ==================================================================== */
@media print {
  @page {
    size: A4;
    margin: 12mm;
  }
  html, body {
    background: #fff !important;
  }
  #app > *:not(.preview-panel) {
    display: none !important;
  }
  .preview-panel {
    all: unset;
    display: block;
  }
  .a4-page-wrap {
    all: unset;
  }
  .a4-page {
    box-shadow: none;
    width: auto;
    min-height: 0;
    padding: 0;
    margin: 0;
  }
  .toast-container,
  .update-banner,
  .modal-overlay {
    display: none !important;
  }
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
