:root {
  --black: #171717;
  --panel-black: #1d1d1d;
  --line: #2f2f2f;
  --line-soft: #4a4a4a;
  --paper: #d6d6da;
  --paper-deep: #c6c6ca;
  --sidebar: #a5a5a8;
  --sidebar-deep: #98989c;
  --text: #161616;
  --muted: #77767b;
  --accent: #b99a93;
  --accent-deep: #5a0e0b;
  --green: #2d8d3e;
  --red: #b22e2e;
  --sidebar-width: 360px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #000;
  color: var(--text);
  font-family: "Overpass", sans-serif;
}

body {
  padding: 18px 18px 28px;
}

button,
input,
select {
  font: inherit;
}

button {
  appearance: none;
}

.app-shell {
  width: min(100%, 1920px);
  margin: 0 auto;
  border: 4px solid #d5d5d8;
  background: var(--paper);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.app-header {
  position: relative;
  padding: 14px 14px 0;
  background: var(--panel-black);
  border-bottom: 4px solid var(--line-soft);
  min-height: 244px;
}

.header-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.25fr) minmax(300px, 0.8fr) minmax(360px, 1fr);
  min-height: 210px;
  border: 2px solid #6b6b6e;
}

.header-hero-panel,
.header-tools-panel,
.header-stats-panel {
  min-width: 0;
  min-height: 100%;
}

.header-hero-panel,
.header-tools-panel {
  border-right: 2px solid #6b6b6e;
}

.header-hero-panel {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 14px;
  padding: 16px 22px 14px;
}

.brand-block {
  width: min(100%, 560px);
  height: auto;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
}

.brand-lockup-image {
  width: min(100%, 560px);
  max-height: 92px;
  height: auto;
  object-fit: contain;
}

.brand-meta {
  margin: 0;
  color: #c9cab1;
  text-align: left;
  opacity: 0.92;
  line-height: 1.02;
  white-space: normal;
}

.live-meta-line {
  display: block;
}

.live-meta-date,
.live-meta-time,
.live-meta-weather {
  font-size: 1.18rem;
  font-weight: 800;
  font-variant-caps: small-caps;
  letter-spacing: 0.06em;
}

.live-meta-time {
  margin-top: 4px;
  font-size: 1.3rem;
}

.live-meta-weather {
  margin-top: 4px;
}

.header-tools-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  padding: 16px 18px 14px;
  align-items: stretch;
}

.header-calendar-card {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.02);
  padding: 10px 12px 8px;
}

.calendar-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #e1e1e5;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.calendar-nav {
  color: #c3c3c8;
  font-size: 1.05rem;
  letter-spacing: 0.22em;
}

.calendar-weekdays,
.calendar-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 7px 5px;
}

.calendar-weekdays {
  margin-top: 12px;
  color: #9d9da4;
  font-size: 0.73rem;
  font-weight: 700;
  text-align: center;
}

.calendar-days {
  margin-top: 10px;
}

.calendar-day {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 25px;
  color: #ececef;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 999px;
}

.calendar-day.is-muted {
  color: #78787f;
}

.calendar-day.is-today {
  background: #8b9dd1;
  color: #10121b;
}

.header-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.header-action-button {
  border: 1px solid #7f7f84;
  background: rgba(255, 255, 255, 0.07);
  color: #f1eeee;
  cursor: pointer;
  padding: 15px 18px;
  width: 100%;
  min-height: 58px;
  text-align: center;
  font-size: 0.98rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.12em;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.header-action-button-primary {
  background: rgba(120, 130, 92, 0.34);
  border-color: rgba(161, 169, 129, 0.42);
}

.header-action-button:hover,
.header-action-button.is-active {
  background: rgba(185, 154, 147, 0.22);
  border-color: var(--accent);
  color: #fff;
}

.header-history-button {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  gap: 4px;
}

.header-history-meta {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  font-variant-caps: small-caps;
  color: #c2b0ac;
}

.header-stats-panel {
  padding: 16px 18px 14px;
}

.header-stats-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.02);
  padding: 14px 16px;
}

