:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f4;
  --line: #d9e2e5;
  --text: #18252b;
  --muted: #60717a;
  --nav: #17242a;
  --nav-soft: #22343c;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warning: #b45309;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(16, 36, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.boot-page,
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    linear-gradient(145deg, rgba(15, 118, 110, 0.08), transparent 42%),
    linear-gradient(320deg, rgba(180, 83, 9, 0.07), transparent 48%),
    var(--bg);
}

.boot-panel {
  color: var(--muted);
  text-align: center;
}

.boot-panel h1 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 24px;
}

.boot-panel p {
  margin: 0;
}

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

.auth-panel h1 {
  margin: 0 0 24px;
  font-size: 26px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.tab,
.ghost-btn,
.primary-btn,
.nav-item,
.icon-btn {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 38px;
}

.tab {
  background: var(--surface-soft);
  color: var(--muted);
}

.tab.active {
  background: #e2f2ef;
  color: var(--accent-strong);
  border-color: #b8ded8;
}

.auth-form,
.profile-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--text);
  background: #fff;
}

input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.18);
  border-color: var(--accent);
}

.primary-btn {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  padding: 0 16px;
}

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

.ghost-btn {
  color: var(--text);
  background: var(--surface);
  border-color: var(--line);
  padding: 0 14px;
}

.ghost-btn:hover {
  border-color: #aebfc4;
}

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

.message {
  min-height: 20px;
  margin: 16px 0 0;
  color: var(--warning);
  font-size: 14px;
}

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

.side-nav {
  background: var(--nav);
  color: #dbe8eb;
  padding: 18px 14px;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 24px;
  font-weight: 700;
  line-height: 1.4;
}

.nav-item {
  width: 100%;
  text-align: left;
  padding: 0 14px;
  margin-bottom: 8px;
  color: #dbe8eb;
  background: transparent;
}

.nav-item.active,
.nav-item:hover {
  background: var(--nav-soft);
}

.main-area {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.top-bar {
  min-height: 78px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.top-bar h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

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

.top-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-greeting {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.user-name-link {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  padding: 6px 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.user-name-link:hover {
  color: var(--accent-strong);
  text-decoration-thickness: 2px;
}

.log-workspace {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.content-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  padding: 0 18px 18px;
}

.tree-panel,
.list-panel,
.user-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-panel {
  margin: 18px;
}

.panel-head {
  min-height: 52px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
}

.search-bar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.log-search {
  margin: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  grid-template-columns: minmax(220px, 1fr) auto auto auto;
}

.search-summary {
  padding: 8px 14px;
  color: var(--muted);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  width: 34px;
  min-height: 34px;
  background: var(--surface-soft);
  color: var(--text);
  border-color: var(--line);
}

.model-tree {
  padding: 10px;
  overflow: auto;
  max-height: calc(100vh - 168px);
}

.tree-empty,
.empty-row {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.model-btn,
.serial-btn {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 6px;
  color: var(--text);
  min-height: 38px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.model-btn:hover,
.serial-btn:hover,
.serial-btn.active {
  background: var(--surface-soft);
}

.model-btn.active {
  background: #e2f2ef;
  color: var(--accent-strong);
}

.serials {
  margin: 4px 0 10px 14px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
}

.count-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
}

.status-pill.pending {
  color: var(--warning);
  background: #fff4df;
}

.status-pill.active {
  color: var(--accent-strong);
  background: #e2f2ef;
}

.status-pill.disabled,
.status-pill.rejected,
.status-pill.deleted {
  color: var(--danger);
  background: #fde8e6;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 168px);
}

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

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

th {
  position: sticky;
  top: 0;
  background: #f9fbfb;
  z-index: 1;
  color: var(--muted);
  font-weight: 700;
}

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

.link-btn {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  padding: 4px 0;
}

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

.modal {
  width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 36px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal::backdrop {
  background: rgba(15, 28, 33, 0.42);
}

.modal-head {
  min-height: 56px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  font-size: 18px;
}

.zip-list {
  max-height: calc(100vh - 112px);
  overflow: auto;
  padding: 8px 14px 16px;
}

.zip-list.text-mode {
  height: min(720px, calc(100vh - 112px));
  max-height: calc(100vh - 112px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  padding: 0 14px 14px;
}

.zip-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.zip-entry span:last-child {
  color: var(--muted);
}

.muted-text {
  color: var(--muted);
}

.text-viewer-toolbar {
  min-height: 48px;
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto auto;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  white-space: nowrap;
}

.text-viewer-toolbar .ghost-btn {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.text-viewer {
  margin: 0;
  padding: 12px 0 0;
  min-height: 0;
  overflow: auto;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.55;
  outline: none;
}

.text-line {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  min-height: 22px;
}

.text-line code {
  white-space: pre-wrap;
  word-break: break-word;
}

.line-no {
  position: sticky;
  left: 0;
  background: var(--surface);
  color: var(--muted);
  border-right: 1px solid var(--line);
  padding-right: 10px;
  margin-right: 10px;
  text-align: right;
  user-select: none;
}

.matched-line {
  background: #fff8db;
}

.text-search-input {
  min-height: 32px;
  min-width: 0;
  font-size: 13px;
}

mark {
  background: #ffe082;
  color: inherit;
  padding: 0 1px;
}

.profile-form {
  padding: 16px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  background: var(--nav);
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 10;
}

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

  .side-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px;
  }

  .side-brand {
    padding: 0;
  }

  .side-nav nav {
    display: flex;
    gap: 8px;
  }

  .nav-item {
    width: auto;
    margin: 0;
  }

  .top-bar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .search-bar {
    grid-template-columns: 1fr;
  }

  .text-viewer-toolbar {
    grid-template-columns: auto minmax(120px, 1fr) auto auto auto;
    gap: 6px;
  }

  .text-viewer-toolbar .ghost-btn,
  .text-search-input {
    font-size: 12px;
  }

  .model-tree,
  .table-wrap {
    max-height: none;
  }
}
