:root {
  color-scheme: light;
  --cream: #fff8ee;
  --cream-2: #fff1dc;
  --paper: #fffdfa;
  --ink: #241513;
  --muted: #7a625e;
  --line: #efd4c4;
  --orange: #ff7a1a;
  --orange-soft: #ffe3c7;
  --red: #c61618;
  --deep-red: #8d1115;
  --gold: #d8952f;
  --green: #1f8a61;
  --blue: #315a92;
  --shadow: 0 18px 42px rgba(141, 17, 21, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 122, 26, 0.08), transparent 360px),
    var(--cream);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

.hidden {
  display: none !important;
}

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

button,
label.file-button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(255, 122, 26, 0.36);
  outline-offset: 2px;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(141, 17, 21, 0.84), rgba(141, 17, 21, 0.94)),
    var(--cream);
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(100%, 390px);
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  padding: 24px;
  background: var(--paper);
  box-shadow: 0 24px 70px rgba(36, 21, 19, 0.28);
}

.login-card img {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 50%;
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
}

.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--deep-red);
  font-weight: 700;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 22px 18px;
  background:
    linear-gradient(180deg, rgba(255, 122, 26, 0.24), transparent 220px),
    var(--deep-red);
  color: #fff;
}

.brand {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.brand img {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 50%;
  background: var(--cream);
}

.brand strong,
.sidebar-status strong,
.compact-list strong,
.action-list strong,
.card-title {
  display: block;
}

.brand strong {
  font-size: 20px;
  line-height: 1.1;
}

.brand span,
.sidebar-status span {
  color: rgba(255, 255, 255, 0.74);
  font-size: 14px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.sidebar-status {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  align-items: start;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 50%;
  background: #63d690;
  box-shadow: 0 0 0 5px rgba(99, 214, 144, 0.16);
}

.dashboard {
  display: grid;
  gap: 22px;
  align-content: start;
  padding: 26px;
}

.topbar,
.panel-heading {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.topbar h1,
.panel h2 {
  margin: 0;
  line-height: 1.08;
}

.topbar h1 {
  max-width: 820px;
  font-size: 32px;
}

.panel h2 {
  font-size: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.role-chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff7ec;
  color: var(--deep-red);
  font-weight: 800;
  white-space: nowrap;
}

#import-data {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.primary-button,
.ghost-button,
.danger-button,
.file-button,
.table-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  border-color: var(--deep-red);
  background: linear-gradient(180deg, var(--red), var(--deep-red));
  color: #fff;
  font-weight: 700;
}

.ghost-button,
.file-button {
  background: #fff;
}

.danger-button {
  border-color: rgba(198, 22, 24, 0.32);
  background: #fff3f1;
  color: var(--deep-red);
}

.table-action {
  min-height: 32px;
  padding: 0 10px;
  font-size: 14px;
}

.table-action.danger {
  border-color: rgba(198, 22, 24, 0.28);
  color: var(--deep-red);
}

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

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.96);
  box-shadow: var(--shadow);
}

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 126px;
  padding: 18px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card strong {
  overflow-wrap: anywhere;
  font-size: 30px;
  line-height: 1;
}

.metric-card.attention {
  border-color: rgba(255, 122, 26, 0.42);
  background: #fff3e4;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.work-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(0, 1.55fr);
  gap: 14px;
  align-items: start;
}

.stacked-panels {
  display: grid;
  gap: 14px;
}

.span-2 {
  grid-column: span 2;
}

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

.panel-heading.compact {
  margin-bottom: 16px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segmented button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}

.segmented button.selected {
  border-color: var(--deep-red);
  background: var(--deep-red);
  color: #fff;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 6px;
}

.stats-strip div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.stats-strip span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.stats-strip strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 22px;
}

.wheat-strip {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
}

.data-form {
  display: grid;
  gap: 12px;
}

.data-form label,
.shift-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}

input::placeholder {
  color: #aa928e;
}

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

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

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.done,
.badge.paid,
.badge.ok,
.badge.income,
.badge.ordered,
.badge.taken {
  background: #e7f6ef;
  color: var(--green);
}

