:root {
  color-scheme: light;
  --concrete-50: #F2F0EC;
  --concrete-100: #E8E4DC;
  --concrete-200: #D8D1C5;
  --concrete-900: #26241F;
  --stone-600: #6E6A5F;
  --stone-500: #837D70;
  --surface: #FFFDF8;
  --surface-strong: #FFFFFF;
  --line: rgba(38, 36, 31, 0.16);
  --signal-orange: #E8551A;
  --signal-orange-dark: #B94316;
  --ok-green: #3E7A4D;
  --warn-red: #B6402F;
  --neutral-gray: #89847A;
  --focus: #1D6BCE;
  --shadow: 0 18px 48px rgba(38, 36, 31, 0.14);
  --soft-shadow: 0 8px 22px rgba(38, 36, 31, 0.08);
  --bottom-safe: env(safe-area-inset-bottom, 0px);
}

body.dark {
  color-scheme: dark;
  --concrete-50: #1F1E1A;
  --concrete-100: #2B2924;
  --concrete-200: #3A372F;
  --concrete-900: #F5F1E8;
  --stone-600: #BDB6A9;
  --stone-500: #A89F92;
  --surface: #282620;
  --surface-strong: #302D26;
  --line: rgba(245, 241, 232, 0.15);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  --soft-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(38, 36, 31, 0.035) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(0deg, rgba(38, 36, 31, 0.025) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--concrete-50);
  color: var(--concrete-900);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--signal-orange);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.1;
  font-family: Archivo, Inter, sans-serif;
  letter-spacing: 0;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--stone-600);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-strong);
  color: var(--concrete-900);
  padding: 10px 12px;
  font-weight: 600;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.primary-action,
.secondary-action,
.ghost-action,
.danger-action,
.icon-action {
  min-height: 44px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 10px 14px;
  font-weight: 900;
  white-space: nowrap;
}

.primary-action {
  background: var(--signal-orange);
  color: #fff;
  box-shadow: 0 8px 18px rgba(232, 85, 26, 0.24);
}

.primary-action:hover {
  background: var(--signal-orange-dark);
}

.secondary-action {
  background: color-mix(in srgb, var(--signal-orange) 10%, var(--surface));
  color: var(--signal-orange-dark);
  border-color: color-mix(in srgb, var(--signal-orange) 36%, transparent);
}

.ghost-action,
.icon-action {
  background: transparent;
  color: var(--stone-600);
  border-color: var(--line);
}

.icon-action {
  width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 24px;
}

.danger-action {
  background: color-mix(in srgb, var(--warn-red) 10%, var(--surface));
  color: var(--warn-red);
  border-color: color-mix(in srgb, var(--warn-red) 28%, transparent);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--warn-red);
  font-size: 13px;
  font-weight: 800;
}

.field-error {
  min-height: 16px;
  color: var(--warn-red);
  font-size: 12px;
  font-weight: 800;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
  line-height: 1.35;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.usage-list,
.calculation-preview,
.schedule-sheet {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface-strong) 86%, transparent);
}

.usage-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.usage-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) minmax(92px, 0.7fr) minmax(140px, 1fr) 44px;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.mini-table th,
.mini-table td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}

.muted-note {
  margin: 0;
  color: var(--stone-600);
  font-weight: 700;
}

.print-link {
  display: inline-grid;
  place-items: center;
  width: fit-content;
  text-decoration: none;
}

.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px 1fr;
}

.sidebar {
  min-height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(12px);
  overflow-y: auto;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--concrete-900);
  color: var(--concrete-50);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 900;
}

.brand small {
  display: block;
  color: var(--stone-600);
  margin-top: 3px;
}

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

.nav button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--stone-600);
  padding: 10px 12px;
  text-align: left;
  font-weight: 900;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav button i,
.nav button span {
  width: 22px;
  height: 22px;
  color: var(--signal-orange);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  text-align: center;
  flex: 0 0 22px;
}

.nav button.active,
.nav button:hover {
  background: var(--concrete-100);
  color: var(--concrete-900);
}