.header-stats-kicker {
  margin: 0 0 12px;
  color: #cbc0bc;
  font-size: 0.88rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.16em;
}

.header-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.header-stat-card {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  padding: 12px 12px 10px;
}

.header-stat-value {
  display: block;
  color: #f2f2f5;
  font-size: 1.58rem;
  font-weight: 800;
  line-height: 1;
}

.header-stat-label {
  display: block;
  margin-top: 6px;
  color: #b7b7bb;
  font-size: 0.8rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.1em;
}

.search-frame {
  display: flex;
  align-items: stretch;
  width: 348px;
  border: 2px solid #6f6f73;
  background: #111;
  box-shadow: inset 0 0 0 1px #000;
}

.search-frame input {
  flex: 1;
  border: 0;
  background: #dfdfe4;
  color: #78767a;
  padding: 12px 22px;
  font-size: 1.05rem;
  font-style: italic;
  font-weight: 600;
  text-align: right;
}

.search-frame input:focus {
  outline: none;
}

.search-button {
  width: 54px;
  border: 0;
  border-left: 2px solid #000;
  background: #0a0a0a;
  color: #efefef;
  cursor: pointer;
}

.search-glyph {
  display: inline-block;
  font-size: 1.6rem;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, var(--sidebar-width)) 14px minmax(0, 1fr);
  min-height: 980px;
  background: var(--paper);
}

.left-rail {
  min-width: 260px;
  background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-deep) 100%);
  border-right: 1px solid var(--line);
  padding: 0 10px 16px;
}

.rail-search-section {
  padding: 14px 10px 10px;
  border-bottom: 3px solid var(--line);
}

.search-frame-rail {
  width: 100%;
}

.rail-resizer {
  position: relative;
  cursor: col-resize;
  background: linear-gradient(180deg, #bbbbbe 0%, #9d9da1 100%);
  border-right: 1px solid #5f5f63;
  border-left: 1px solid #5f5f63;
}

.rail-resizer::before {
  content: "";
  position: absolute;
  inset: 0;
  width: 2px;
  margin: 0 auto;
  background: #49494c;
}

.accordion-section {
  border-bottom: 3px solid var(--line);
}

.accordion-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 16px 8px 9px;
  color: var(--accent-deep);
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-caps: small-caps;
  letter-spacing: 0.1em;
  cursor: pointer;
  text-align: left;
}

.accordion-caret {
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid #000;
  transition: transform 180ms ease;
}

.accordion-section.is-open .accordion-caret {
  transform: rotate(180deg);
}

.accordion-body {
  display: none;
  padding: 0 10px 12px;
}

.accordion-section.is-open .accordion-body {
  display: block;
}

.option-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
  max-height: 510px;
  overflow: auto;
  padding-right: 6px;
}

.option-button {
  border: 0;
  background: transparent;
  color: #000;
  cursor: pointer;
  text-align: left;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1.1;
  padding: 0 0 0 24px;
}

.option-button.is-active {
  color: #000;
  font-style: italic;
  font-weight: 800;
}

.main-panel {
  background: var(--paper);
}

.inventory-table-frame,
.inbox-table-frame {
  height: 100%;
  overflow: auto;
}

.inventory-table,
.inbox-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--paper);
}

.inventory-table th,
.inventory-table td,
.inbox-table th,
.inbox-table td {
  border: 1px solid #353535;
  padding: 5px 8px;
  font-size: 0.83rem;
}

.inventory-table thead th,
.inbox-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #c9c9cd;
  text-align: center;
  font-size: 0.95rem;
  font-style: italic;
  font-weight: 800;
}

.inventory-table thead th {
  padding: 0;
}

.inventory-table thead th[aria-sort="ascending"] .sort-indicator::before {
  content: "▲";
}

.inventory-table thead th[aria-sort="descending"] .sort-indicator::before {
  content: "▼";
}

.sort-trigger {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 7px 18px 7px 8px;
  font-style: inherit;
  font-weight: inherit;
}

.sort-indicator {
  display: inline-block;
  min-width: 12px;
  margin-left: 5px;
  font-size: 0.68rem;
  vertical-align: middle;
}

.column-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
}

