:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #eef3f4;
  --nav: #1d2b2d;
  --text: #182326;
  --muted: #627174;
  --border: #dce4e6;
  --accent: #0f766e;
  --accent-weak: #d9eeea;
  --danger: #b42318;
  --warning: #b7791f;
  --shadow: 0 18px 40px rgba(31, 49, 53, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

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

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  min-height: 36px;
  padding: 0 14px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  min-height: 36px;
  padding: 0 10px;
}

textarea {
  min-height: 72px;
  padding: 10px;
  resize: vertical;
}

table {
  min-width: 1120px;
  border-collapse: collapse;
  table-layout: auto;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.45;
  padding: 10px 8px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f8fafb;
  color: #49595c;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  color: #253236;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th:last-child,
td:last-child {
  background: inherit;
  min-width: 104px;
  position: sticky;
  right: 0;
  z-index: 2;
}

th:last-child {
  background: #f8fafb;
}

td:last-child {
  background: #ffffff;
}

.hidden {
  display: none !important;
}

.login-screen {
  align-items: center;
  display: flex;
  min-height: 100vh;
  justify-content: center;
  padding: 24px;
}

.login-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 28px;
  max-width: 760px;
  padding: 32px;
  width: min(100%, 760px);
  grid-template-columns: 1fr 320px;
}

.login-panel h1 {
  font-size: 28px;
  line-height: 1.15;
  margin: 0 0 8px;
}

.login-panel p {
  color: var(--muted);
  margin: 0;
}

.login-form {
  display: grid;
  gap: 14px;
}

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

.form-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 16px;
}

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

.app-shell.drawer-open {
  grid-template-columns: 232px minmax(0, 1fr) minmax(340px, 390px);
}

.sidebar {
  background: var(--nav);
  color: #e8eff0;
  padding: 20px 14px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 10px;
  margin-bottom: 28px;
  padding: 0 8px;
}

.brand-mark {
  align-items: center;
  background: #d9eeea;
  border-radius: 6px;
  color: #0b4e49;
  display: inline-flex;
  font-weight: 800;
  height: 34px;
  justify-content: center;
  width: 34px;
}

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

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

.brand small {
  color: #a9bbbf;
  font-size: 11px;
  margin-top: 2px;
}

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

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

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

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

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

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

.topbar p {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.account {
  align-items: center;
  display: flex;
  gap: 10px;
  white-space: nowrap;
}

.ghost-button {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
}

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

.danger-button:hover {
  border-color: #f3b4ad;
  background: #fff5f4;
}

.icon-button {
  align-items: center;
  background: var(--surface-muted);
  color: var(--text);
  display: inline-flex;
  flex: 0 0 34px;
  font-size: 20px;
  justify-content: center;
  padding: 0;
  width: 34px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.kpi span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 6px;
}

.kpi strong {
  font-size: 22px;
  line-height: 1.1;
}

.filter-bar,
.entity-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px;
}

.filter-bar {
  align-items: center;
  grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
}

.filter-bar > * {
  min-width: 0;
}

.filter-bar button {
  width: 100%;
}

.entity-form {
  grid-template-columns: 1.4fr 0.7fr 1.2fr auto auto;
}

.checkbox-label {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  gap: 8px;
  white-space: nowrap;
}

.checkbox-label input {
  min-height: auto;
  width: auto;
}

.toolbar,
.pagination {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
}

.toolbar {
  color: var(--muted);
  font-size: 13px;
}

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

.table-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: calc(100vh - 315px);
  overflow: auto;
}

.status-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 11px;
  font-weight: 700;
  max-width: 100%;
  padding: 3px 8px;
}

.status-neutral {
  background: #edf2f4;
  color: #405053;
}

.status-good {
  background: #dcfce7;
  color: #166534;
}

.status-warn {
  background: #fef3c7;
  color: #92400e;
}

.status-danger {
  background: #fee2e2;
  color: #991b1b;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.row-actions button {
  min-height: 28px;
  min-width: 38px;
  padding: 0 8px;
}

.detail-drawer {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: none;
  flex-direction: column;
  max-height: 100vh;
  min-width: 0;
  overflow: hidden;
}

.detail-drawer.open {
  display: flex;
}

.drawer-header {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 18px;
}

.drawer-header > div {
  min-width: 0;
}

.drawer-header h2 {
  font-size: 18px;
  line-height: 1.2;
  margin: 0 0 4px;
}

.drawer-header p {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.drawer-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.empty-state {
  align-items: center;
  color: var(--muted);
  display: flex;
  justify-content: center;
}

.detail-section {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}

.detail-section:first-child {
  padding-top: 0;
}

.detail-section h3 {
  font-size: 13px;
  margin: 0 0 10px;
}

.detail-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.field {
  min-width: 0;
}

.field span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  margin-bottom: 3px;
}

.field strong,
.field code {
  color: var(--text);
  display: block;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.status-form {
  display: grid;
  gap: 8px;
}

.json-box,
.log-list {
  background: #f8fafb;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #243134;
  font-size: 11px;
  line-height: 1.5;
  max-height: 260px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

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

.stat-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

.stat-panel h2 {
  font-size: 15px;
  margin: 0 0 10px;
}

.stat-row {
  display: flex;
  font-size: 13px;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}

.stat-row:last-child {
  border-bottom: 0;
}

@media (max-width: 1180px) {
  .app-shell,
  .app-shell.drawer-open {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .detail-drawer {
    bottom: 0;
    box-shadow: var(--shadow);
    display: flex;
    max-width: 520px;
    pointer-events: none;
    position: fixed;
    right: 0;
    top: 0;
    transform: translateX(100%);
    transition: transform 160ms ease;
    visibility: hidden;
    width: 92vw;
    z-index: 20;
  }

  .detail-drawer.open {
    pointer-events: auto;
    transform: translateX(0);
    visibility: visible;
  }

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

@media (max-width: 760px) {
  .login-panel,
  .app-shell,
  .app-shell.drawer-open {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 12px;
  }

  .nav {
    display: flex;
    overflow-x: auto;
  }

  .nav-item {
    white-space: nowrap;
  }

  .workspace {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
  }

  .kpi-strip,
  .filter-bar,
  .entity-form,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .table-shell {
    max-height: none;
  }
}