.sidebar .ghost-action {
  margin-top: auto;
}

.workspace {
  min-width: 0;
  padding: 22px 22px 92px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  margin: -22px -22px 18px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--concrete-50) 88%, transparent);
  backdrop-filter: blur(12px);
}

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

.breadcrumb-current {
  display: block;
  margin-top: 3px;
  color: var(--stone-600);
  font-size: 13px;
  font-weight: 800;
}

.section {
  display: none;
  width: min(100%, 1240px);
  margin-inline: auto;
}

.section.active {
  display: block;
}

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

.section-heading p {
  margin: 5px 0 0;
  color: var(--stone-600);
  font-weight: 700;
}

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

.summary-card,
.editor-panel,
.data-area,
.item-card,
.mobile-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
}

.summary-card {
  min-height: 158px;
  display: grid;
  align-content: space-between;
  gap: 12px;
  padding: 16px;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 26px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.summary-card span {
  color: var(--stone-600);
  font-weight: 900;
}

.summary-card.neutral {
  color: var(--neutral-gray);
}

.summary-card.positive {
  color: var(--ok-green);
}

.summary-card.negative {
  color: var(--warn-red);
}

.summary-card.accent {
  color: var(--signal-orange);
}

.summary-card strong,
.summary-card .summary-note,
.summary-card .sparkline {
  color: inherit;
}

.summary-note {
  margin: 0;
  color: var(--stone-600);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.35;
}

.sparkline {
  width: 100%;
  height: 22px;
  opacity: 0.68;
}

.sparkline path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.split-layout {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 16px;
  align-items: start;
}

.split-layout.active {
  display: grid;
}

.data-area {
  min-width: 0;
  overflow: hidden;
}

.toolbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

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

.content-toolbar strong,
.module-toolbar strong {
  display: block;
  font-family: Archivo, Inter, sans-serif;
  font-size: 20px;
  line-height: 1.15;
}

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

.toolbar input {
  max-width: 360px;
}

.module-toolbar {
  justify-content: space-between;
}

.module-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--concrete-50) 42%, transparent);
}

.module-filters label {
  min-width: 0;
}

.module-filters .ghost-action {
  align-self: end;
}

.module-toolbar small {
  display: block;
  margin-top: 3px;
  color: var(--stone-600);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  font-weight: 700;
}

.content-toolbar small {
  display: block;
  margin-top: 4px;
  color: var(--stone-600);
  font-size: 13px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--stone-600);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 11px;
  text-transform: uppercase;
}

td {
  font-weight: 650;
}

td.actions {
  width: 1%;
  white-space: nowrap;
}

.item-card .actions,
.mobile-card .actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.editor-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.item-list {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.item-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
}

.item-card p {
  margin: 4px 0 0;
  color: var(--stone-600);
}

.empty-state {
  padding: 28px;
  color: var(--stone-600);
  font-weight: 800;
}

.empty-state p {
  margin: 0 0 14px;
}

.mobile-card-list {
  display: none;
  padding: 12px;
  gap: 10px;
}

.mobile-card {
  padding: 14px;
}

.mobile-card header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.mobile-card strong {
  display: block;
  font-family: Archivo, Inter, sans-serif;
  font-size: 17px;
}

.mobile-card dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.mobile-card dl > div:nth-child(n + 4) {
  display: none;
}

.mobile-card.expanded dl > div {
  display: block;
}

.mobile-card dt {
  color: var(--stone-600);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.mobile-card dd {
  margin: 2px 0 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 700;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.card-more {
  width: 100%;
  margin-top: 12px;
}

.card-actions .secondary-action,
.card-actions .danger-action {
  flex: 1 1 130px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--concrete-100);
  color: var(--stone-600);
  font-size: 12px;
  font-weight: 900;
}

.status-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}

.status-ok,
.money-positive {
  color: var(--ok-green);
}

.status-warn,
.money-negative {
  color: var(--warn-red);
}

