:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #1f2937;
  --sub: #6b7280;
  --primary: #2563eb;
  --green: #16a34a;
  --orange: #d97706;
  --red: #dc2626;
  --sidebar-width: 220px;
  --sidebar-collapsed-width: 72px;
}

* {
  box-sizing: border-box;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.layout {
  display: block;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  overflow-y: auto;
  z-index: 20;
  transition: width .2s ease, padding .2s ease;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.collapse-btn {
  border: 1px solid var(--line);
  background: #fff;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sub);
}

.brand {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 28px;
}

#toggle-sidebar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.toggle-icon {
  font-size: 14px;
  line-height: 1;
  transition: transform .2s ease;
}

.toggle-text {
  white-space: nowrap;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sub);
  cursor: pointer;
}

.nav-icon {
  width: 20px;
  text-align: center;
  flex: 0 0 20px;
}

.nav-text {
  white-space: nowrap;
}

.nav-item.active {
  color: var(--primary);
  background: #eff6ff;
  border-color: #bfdbfe;
}

.main {
  margin-left: var(--sidebar-width);
  padding: 22px;
  transition: margin-left .2s ease;
}

body.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-width);
  padding: 22px 10px;
}

body.sidebar-collapsed .main {
  margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .brand {
  display: none;
}

body.sidebar-collapsed .sidebar-head {
  justify-content: center;
}

body.sidebar-collapsed .collapse-btn {
  transform: rotate(180deg);
}

body.sidebar-collapsed .nav-item {
  justify-content: center;
  padding: 10px 8px;
}

body.sidebar-collapsed .nav-text {
  display: none;
}

body.sidebar-collapsed #toggle-sidebar {
  padding: 10px 8px;
}

body.sidebar-collapsed .toggle-text {
  display: none;
}

body.sidebar-collapsed .toggle-icon {
  transform: rotate(180deg);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.title-group h1 {
  margin: 0;
  font-size: 24px;
}

.title-group p {
  margin: 6px 0 0;
  color: var(--sub);
  font-size: 14px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.scheduler-chip {
  background: #f3f4f6;
  color: var(--sub);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
}

.user-chip {
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
}

.clock {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}

.stat h3 {
  margin: 0;
  color: var(--sub);
  font-size: 14px;
  font-weight: 500;
}

.stat p {
  margin: 12px 0 0;
  font-size: 32px;
  font-weight: 700;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

h3 {
  margin: 0;
  font-size: 16px;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  border-radius: 10px;
  padding: 8px 14px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

.secondary-btn {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.secondary-btn:disabled {
  cursor: not-allowed;
  color: #94a3b8;
  background: #f8fafc;
}

.ghost-btn {
  background: transparent;
  color: var(--sub);
  border-color: var(--line);
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.input,
.select {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  outline: none;
  min-width: 160px;
}

.textarea {
  min-height: 92px;
  resize: vertical;
}

.table-wrap {
  overflow: auto;
}

.pagination-bar {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.pagination-summary {
  color: var(--sub);
  font-size: 13px;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-size {
  min-width: 84px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  color: var(--sub);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  white-space: nowrap;
}

tbody td {
  border-bottom: 1px solid #f0f1f4;
  padding: 11px 8px;
  white-space: nowrap;
}

.download-link-cell {
  min-width: 72px;
}

.download-link-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-btn img {
  width: 15px;
  height: 15px;
  display: block;
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.op-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  margin-right: 6px;
  font-size: 12px;
  background: #fff;
  cursor: pointer;
}

.op-btn:disabled {
  cursor: not-allowed;
  color: #94a3b8;
  background: #f8fafc;
}

.text-btn {
  border: none;
  background: transparent;
  color: #2563eb;
  padding: 0;
  cursor: pointer;
}

.text-btn:hover {
  text-decoration: underline;
}

.note-title-cell {
  max-width: 140px;
}

.note-title-btn {
  border: none;
  background: transparent;
  color: #2563eb;
  cursor: pointer;
  padding: 0;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
  text-align: left;
}

.note-title-empty {
  color: var(--sub);
}

.status {
  font-size: 12px;
  border-radius: 999px;
  padding: 4px 10px;
  display: inline-block;
}

.status-idle {
  background: #ecfdf3;
  color: var(--green);
}

.status-processing {
  background: #fff7ed;
  color: var(--orange);
}

.status-error {
  background: #fef2f2;
  color: var(--red);
}

.upcoming-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.upcoming-item {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #f0f1f4;
  padding: 10px 0;
}

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.summary-box {
  margin-top: 14px;
  color: var(--sub);
}

.cleanup-targets {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.cleanup-targets label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
}

.cleanup-preview-summary {
  margin-bottom: 14px;
  color: var(--sub);
}

.kv-list {
  display: grid;
  gap: 10px;
}

.kv-list div {
  display: flex;
  justify-content: space-between;
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.kv-list span {
  color: var(--sub);
}

.control-box {
  display: grid;
  gap: 12px;
}

.actions-row {
  display: flex;
  gap: 10px;
}

.switch-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.placeholder {
  color: var(--sub);
  line-height: 1.8;
}

.modal,
.drawer {
  position: fixed;
  inset: 0;
  display: none;
}

.modal.open,
.drawer.open {
  display: block;
}

.modal {
  background: rgba(15, 23, 42, 0.35);
}

.panel {
  width: min(760px, 92vw);
  background: var(--panel);
  margin: 5vh auto;
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 16px;
}

.detail-panel {
  width: min(980px, 96vw);
}

.detail-meta {
  color: var(--sub);
  font-size: 13px;
  margin-bottom: 10px;
}

.detail-content {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  padding: 12px;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.drawer {
  background: rgba(15, 23, 42, 0.2);
}

.drawer-panel {
  width: min(520px, 96vw);
  height: 100%;
  margin-left: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.close-btn {
  border: 1px solid var(--line);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label {
  display: grid;
  gap: 8px;
  color: var(--sub);
  font-size: 13px;
}

.full-width {
  grid-column: 1 / -1;
}

.input[readonly] {
  background: #f8fafc;
  color: #334155;
}

.panel-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #111827;
  color: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: all .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #eef2ff 0%, #f8fafc 45%, #f6f8fb 100%);
}

.login-card {
  width: min(420px, 92vw);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
}

.login-title {
  margin: 0;
  font-size: 24px;
}

.login-subtitle {
  color: var(--sub);
  margin: 8px 0 20px;
  font-size: 14px;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-footer {
  margin-top: 12px;
  color: var(--sub);
  font-size: 12px;
}

@media (max-width: 1100px) {
  .sidebar {
    position: static;
    width: auto;
    overflow: visible;
  }
  .main {
    margin-left: 0;
  }
  body.sidebar-collapsed .sidebar {
    width: auto;
    padding: 22px 16px;
  }
  body.sidebar-collapsed .main {
    margin-left: 0;
  }
  body.sidebar-collapsed .brand {
    display: block;
  }
  body.sidebar-collapsed .nav-text {
    display: inline;
  }
  body.sidebar-collapsed .toggle-text {
    display: inline;
  }
  #toggle-sidebar {
    display: none;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}
