:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #687583;
  --line: #dbe3ea;
  --brand: #1f7a6d;
  --brand-dark: #145b52;
  --accent: #bc5d2e;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(29, 42, 57, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

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

button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
  white-space: normal;
}

button:hover {
  background: var(--brand-dark);
}

button.secondary,
button.ghost {
  background: #e8eef1;
  color: var(--ink);
}

button.secondary:hover,
button.ghost:hover {
  background: #d9e3e8;
}

button.danger {
  background: #fde8e6;
  color: var(--danger);
}

button.danger:hover {
  background: #fbd0cb;
}

button.warning {
  background: #fff3d6;
  color: #7a4b00;
}

button.warning:hover {
  background: #ffe4a3;
}

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

input[type="color"] {
  padding: 4px;
}

textarea {
  min-height: 92px;
  padding: 12px;
  resize: vertical;
}

label {
  display: grid;
  gap: 7px;
  color: #394755;
  font-size: 13px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.shell {
  min-height: 100vh;
}

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

.login-panel {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-panel h1,
.topbar h1,
.panel h2,
.sidebar h2 {
  margin: 0;
  letter-spacing: 0;
}

.eyebrow,
.muted {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.stack {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.system-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafb;
  color: #405061;
  font-size: 13px;
  font-weight: 700;
  margin-top: 20px;
  padding: 10px 12px;
}

.system-status.ok {
  border-color: #b8dec8;
  background: #ecf8f1;
  color: #17643a;
}

.system-status.warning {
  border-color: #efc5b0;
  background: #fff4ec;
  color: #8a421f;
}

.system-status.error {
  border-color: #efb4ae;
  background: #fff0ee;
  color: var(--danger);
}

.status-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 999px;
  background: currentColor;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  min-height: 100vh;
  min-width: 0;
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 24px;
}

.sidebar > * {
  min-width: 0;
}

.sidebar nav {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.nav-item {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  color: #344252;
  text-align: left;
}

.nav-item.active {
  background: #dff0ec;
  color: #0f5c52;
}

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

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

.role-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  background: #fff3e8;
  color: #8a421f;
  font-size: 13px;
  font-weight: 700;
  padding: 0 12px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(29, 42, 57, 0.06);
  padding: 22px;
  margin-bottom: 18px;
  min-width: 0;
}

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

.panel-head.compact {
  margin-bottom: 14px;
}

.panel-head h3 {
  margin: 0;
}

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

.metrics article {
  min-height: 110px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metrics strong {
  display: block;
  margin-top: 16px;
  color: var(--brand-dark);
  font-size: 34px;
}

.metrics .metric-text {
  font-size: 22px;
  line-height: 1.2;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f7fafb;
  color: #405061;
  margin-top: 18px;
  padding: 18px;
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  gap: 14px;
  align-items: end;
  margin-bottom: 20px;
}

.filter-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 14px;
  align-items: end;
  margin-bottom: 20px;
}

.check-row {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

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

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

.form-actions button {
  flex: 1 1 160px;
}

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

.row-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.wide-field {
  grid-column: 1 / -1;
}

.manager-layout {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.rights-panel {
  margin-top: 18px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
}

.calendar-day {
  min-height: 128px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.calendar-day.muted-day {
  background: #f7fafb;
  color: var(--muted);
}

.calendar-date {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.calendar-item {
  display: block;
  border-radius: 6px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  margin-top: 6px;
  padding: 6px 8px;
}

.registry-result {
  display: grid;
  gap: 16px;
}

.subpanel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 18px;
  min-width: 0;
}

.helper-text {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.task-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 0 10px;
}

.muted-line {
  color: var(--muted);
  font-size: 12px;
}

.color-swatch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.color-swatch::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--swatch-color);
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  font-size: 14px;
  overflow-wrap: anywhere;
}

th {
  background: #f7fafb;
  color: #405061;
}

tr:last-child td {
  border-bottom: 0;
}

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

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #e6f4ea;
  color: #17643a;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}

.status.passive {
  background: #f8e7e5;
  color: var(--danger);
}

.form-message {
  min-height: 20px;
  color: var(--danger);
  font-weight: 700;
}

@media (max-width: 860px) {
  .app-view {
    grid-template-columns: 1fr;
    width: 100%;
    overflow-x: hidden;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .content {
    padding: 18px;
  }

  .metrics,
  .grid-form,
  .filter-form,
  .manager-layout {
    grid-template-columns: 1fr;
  }

  .topbar,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  body {
    background: #eef3f5;
  }

  .login-view {
    align-items: stretch;
    padding: 16px;
  }

  .login-panel {
    align-self: center;
    padding: 22px;
  }

  .sidebar {
    gap: 16px;
    padding: 16px;
  }

  .sidebar nav {
    display: flex;
    gap: 8px;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 2px;
  }

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

  .sidebar .ghost {
    width: 100%;
  }

  .content {
    padding: 14px;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 14px;
  }

  .topbar h1 {
    font-size: 22px;
    line-height: 1.2;
  }

  .panel {
    border-radius: 6px;
    padding: 14px;
  }

  .panel-head {
    gap: 10px;
    margin-bottom: 14px;
  }

  .panel-head h2 {
    font-size: 20px;
  }

  .panel-head button {
    width: 100%;
  }

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

  .metrics article {
    min-height: 82px;
    padding: 12px;
  }

  .metrics strong,
  .metrics .metric-text {
    margin-top: 8px;
    font-size: 24px;
  }

  .subpanel {
    padding: 12px;
  }

  .form-actions button,
  .row-actions button {
    width: 100%;
    flex-basis: 100%;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
    border-collapse: separate;
  }

  thead {
    display: none;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    margin-bottom: 10px;
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    font-size: 13px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  td[colspan] {
    display: block;
    text-align: center;
    color: var(--muted);
  }

  td[colspan]::before {
    content: "";
  }

  .task-chip,
  .status {
    justify-self: start;
  }

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

  .calendar-day {
    min-height: auto;
  }
}