.status-active {
  color: var(--signal-orange);
}

.primary-action:disabled,
.secondary-action:disabled,
.ghost-action:disabled,
.danger-action:disabled,
.icon-action:disabled {
  cursor: wait;
  opacity: 0.58;
  box-shadow: none;
}

.stock-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--concrete-100);
  overflow: hidden;
  margin-top: 7px;
}

.stock-bar span {
  display: block;
  height: 100%;
  width: var(--stock-width, 50%);
  background: var(--ok-green);
}

.stock-bar.low span {
  background: var(--warn-red);
}

.bottom-tabs {
  display: none;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  border: 1px solid var(--line);
  border-left: 4px solid var(--signal-orange);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-weight: 800;
}

.toast.success {
  border-left-color: var(--ok-green);
}

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

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: end center;
  background: rgba(38, 36, 31, 0.36);
}

.bottom-sheet {
  width: min(640px, 100%);
  max-height: min(78vh, 720px);
  overflow: auto;
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 10px 16px 18px;
  animation: sheetIn 160ms ease-out;
}

.sheet-handle {
  width: 48px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 0 auto 12px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-body {
  display: grid;
  gap: 10px;
}

.sheet-menu {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sheet-menu button {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--concrete-900);
  font-weight: 900;
  text-align: left;
  padding: 12px;
}

@keyframes sheetIn {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .app-view {
    grid-template-columns: 232px minmax(0, 1fr);
  }

  .sidebar {
    padding: 16px;
  }

  .workspace {
    padding: 18px 18px 72px;
  }

  .topbar {
    margin: -18px -18px 18px;
    padding: 12px 18px;
  }

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

  .split-layout.active {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    display: none;
  }

  .workspace {
    padding: 14px 14px calc(96px + var(--bottom-safe));
  }

  .topbar {
    margin: -14px -14px 14px;
    padding: 12px 14px;
  }

  .bottom-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    padding: 8px 8px calc(8px + var(--bottom-safe));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(16px);
  }

  .bottom-tabs button {
    min-width: 0;
    min-height: 54px;
    display: grid;
    place-items: center;
    gap: 2px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--stone-600);
    font-size: 11px;
    font-weight: 900;
  }

  .bottom-tabs button i,
  .bottom-tabs button span {
    font-family: "IBM Plex Mono", ui-monospace, monospace;
    width: 20px;
    height: 20px;
    font-size: 18px;
    line-height: 1;
  }

  .bottom-tabs button.active {
    background: var(--concrete-100);
    color: var(--signal-orange);
  }

  h2 {
    font-size: 21px;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .topbar-actions .secondary-action {
    display: none;
  }

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

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

  .toolbar,
  .item-card {
    align-items: stretch;
    flex-direction: column;
  }

  .content-toolbar,
  .module-toolbar {
    gap: 12px;
  }

  .module-filters {
    grid-template-columns: 1fr;
  }

  .toolbar-controls {
    width: 100%;
  }

  .toolbar input {
    max-width: none;
    flex: 1 1 auto;
  }

  .two-col,
  .sheet-menu {
    grid-template-columns: 1fr;
  }

  .table-wrap table {
    display: none;
  }

  .mobile-card-list {
    display: grid;
  }

  .content-toolbar .primary-action,
  #modulePrimaryAction {
    position: fixed;
    right: 16px;
    bottom: calc(86px + var(--bottom-safe));
    z-index: 61;
    min-width: 58px;
    min-height: 50px;
    padding-inline: 16px;
    border-radius: 999px;
    box-shadow: var(--shadow);
  }

  .editor-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    max-height: 84vh;
    overflow: auto;
    border-radius: 8px 8px 0 0;
    padding-bottom: calc(18px + var(--bottom-safe));
  }

  .split-layout.active > .editor-panel {
    display: none;
  }

  .split-layout:not(.active) .editor-panel {
    display: none;
  }

  .toast-region {
    right: 10px;
    bottom: calc(86px + var(--bottom-safe));
    width: calc(100vw - 20px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
