:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef4f7;
  --surface-strong: #dfe9ee;
  --text: #15242e;
  --muted: #667783;
  --faint: #8a9aa5;
  --border: #dce5ea;
  --accent: #0f8b8d;
  --accent-strong: #0a6d71;
  --accent-soft: #dff4f2;
  --success: #168255;
  --success-soft: #e1f5ec;
  --warning: #c98212;
  --warning-soft: #fff3d9;
  --danger: #c64242;
  --danger-soft: #ffe6e6;
  --shadow: 0 18px 44px rgba(21, 36, 46, 0.08);
  --radius: 8px;
  --sidebar: 270px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 22px;
  padding: 24px 18px;
  border-right: 1px solid var(--border);
  background: #fbfdfe;
}

.brand,
.company-chip,
.sidebar-footer,
.role-notice,
.callout,
.status-row,
.settings-preview,
.inline-form,
.button-row,
.period-control,
.topbar-actions {
  display: flex;
  align-items: center;
}

.brand {
  align-items: flex-start;
  padding: 0 8px 14px;
}

.brand-logo {
  display: block;
  width: min(170px, 100%);
  height: auto;
  object-fit: contain;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 15px;
}

.brand span,
.sidebar-footer,
.eyeline,
.section-heading p,
.metric-card p,
.seller-box dt,
.role-select span,
.field span,
.result-box small {
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
  overflow-y: auto;
  padding-right: 2px;
}

.nav-group,
.nav-sublist {
  display: grid;
  gap: 4px;
}

.nav-group:not(.open) .nav-sublist {
  display: none;
}

.nav-item {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  padding: 0 10px;
  text-align: left;
}

.nav-item > span:not(.nav-chevron) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item:hover,
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.nav-parent {
  width: 100%;
}

.nav-chevron {
  display: inline-flex;
  margin-left: auto;
  transition: transform 0.16s ease;
}

.nav-group.open .nav-chevron {
  transform: rotate(180deg);
}

.nav-subitem {
  min-height: 36px;
  margin-left: 14px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  font-size: 13px;
}

.nav-subitem.active {
  border-left-color: var(--accent);
}

.sidebar-footer {
  gap: 8px;
  margin-top: auto;
  padding: 12px 10px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  background: var(--success);
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  min-height: 84px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(246, 248, 251, 0.92);
  backdrop-filter: blur(16px);
}

.eyeline {
  margin: 0 0 3px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 25px;
  line-height: 1.18;
}

h2 {
  margin-bottom: 4px;
  font-size: 17px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 5px;
  font-size: 15px;
}