.column-resizer::after {
  content: "";
  position: absolute;
  top: 20%;
  bottom: 20%;
  right: 3px;
  width: 1px;
  background: rgba(0, 0, 0, 0.28);
}

.inventory-table td:first-child {
  text-align: center;
  font-weight: 800;
}

.inventory-table td:nth-child(2) {
  font-size: 0.98rem;
  font-weight: 800;
}

.inventory-table td:last-child,
.inbox-table td:nth-child(2),
.inbox-table td:nth-child(10) {
  white-space: nowrap;
}

.inventory-table tbody tr:hover,
.inbox-table tbody tr:hover,
.edit-row-button:hover {
  background: rgba(185, 154, 147, 0.12);
}

.inventory-table tbody tr.is-selected,
.inbox-table tbody tr.is-selected {
  background: rgba(185, 154, 147, 0.22);
}

.categories-cell {
  color: #38343a;
  font-size: 0.78rem;
  line-height: 1.2;
  white-space: normal;
  cursor: pointer;
}

.qty-positive,
.delta-add {
  color: var(--green);
}

.qty-negative,
.delta-remove {
  color: var(--red);
}

.inbox-drawer {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 20;
}

.inbox-drawer.is-open {
  display: block;
}

.inbox-drawer-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.42);
  cursor: pointer;
}

.inbox-drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(86vw, 1320px);
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--paper);
  border-left: 3px solid #2e2e31;
  box-shadow: -24px 0 48px rgba(0, 0, 0, 0.28);
}

.inbox-drawer-toolbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
  padding: 18px 24px;
  background: var(--panel-black);
  border-bottom: 3px solid #4f4f52;
}

.dashboard-return-button {
  border: 1px solid #9c9ca0;
  background: rgba(255, 255, 255, 0.05);
  color: #f2f0f0;
  cursor: pointer;
  padding: 11px 18px;
  font-size: 0.92rem;
  font-variant: small-caps;
  letter-spacing: 0.12em;
}

.inbox-drawer-heading {
  text-align: center;
  color: #f1efef;
}

.inbox-drawer-kicker {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.inbox-drawer-heading h2 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.action-overlay {
  position: fixed;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 40;
}

.action-overlay.is-open {
  display: block;
}

.action-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 36px));
  border: 2px solid #7e7e82;
  background: #ececef;
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.24);
  padding: 22px 22px 18px;
  pointer-events: auto;
}

.action-overlay.mode-space .action-panel,
.action-overlay.mode-add .action-panel,
.action-overlay.mode-edit .action-panel,
.action-overlay.mode-tag .action-panel {
  left: 50%;
}

.action-overlay.mode-remove .action-panel {
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: min(480px, calc(100vw - 36px));
}

.action-panel-copy {
  margin-bottom: 12px;
}

.action-panel-kicker {
  margin: 0 0 4px;
  color: var(--accent-deep);
  font-size: 0.82rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.12em;
}

.action-panel-copy h3 {
  margin: 0 0 6px;
  color: #141414;
  font-size: 1.3rem;
  font-weight: 700;
}

.action-panel-hint {
  margin: 0;
  color: #55555a;
  font-size: 0.92rem;
  line-height: 1.35;
}

.action-selection-label {
  min-height: 1.2em;
  margin: 0 0 10px;
  color: #2d2d32;
  font-size: 0.9rem;
  font-style: italic;
}

.action-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}

.action-overlay.mode-remove .action-form,
.action-overlay.mode-tag .action-form {
  grid-template-columns: 1fr;
}

.action-field {
  display: grid;
  gap: 5px;
}

.action-field[hidden],
.edit-row-picker[hidden],
.space-planner-placeholder[hidden] {
  display: none;
}

.action-field-full {
  grid-column: 1 / -1;
}

.action-field label,
.edit-row-picker-label {
  color: #3f3f44;
  font-size: 0.78rem;
  font-variant-caps: small-caps;
  letter-spacing: 0.08em;
}

.action-field input,
.action-field select {
  width: 100%;
  border: 2px solid #7f7f84;
  background: #fff;
  color: #101010;
  padding: 13px 14px;
  font-size: 1rem;
}

