/*




 
  __  __  __  __    
/\ \/\ \/\ \/\ \   
\ \ \ \ \ \ \ \ \  
 \ \ \ \ \ \ \ \ \ 
  \ \ \_/ \ \ \_/ \
   \ `\___/\ `\___/
    `\/__/  `\/__/                                 





*/

@font-face {
  font-family: "alan";
  src: url("../fonts/alan.woff2") format("woff2");
  font-weight: 300 900;
  font-display: swap;
}

:root {
  color-scheme: light;

  --font-sans: "alan", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --t-fast: 0.15s;
  --t-normal: 0.25s;
  --t-smooth: 0.35s;
  --t-spring: 0.4s;
  --e-inout: cubic-bezier(0.4, 0, 0.2, 1);
  --e-out: cubic-bezier(0, 0, 0.2, 1);
  --e-emph: cubic-bezier(0.2, 0, 0, 1);
  --e-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --bg: light-dark(#fafafa, #1a1a1a);
  --bg-elevated: light-dark(#ffffff, #2a2a2a);
  --bg-subtle: light-dark(#f3f3f3, #222222);
  --bg-muted: light-dark(#eeeeee, #333333);
  --bg-hover: light-dark(#e8e8e8, #3d3d3d);
  --bg-input: light-dark(#f0f0f0, #252525);
  --border: light-dark(#e5e5e5, #3a3a3a);
  --border-subtle: light-dark(#eeeeee, #2f2f2f);
  --border-input: light-dark(rgb(0 0 0 / 0.06), rgb(255 255 255 / 0.06));
  --border-focus: light-dark(#444444, #cccccc);
  --text: light-dark(#3d3d3d, #d8d8d8);
  --text-secondary: light-dark(#888888, #999999);
  --text-tertiary: light-dark(#aaaaaa, #6a6a6a);
  --text-muted: light-dark(#cccccc, #4a4a4a);
  --text-inverse: light-dark(#ffffff, #1a1a1a);
  --shadow: light-dark(rgb(0 0 0 / 0.04), rgb(0 0 0 / 0.2));
  --shadow-lg: light-dark(rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.4));
  --accent: light-dark(#8b5cf6, #a78bfa);
  --danger: light-dark(#ef4444, #f87171);
  --tooltip-bg: light-dark(#222222, #ffffff);
  --tooltip-fg: light-dark(#ffffff, #222222);

  &[data-theme="dark"] {
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

html {
  font-feature-settings: "ss01", "tnum";
  background: var(--bg);
}

input,
textarea,
select,
button {
  font-family: var(--font-sans);
  font-feature-settings: inherit;
}

html,
body {
  max-width: 100vw;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:is(button, a, [tabindex]):focus-visible {
  outline: 2px solid #3b82f6 !important;
  outline-offset: 2px !important;
}

textarea::-webkit-resizer {
  display: none;
}

[hidden] {
  display: none !important;
}

[popover] {
  position: absolute;
  inset: auto;
  margin: 0;
  padding: 0;
  overflow: visible;
  color: inherit;
  background: transparent;
  border: none;
}

.flex {
  display: flex;
}

.contents {
  display: contents;
}

@keyframes dropdown-expand {
  0% { opacity: 0; transform: scaleY(0.6) translateY(-4px); }
  100% { opacity: 1; transform: scaleY(1) translateY(0); }
}

.builder {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 530px) minmax(0, 520px);
  justify-content: center;
  align-content: center;
  align-items: start;
  column-gap: clamp(48px, 10vw, 170px);
  row-gap: 48px;
  padding: 64px 16px;
  background: var(--bg);
  transition: background 300ms ease;

  @media (max-width: 1100px) {
    grid-template-columns: minmax(0, 560px);
  }
}

.builder-panel {
  display: flex;
  flex-direction: column;
  min-height: 736px;

  @media (max-width: 1100px) {
    min-height: 0;
  }
}

.builder-preview {
  display: flex;
  justify-content: center;
}

.intro {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 14px 24px;
}

.divider {
  height: 1px;
  background: var(--border-subtle);
  transition: background var(--t-smooth) var(--e-inout);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;

  > .btn {
    flex-shrink: 0;
  }
}

.tabs-scroll {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
}

.tabpanel {
  padding: 16px 14px;
  flex: 1;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
}

.footer-end {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.theme-group {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 16px;
  background: var(--bg-subtle);
}

.stack {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  align-items: center;
}

.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

.spread {
  justify-content: space-between;
}

.form-divider {
  margin: 8px 0;
}

.dates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.amounts-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: 12px;
}

.items-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px 96px 32px;
  align-items: center;
  gap: 8px;
}

.text {
  font-family: var(--font-sans);
  font-weight: 400;
  color: var(--text);
  transition: color var(--t-smooth) var(--e-inout);
}

.t-sm { font-size: 12px; line-height: 1.55; letter-spacing: 0.01em; }
.t-md { font-size: 14px; line-height: 1.6; letter-spacing: 0.005em; }
.t-lg { font-size: 16px; line-height: 1.5; }

.w-medium { font-weight: 500; }

.c-secondary { color: var(--text-secondary); }
.c-tertiary { color: var(--text-tertiary); }
.c-danger { color: var(--danger); }

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 2px 6px;
  font-family: var(--font-sans);
  font-size: 10px;
  line-height: 1.4;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  box-shadow: 0 1px 0 var(--border);
  transition: all var(--t-smooth) var(--e-inout);
}

.tabs {
  position: relative;
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border-radius: 16px;
  background: var(--bg-subtle);
  transition: background var(--t-smooth) var(--e-inout);
}

.tabs-indicator {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  width: 0;
  background: var(--bg-elevated);
  border-radius: 8px;
  box-shadow: 0 1px 2px var(--shadow), 0 0 0 1px var(--border-subtle);
  opacity: 0;
  pointer-events: none;
  transition:
    left var(--t-spring) var(--e-spring),
    width var(--t-spring) var(--e-spring),
    opacity var(--t-fast) var(--e-out),
    background var(--t-smooth) var(--e-inout),
    box-shadow var(--t-smooth) var(--e-inout);
}

.tab {
  position: relative;
  z-index: 1;
  padding: 8px 16px;
  font-size: 12px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
  transition: color var(--t-normal) var(--e-inout), font-weight var(--t-normal) var(--e-inout);

  &[aria-selected="true"] {
    font-weight: 600;
    color: var(--text);
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 500;
  letter-spacing: -0.01em;
  border: none;
  border-radius: 16px;
  outline: none;
  cursor: pointer;
  transition:
    all var(--t-normal) var(--e-inout),
    box-shadow var(--t-fast) var(--e-out),
    filter var(--t-fast) var(--e-out);

  &:active:not(:disabled) {
    transform: scale(0.97);
  }

  &:disabled {
    pointer-events: none;
  }
}

.btn-md { height: 36px; padding: 8px 16px; font-size: 13px; line-height: 1.6; }
.btn-sm { height: 30px; padding: 7px 12px; font-size: 12px; line-height: 1.55; }

.btn-icon {
  display: flex;
  line-height: 1;
}

.btn-primary {
  background: var(--text);
  color: var(--text-inverse);

  &:disabled { background: var(--bg-muted); color: var(--text-muted); }
  &:hover:not(:disabled) { box-shadow: inset 0 -2px 0 0 rgb(0 0 0 / 0.35); filter: brightness(1.15); }
}

.btn-secondary {
  background: var(--bg-muted);
  color: var(--text);

  &:disabled { background: transparent; color: var(--text-muted); }
  &:hover:not(:disabled) { box-shadow: inset 0 -2px 0 0 rgb(0 0 0 / 0.05); filter: brightness(1.04); }
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--border-input);

  &:disabled { color: var(--text-muted); border-color: var(--border-subtle); }
  &:hover:not(:disabled) { box-shadow: inset 0 -2px 0 0 rgb(0 0 0 / 0.08); filter: brightness(1.12); }
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 16px;
  outline: none;
  cursor: pointer;
  transition: all var(--t-normal) var(--e-inout);

  &:hover { background: var(--bg-subtle); transform: scale(1.12); }
  &.is-active { background: var(--bg-muted); }
  &.is-active:hover { background: var(--bg-hover); }
}

.icon-btn-32 { width: 32px; height: 32px; }
.icon-btn-34 { width: 34px; height: 34px; }

.link-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 0 3px;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
  transition: all var(--t-normal) var(--e-inout);

  &::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: var(--text-tertiary);
    transform: scaleX(0);
    transform-origin: right center;
    transition: transform var(--t-normal) var(--e-emph);
  }

  &:hover::after {
    transform: scaleX(1);
    transform-origin: left center;
  }
}

.tooltip {
  position: relative;
  display: inline-flex;

  &.is-shown .tooltip-tip {
    opacity: 1;
  }
}

.tooltip-tip {
  font-family: var(--font-sans);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 6px;
  padding: 5px 10px;
  font-size: 10px;
  line-height: 1.45;
  white-space: nowrap;
  color: var(--tooltip-fg);
  background: var(--tooltip-bg);
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast) var(--e-inout);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.label {
  font-family: var(--font-sans);
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--t-smooth) var(--e-inout);
}

.input,
.textarea {
  width: 100%;
  font-size: 13px;
  line-height: 1.6;
  letter-spacing: 0.01em;
  color: var(--text);
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: 16px;
  outline: none;
  transition: all var(--t-normal) var(--e-inout);

  &:hover {
    border-color: var(--border-subtle);
  }

  &:focus {
    border-color: var(--border-focus);
  }
}

.input {
  height: 38px;
  padding: 10px 16px;
}

.textarea {
  padding: 12px 16px;
  resize: vertical;
}

.textarea-wrap {
  position: relative;
}

.grip {
  position: absolute;
  bottom: 6px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0.25;
  pointer-events: none;

  i {
    align-self: flex-end;
    height: 1px;
    background: var(--text-tertiary);
    border-radius: 1px;

    &:first-child { width: 8px; }
    &:last-child { width: 12px; }
  }
}

.input-group {
  display: flex;
  align-items: stretch;
  height: 38px;
  overflow: hidden;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: 16px;
  transition: border-color var(--t-normal) var(--e-inout), background var(--t-smooth) var(--e-inout);

  &:hover { border-color: var(--border-subtle); }
  &:focus-within { border-color: var(--border-focus); }

  input {
    flex: 1;
    min-width: 0;
    padding: 0 16px;
    font-size: 13px;
    line-height: 1.6;
    letter-spacing: 0.01em;
    color: var(--text);
    background: transparent;
    border: none;
    outline: none;
  }
}

.input-group-addon {
  font-family: var(--font-sans);
  display: flex;
  align-items: center;
  padding: 0 12px;
  font-size: 12px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  color: var(--text-tertiary);
  background: var(--bg-subtle);
  border-left: 1px solid var(--border-subtle);
  transition: all var(--t-smooth) var(--e-inout);
}

.select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 38px;
  padding: 0 16px;
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
  letter-spacing: 0.01em;
  color: var(--text);
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: 16px;
  outline: none;
  cursor: pointer;
  transition: all var(--t-normal) var(--e-inout);

  &[aria-expanded="true"] {
    border-color: var(--border-focus);

    .select-chev svg {
      transform: rotate(-90deg);
    }
  }
}

.select-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-chev {
  display: inline-flex;
  color: var(--text-tertiary);

  svg {
    transform: rotate(90deg);
    transition: transform var(--t-normal) var(--e-inout);
  }
}

.select-list {
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
  background: var(--bg-elevated);
  border-radius: 16px;
  box-shadow: 0 4px 20px var(--shadow-lg);
  transform-origin: top center;
  animation: dropdown-expand var(--t-fast) var(--e-out) both;
}

.select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
  letter-spacing: 0.01em;
  font-weight: 400;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
  transition: background var(--t-normal) var(--e-inout), color var(--t-normal) var(--e-inout);

  &[aria-selected="true"] {
    font-weight: 500;
    color: var(--text);
  }

  &.is-hover {
    background: var(--bg-subtle);
  }

  svg {
    flex-shrink: 0;
    color: var(--text-tertiary);
  }
}

.switch {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 24px;
  padding: 0;
  background: var(--bg-muted);
  border: none;
  border-radius: 12px;
  outline: none;
  cursor: pointer;
  transition: all var(--t-normal) var(--e-inout);

  &[aria-checked="true"] {
    background: var(--accent);

    .switch-knob {
      left: 22px;
      background: #ffffff;
    }
  }
}

.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--bg-elevated);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
  transition: left var(--t-spring) var(--e-spring);
}

.avatar {
  font-family: var(--font-sans);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 50%;
  font-weight: 600;
  letter-spacing: -0.02em;

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

.datepicker {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
}

.dp-control {
  position: relative;
  display: flex;
  flex-direction: column;
}

.dp-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 16px;
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
  letter-spacing: 0.01em;
  color: var(--text-tertiary);
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: 16px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--t-normal) var(--e-inout);

  &.has-value { color: var(--text); }
  &.is-clearable { padding-right: 40px; }
  &:hover:not(:disabled) { border-color: var(--border-subtle); }
  &[aria-expanded="true"],
  &[aria-expanded="true"]:hover { border-color: var(--border-focus); }
  &:disabled { cursor: default; }
}

.dp-icon {
  display: inline-flex;
  color: var(--text-tertiary);
}

.dp-text {
  flex: 1;
}

.dp-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--text-tertiary);
  background: transparent;
  border: none;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
}

.calendar {
  font-family: var(--font-sans);
  width: 260px;
  padding: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.cal-nav {
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1.6;
  letter-spacing: 0.01em;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
}

.cal-title {
  font-size: 12px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  font-weight: 500;
  color: var(--text);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-dow {
  padding: 6px 0;
  text-align: center;
  text-transform: uppercase;
  font-size: 9px;
  line-height: 1.3;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
}

.cal-day {
  padding: 6px 0;
  font-size: 12px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  font-weight: 400;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
  transition: all var(--t-fast) var(--e-inout);

  &.is-today { color: var(--accent); font-weight: 600; border-color: var(--accent); }
  &:disabled { color: var(--text-muted); cursor: default; }
  &.is-selected { color: #ffffff; font-weight: 600; background: var(--accent); border-color: transparent; }
  &.is-blank { color: transparent; }
}

.invoice-frame {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: 520px;
}

.invoice-page {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 32px;
  width: 595px;
  height: 842px;
  padding: 32px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid #e9e9ec;
  border-radius: 8px;

  p {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 10px;
    line-height: 14px;
    font-weight: 400;
    color: #545456;
  }

  .lbl { font-weight: 600; }
  .r { text-align: right; }
  .pre { white-space: pre-line; }
  .wrap { overflow-wrap: anywhere; }
  .big { font-size: 32px; line-height: 36px; }
  .number { color: #7f7f8b; }
  .bold { font-weight: 700; }
}

.invoice-placeholder {
  color: #a9a9b2;
}

.halves {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
}

.thirds {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  column-gap: 16px;
}

.cell {
  min-width: 0;
}

.rule {
  padding-top: 4px;
  border-top: 1px solid #545456;
}

.items-head {
  padding: 4px 0;
  border-bottom: 1px solid #545456;
}

.item-row {
  padding: 4px 0;

  & + & {
    border-top: 1px solid #e9e9ec;
  }
}

.sums {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.invoice-logo {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: cover;
}

.spacer {
  flex: 1;
  min-height: 0;
}

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  html,
  body,
  .builder {
    background: #fff !important;
  }

  .builder {
    display: block;
    padding: 0;
    min-height: 0;
  }

  .builder-panel {
    display: none;
  }

  .invoice-placeholder {
    display: none !important;
  }

  .invoice-frame {
    max-width: none !important;
  }

  .invoice-page {
    zoom: 1.333333 !important;
    height: 841px !important;
    border: none !important;
    border-radius: 0 !important;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}
