:root {
  --bg: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --text: #18222f;
  --muted: #64748b;
  --line: #dce5ef;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #2563eb;
  --danger: #b42318;
  --warning: #b7791f;
  --ok: #157f3b;
  --shadow: 0 20px 50px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  background: #0b1722;
  color: #e5edf6;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #12b5a5;
  color: #06231f;
  font-weight: 900;
  letter-spacing: 0.5px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.sidebar-footer {
  color: #9fb0c4;
  font-size: 0.9rem;
}

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

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  color: #c9d6e5;
  background: transparent;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.sidebar-footer strong {
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 2.5vw, 2.4rem);
}

h2 {
  margin-bottom: 4px;
  font-size: 1.1rem;
}

.topbar-actions,
.toolbar,
.dialog-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.65);
}

.btn.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.file-btn input {
  display: none;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

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

.kpi {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi span {
  color: var(--muted);
  font-size: 0.9rem;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
}

.dashboard-grid,
.masters-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 18px;
}

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

.stack-list,
.master-list,
.quality-list,
.bars {
  padding: 14px;
}

.stack-item,
.master-row,
.quality-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.stack-item + .stack-item,
.master-row + .master-row,
.quality-card + .quality-card {
  margin-top: 10px;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  border-radius: 999px;
  padding: 4px 10px;
  background: #e6f4f1;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 800;
}

.badge.danger {
  background: #fdecec;
  color: var(--danger);
}

.badge.warning {
  background: #fff7df;
  color: var(--warning);
}

.badge.ok {
  background: #e8f7ee;
  color: var(--ok);
}

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 48px;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef5;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.toolbar {
  justify-content: space-between;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: min(420px, 100%);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.search span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.search input {
  flex: 1;
  min-width: 120px;
  border: 0;
  outline: 0;
  padding: 11px 0;
  background: transparent;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.row-actions,
.mini-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.link-btn,
.danger-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 800;
}

.danger-btn {
  color: var(--danger);
}

.calendar-heading input {
  width: 180px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: 1px;
  padding: 1px;
  background: var(--line);
  overflow-x: auto;
}

.day-name,
.calendar-day {
  min-height: 92px;
  padding: 10px;
  background: var(--surface);
}

.day-name {
  min-height: auto;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.calendar-day strong {
  display: block;
  margin-bottom: 8px;
}

.calendar-order {
  display: block;
  margin-top: 6px;
  border-left: 3px solid var(--primary);
  padding-left: 7px;
  color: var(--text);
  font-size: 0.82rem;
}

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

.dialog {
  width: min(560px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.dialog.wide {
  width: min(980px, calc(100vw - 28px));
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.dialog form {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

label input,
label select,
label textarea {
  color: var(--text);
  font-weight: 500;
}

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

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  padding: 12px 16px;
  background: #0b1722;
  color: #ffffff;
  box-shadow: var(--shadow);
  transition: 0.2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 4;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
  }

  .sidebar-footer {
    display: none;
  }

  .kpi-grid,
  .dashboard-grid,
  .masters-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .main {
    padding: 18px;
  }

  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .kpi-grid,
  .dashboard-grid,
  .masters-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

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