.action-field input:focus,
.action-field select:focus {
  outline: none;
  border-color: #4f4f54;
}

.action-panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.action-panel-button {
  border: 1px solid #7b7b80;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.92rem;
}

.action-panel-button-secondary {
  background: #d8d8dc;
  color: #151515;
}

.action-panel-button-primary {
  background: #111;
  color: #efefef;
}

.space-planner-placeholder {
  border: 1px dashed #7f7f84;
  background: #dfdfe3;
  color: #4b4b50;
  padding: 18px;
  text-align: center;
}

.row-context-menu {
  position: fixed;
  display: none;
  min-width: 148px;
  border: 1px solid #6f6f73;
  background: #efeff2;
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.24);
  z-index: 55;
}

.row-context-menu.is-open {
  display: block;
}

.row-context-button {
  width: 100%;
  border: 0;
  background: transparent;
  color: #171717;
  cursor: pointer;
  padding: 10px 12px;
  text-align: left;
}

.row-context-button:hover {
  background: rgba(185, 154, 147, 0.18);
}

@media (max-width: 1360px) {
  .header-grid {
    grid-template-columns: minmax(300px, 1fr) minmax(280px, 0.82fr) minmax(280px, 0.9fr);
  }

  .workspace {
    grid-template-columns: 300px 14px minmax(0, 1fr);
  }
}

@media (max-width: 1080px) {
  body {
    padding: 0;
  }

  .app-shell {
    border-width: 0;
  }

  .app-header {
    padding: 10px 10px 0;
  }

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

  .header-hero-panel,
  .header-tools-panel {
    border-right: 0;
    border-bottom: 2px solid #6b6b6e;
  }

  .header-tools-panel {
    grid-template-columns: minmax(0, 1fr) 220px;
  }

  .header-stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .left-rail {
    min-width: 0;
    border-right: 0;
    border-bottom: 3px solid var(--line);
  }

  .rail-resizer {
    display: none;
  }

  .option-grid {
    max-height: 280px;
  }

  .inbox-drawer-panel {
    width: 100vw;
  }

  .action-panel,
  .action-overlay.mode-remove .action-panel {
    left: 12px;
    right: 12px;
    top: 12px;
    width: auto;
    max-height: calc(100vh - 24px);
    overflow: auto;
    transform: none;
  }

  .action-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .header-hero-panel {
    padding: 14px 16px 12px;
  }

  .brand-lockup-image {
    width: min(100%, 460px);
  }

  .header-tools-panel {
    grid-template-columns: 1fr;
  }

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

  .header-action-button:first-child {
    grid-column: 1 / -1;
  }

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

  .live-meta-date,
  .live-meta-time,
  .live-meta-weather {
    font-size: 1.02rem;
  }
}

@media (max-width: 640px) {
  .search-frame input {
    padding: 11px 16px;
    font-size: 0.98rem;
  }

  .brand-lockup-image {
    max-height: 74px;
  }

  .header-stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .action-overlay.mode-add .action-panel,
  .action-overlay.mode-remove .action-panel,
  .action-overlay.mode-edit .action-panel,
  .action-overlay.mode-tag .action-panel,
  .action-overlay.mode-space .action-panel {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    max-height: min(92vh, 820px);
    border-width: 2px 0 0;
    border-radius: 20px 20px 0 0;
    overflow: auto;
    padding: 18px 16px calc(22px + env(safe-area-inset-bottom));
    transform: none;
  }

  .action-form {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .action-panel-copy h3 {
    font-size: 1.12rem;
  }

  .action-field input,
  .action-field select {
    padding: 15px 14px;
    min-height: 52px;
    font-size: 1rem;
  }

  .action-panel-actions {
    position: sticky;
    bottom: -18px;
    padding-top: 12px;
    padding-bottom: env(safe-area-inset-bottom);
    background: linear-gradient(180deg, rgba(236, 236, 239, 0) 0%, rgba(236, 236, 239, 0.94) 24%, #ececef 100%);
  }

  .action-panel-button {
    min-height: 48px;
    padding: 12px 14px;
  }
}