.badge.work,
.badge.shipped,
.badge.samples,
.badge.reserved {
  background: #eaf1fb;
  color: var(--blue);
}

.badge.planned,
.badge.wait,
.badge.expense,
.badge.waiting,
.badge.new {
  background: var(--orange-soft);
  color: #96510a;
}

.badge.low,
.badge.unpaid,
.badge.debt,
.badge.no_answer,
.badge.lost,
.badge.problem {
  background: #fff0ee;
  color: var(--deep-red);
}

.bar-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(34px, 1fr));
  gap: 7px;
  align-items: end;
  min-height: 230px;
  padding-top: 20px;
}

.bar {
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 7px;
  min-width: 0;
  height: 210px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.bar-fill {
  align-self: end;
  min-height: 7px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, var(--orange), var(--red));
}

.bar strong {
  color: var(--ink);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.action-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.action-list li,
.compact-item,
.empty-state,
.goal-card,
.shift-card,
.debt-card,
.lead-card,
.note-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.action-list span,
.compact-list span,
.empty-state,
.muted {
  color: var(--muted);
}

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

.compact-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.compact-item strong,
.compact-item span {
  overflow-wrap: anywhere;
}

.empty-cell {
  padding: 24px 10px;
  color: var(--muted);
  text-align: center;
}

.goal-board,
.shift-board,
.debt-board,
.note-board {
  display: grid;
  gap: 12px;
}

.goal-card,
.shift-card,
.debt-card,
.note-card {
  display: grid;
  gap: 10px;
}

.goal-card header,
.shift-card header,
.debt-card header,
.lead-card header,
.note-card header {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}

.progress {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: var(--cream-2);
}

.progress span {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--orange), var(--red));
}

.shift-toolbar {
  max-width: 360px;
  margin-bottom: 14px;
}

.shift-card.taken {
  border-color: rgba(31, 138, 97, 0.28);
}

.debt-card {
  border-color: rgba(198, 22, 24, 0.28);
}

.debt-card.ready {
  border-color: rgba(31, 138, 97, 0.32);
  background: #fffef8;
}

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

.lead-column {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.lead-column h3 {
  margin: 0;
  font-size: 15px;
}

.lead-card {
  display: grid;
  gap: 8px;
}

.lead-card p,
.note-card p,
.debt-card p,
.shift-card p,
.goal-card p {
  margin: 0;
  color: var(--muted);
}

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

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

  .span-2 {
    grid-column: span 2;
  }

  .lead-columns {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}

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

  .sidebar {
    position: sticky;
    z-index: 10;
    height: auto;
    max-height: none;
    padding: 12px;
  }

  .brand {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .brand img {
    width: 44px;
    height: 44px;
  }

  .brand strong {
    font-size: 18px;
  }

  .nav-list {
    display: flex;
    gap: 8px;
    margin: 0 -12px;
    padding: 0 12px 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    min-height: 38px;
    padding: 0 12px;
    white-space: nowrap;
  }

  .sidebar-status {
    display: none;
  }

  .dashboard {
    padding: 18px;
  }

  .topbar,
  .panel-heading,
  .goal-card header,
  .shift-card header,
  .debt-card header,
  .lead-card header,
  .note-card header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar h1 {
    font-size: 26px;
  }

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

  .kpi-grid,
  .overview-grid,
  .stats-strip,
  .wheat-strip,
  .lead-columns {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .bar-chart {
    overflow-x: auto;
    grid-template-columns: repeat(var(--bar-count, 7), minmax(48px, 1fr));
    padding-bottom: 6px;
  }

  .bar {
    height: 180px;
  }
}

@media (max-width: 430px) {
  .dashboard {
    padding: 14px;
  }

  .topbar-actions > * {
    flex: 1 1 auto;
  }

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

  .compact-item {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .ghost-button,
  .danger-button,
  .file-button {
    width: 100%;
  }
}