p {
  line-height: 1.55;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

.company-chip {
  min-height: 42px;
  gap: 9px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.company-chip img,
.logo-preview img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
}

.role-select {
  display: grid;
  gap: 4px;
}

.role-select select,
.period-control select {
  min-width: 150px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.content {
  display: grid;
  gap: 18px;
  padding: 24px 28px 36px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.metric-card,
.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 132px;
  padding: 18px;
}

.metric-card span {
  display: block;
  min-height: 34px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin: 10px 0 8px;
  color: var(--text);
  font-size: 27px;
  line-height: 1.05;
}

.metric-card p {
  margin-bottom: 0;
}

.metric-card.success {
  border-color: #b9e9d4;
}

.metric-card.warning {
  border-color: #f3d392;
}

.metric-card.danger {
  border-color: #f0b6b6;
}

.layout-two {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.9fr);
  gap: 18px;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-heading p {
  margin-bottom: 0;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.primary-button,
.secondary-button,
.icon-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 750;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  padding: 0 14px;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
}

.secondary-button:hover,
.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.icon-button {
  width: 38px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 0;
}

.icon-button.success {
  color: var(--success);
}

.icon-button.danger {
  color: var(--danger);
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(34px, 1fr));
  gap: 9px;
  min-height: 300px;
  align-items: end;
  padding-top: 18px;
}

.bar-column {
  display: grid;
  min-width: 0;
  grid-template-rows: 28px 1fr 24px;
  gap: 7px;
  align-items: end;
  text-align: center;
}

.bar-track {
  position: relative;
  height: 210px;
  overflow: hidden;
  border-radius: 7px;
  background: var(--surface-soft);
}

.bar-fill {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  min-height: 8px;
  border-radius: 7px 7px 0 0;
  background: linear-gradient(180deg, #2cb8a7 0%, var(--accent) 100%);
}

.bar-value,
.bar-label {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-list {
  display: grid;
  gap: 10px;
}

.status-row {
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.status-row span {
  color: var(--muted);
  font-size: 13px;
}

.status-row strong {
  font-size: 13px;
  text-align: right;
}

.callout,
.role-notice {
  gap: 10px;
  padding: 13px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.callout p,
.role-notice span {
  margin: 0;
  font-size: 13px;
}

.role-notice {
  border: 1px solid #bde5e0;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

.data-table th,
.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table .strong {
  color: var(--text);
  font-weight: 800;
}

.ksef-cell {
  max-width: 210px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted-text {
  color: var(--muted);
  font-size: 12px;
}

.actions-cell {
  display: flex;
  gap: 6px;
}

.status-pill,
.mini-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill {
  min-height: 26px;
  padding: 4px 9px;
}

.status-pill.draft {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-pill.sent {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-pill.paid {
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.overdue {
  background: var(--danger-soft);
  color: var(--danger);
}

.mini-chip {
  margin: 2px;
  padding: 3px 7px;
  background: var(--surface-soft);
  color: var(--muted);
}

.form-layout,
.stacked-form {
  display: grid;
  gap: 18px;
}

.form-two {
  align-items: start;
}

.form-grid,
.filters-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.costs-filters {
  grid-template-columns: repeat(4, minmax(140px, 1fr));
}

.field {
  display: grid;
  gap: 6px;
}

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

.field span {
  font-weight: 750;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
  padding: 9px 10px;
}

.field textarea {
  resize: vertical;
}

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

.document-number {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--text);
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.seller-box {
  display: grid;
  gap: 10px;
  margin: 0;
}

.seller-box div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 12px;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.seller-box dd {
  margin: 0;
  font-size: 13px;
  font-weight: 750;
}

.editable-table input,
.editable-table select {
  width: 100%;
  min-width: 96px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  padding: 7px 8px;
}

.data-table input,
.data-table select {
  max-width: 100%;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  padding: 6px 8px;
}

.editable-table td:first-child input {
  min-width: 240px;
}

.editable-table td:first-child select {
  min-width: 220px;
}

.inline-fields {
  display: grid;
  grid-template-columns: 78px minmax(90px, 1fr);
  gap: 6px;
}

.sales-offer-table {
  min-width: 1320px;
}

.sales-table {
  min-width: 1120px;
}

.project-table {
  min-width: 1360px;
}

.project-status-map {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.project-inline-form {
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.project-inline-form .field {
  min-width: 170px;
}

.project-work-summary {
  margin-bottom: 12px;
}

.link-list {
  display: grid;
  gap: 10px;
}

.link-list div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.link-list span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.link-list strong {
  font-size: 13px;
  line-height: 1.35;
}

.document-filters {
  grid-template-columns: repeat(7, minmax(120px, 1fr));
}

.document-table {
  min-width: 1180px;
}

.service-table {
  min-width: 1280px;
}

.document-tree {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
}

.document-tree details {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.document-tree summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 800;
}

.document-tree details > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 12px 12px;
}

.folder-chip {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  padding: 4px 9px;
}

.folder-chip strong {
  color: var(--text);
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.template-button {
  display: grid;
  min-height: 98px;
  align-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.template-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.template-button span {
  font-size: 13px;
  font-weight: 800;
}

.template-button small {
  color: var(--muted);
  font-size: 12px;
}

.document-preview {
  display: grid;
  gap: 14px;
}

.document-preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.document-preview-head strong,
.document-preview-head span {
  display: block;
}

.document-preview-head > div > span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.document-frame {
  width: 100%;
  height: 380px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.image-preview {
  display: grid;
  min-height: 300px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.image-preview img {
  max-width: 100%;
  max-height: 420px;
  object-fit: contain;
}

.document-preview-empty {
  display: flex;
  min-height: 240px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  text-align: center;
}

.nowrap {
  white-space: nowrap;
}

.summary-list {
  display: grid;
  gap: 8px;
}

.summary-row {
  display: grid;
  grid-template-columns: 1fr repeat(3, minmax(100px, auto));
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 13px;
}

.summary-row span:not(:first-child),
.summary-row strong {
  text-align: right;
}

.summary-row.total {
  background: var(--text);
  color: white;
}

.totals-layout {
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.8fr);
}

.action-panel {
  align-self: stretch;
}

.button-row {
  flex-wrap: wrap;
  gap: 10px;
}

.inline-message {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.inline-message.success {
  color: var(--success);
}

.inline-message.error {
  color: var(--danger);
}

.empty-state {
  display: grid;
  min-height: 180px;
  place-items: center;
  gap: 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  margin: 0;
}

.period-control {
  flex-wrap: wrap;
  gap: 10px;
}

.period-control label {
  display: grid;
  gap: 5px;
}

.period-control span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.vat-grid {
  margin-bottom: 18px;
}

.inline-form {
  align-items: end;
  gap: 10px;
}

.inline-form .field {
  min-width: 210px;
}

.vies-form {
  flex-wrap: wrap;
}

.vies-form .field:first-child {
  min-width: 110px;
  max-width: 130px;
}

.result-box {
  margin-top: 14px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.result-box.hidden {
  display: none;
}

.result-box p {
  margin: 6px 0;
  font-size: 13px;
}

.module-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.module-tab {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  padding: 0 13px;
}

.module-tab:hover,
.module-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.warehouse-panel {
  display: grid;
  gap: 18px;
}

.warehouse-tab-content {
  align-items: start;
}

.embedded-panel {
  box-shadow: none;
}

.warehouse-table {
  min-width: 1180px;
}

.product-cell {
  display: grid;
  grid-template-columns: 46px minmax(220px, 1fr);
  gap: 10px;
  align-items: center;
}

.product-cell strong,
.product-cell span,
.product-cell small {
  display: block;
}

.product-cell span {
  margin: 2px 0;
  font-weight: 750;
}

.product-cell small {
  max-width: 360px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-photo {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-strong);
}

.product-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.settings-panel {
  max-width: 980px;
}

.settings-preview {
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.settings-preview p {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.ledger-table {
  min-width: 1320px;
}

.compact-table {
  min-width: 760px;
}

.code-preview {
  min-height: 300px;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  line-height: 1.45;
  white-space: pre;
}

.logo-preview {
  display: grid;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: white;
  color: var(--accent);
}

.logo-preview img {
  width: 54px;
  height: 54px;
}

.toast-area {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 40px));
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
}

.toast.error {
  border-left-color: var(--danger);
}

@media (max-width: 1180px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layout-two,
  .totals-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .brand {
    padding-bottom: 8px;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-group {
    grid-column: 1 / -1;
  }

  .nav-sublist {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-subitem {
    margin-left: 0;
  }

  .sidebar-footer {
    margin-top: 0;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .content {
    padding: 18px;
  }

  .dashboard-grid,
  .form-grid,
  .filters-grid,
  .costs-filters,
  .template-grid {
    grid-template-columns: 1fr;
  }

  .bar-chart {
    min-width: 680px;
  }

  .chart-panel {
    overflow-x: auto;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .inline-form .field {
    min-width: 0;
  }

  .project-status-map {
    grid-template-columns: 1fr;
  }

  .summary-row {
    grid-template-columns: 1fr;
  }

  .summary-row span:not(:first-child),
  .summary-row strong {
    text-align: left;
  }
}

@media (max-width: 520px) {
  .nav-list {
    grid-template-columns: 1fr;
  }

  .nav-sublist {
    grid-template-columns: 1fr;
  }

  .metric-card strong {
    font-size: 23px;
  }

  .company-chip {
    width: 100%;
  }
}
