:root {
  --bg: #e8ebf0;
  --side: #dfe3e9;
  --card: #fff;
  --head: #dde1e7;
  --line: #cfd5dd;
  --line-soft: #e4e7ec;
  --ink: #1d2733;
  --soft: #5b6673;
  --blue: #0f4c97;
  --blue-dark: #0b3a75;
  --blue-soft: #e4eefa;
  --green: #17794a;
  --green-soft: #e0f3e9;
  --amber: #8f5a00;
  --amber-soft: #fdf0d5;
  --red: #b3261e;
  --red-soft: #fbe6e4;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  color: var(--ink);
  background: var(--bg);
  font-size: 13px;
}

.shell label, dialog label { color: var(--soft); }
.shell input, .shell select, .shell textarea, dialog input, dialog select, dialog textarea {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  font: inherit;
  font-size: 13px;
}
.shell textarea, dialog textarea { height: 104px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
.shell input:focus, .shell select:focus, .shell textarea:focus,
dialog input:focus, dialog select:focus, dialog textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(15, 76, 151, .16); }
.shell input::placeholder, dialog input::placeholder, .shell textarea::placeholder { color: #8b95a1; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--side);
  border-right: 1px solid var(--line);
}

.brand {
  min-height: 78px;
  padding: 13px 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  color: #cfe0f4;
  background: #0f2d57;
  font-size: 11px;
  text-decoration: none;
}
.brand img { width: 112px; height: auto; }

#nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  min-height: 36px;
  margin-bottom: 3px;
  padding: 0 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #38434f;
  border-radius: 4px;
  font-weight: 500;
  text-decoration: none;
}
.nav-item:hover { background: #d2d7df; }
.nav-item.active { color: #fff; background: var(--blue); font-weight: 600; }
.nav-item small { min-width: 22px; padding: 1px 6px; color: #49535f; background: #c9ced6; border-radius: 3px; font-size: 11px; text-align: center; }
.nav-item.active small { color: #fff; background: rgba(255, 255, 255, .22); }

.side-foot { padding: 12px; display: grid; gap: 10px; border-top: 1px solid var(--line); }
.side-user { display: grid; gap: 1px; min-width: 0; }
.side-user strong { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.side-user span { color: var(--soft); font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.searchbar {
  min-height: 48px;
  padding: 7px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #f3f4f7;
  border-bottom: 1px solid var(--line);
}
.searchbar input { max-width: 320px; }
.searchbar span { color: var(--soft); font-size: 12px; white-space: nowrap; }
#content { padding: 16px 20px 28px; outline: none; }

.page-head { margin-bottom: 14px; display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; }
.page-head h1 { margin: 0; font-size: 19px; font-weight: 700; }
.back { color: var(--blue); font-weight: 600; text-decoration: none; }
.tabs { display: flex; flex-wrap: wrap; padding: 3px; background: #dce0e6; border: 1px solid var(--line); border-radius: 4px; }
.tabs button { min-height: 28px; padding: 0 10px; color: #3b4652; background: transparent; border: 0; border-radius: 3px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 500; }
.tabs button small { margin-left: 5px; padding: 0 5px; color: #4c5662; background: #c8cdd5; border-radius: 3px; font-size: 10px; }
.tabs button.active { color: #fff; background: var(--blue); font-weight: 600; }
.tabs button.active small { color: #fff; background: rgba(255, 255, 255, .24); }
.head-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  min-height: 34px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #aeb6c1;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { background: #f1f3f6; }
.btn.blue { color: #fff; background: var(--blue); border-color: var(--blue); }
.btn.blue:hover { background: var(--blue-dark); }
.btn.danger { color: #fff; background: var(--red); border-color: var(--red); }
.btn:disabled { cursor: wait; opacity: .6; }
.link { padding: 3px 0; color: var(--blue); background: none; border: 0; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.link:hover { text-decoration: underline; }
.link.red { color: var(--red); }

.stats { margin-bottom: 14px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--card); border: 1px solid var(--line); border-radius: 3px; }
.stat { min-width: 0; padding: 12px 14px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat span { display: block; color: var(--soft); font-size: 11px; }
.stat strong { margin-right: 6px; font-size: 19px; font-weight: 700; }
.stat small { color: var(--soft); font-size: 11px; }

.work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.work.with-side { grid-template-columns: minmax(0, 1fr) 360px; }
.stack { display: grid; gap: 14px; min-width: 0; }

.card { min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 3px; }
.card-head { min-height: 44px; padding: 7px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--head); border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; font-size: 13px; font-weight: 700; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 8px 14px; color: #48535f; background: #eef0f3; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 600; text-align: left; white-space: nowrap; }
td { height: 42px; padding: 6px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f6f8fb; }
td strong { font-weight: 600; }
td small { display: block; color: var(--soft); font-size: 11px; }
.mono { font-family: "Noto Sans Mono", ui-monospace, monospace; font-size: 12px; }
.num { color: var(--blue); font-weight: 600; white-space: nowrap; }
.row-actions { display: flex; justify-content: flex-end; gap: 12px; }
th.end { text-align: right; }
.clip { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 7px; border-radius: 3px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.gray { color: #47515c; background: #e5e8ec; }
.badge.green { color: var(--green); background: var(--green-soft); }
.badge.amber { color: var(--amber); background: var(--amber-soft); }
.badge.red { color: var(--red); background: var(--red-soft); }
.badge.blue { color: var(--blue); background: var(--blue-soft); }

.empty { padding: 30px 16px; color: var(--soft); text-align: center; }
.empty strong { display: block; margin-bottom: 3px; color: var(--ink); font-size: 14px; }
.empty .btn { margin-top: 12px; }

.form-grid { padding: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { margin-bottom: 4px; font-size: 12px; font-weight: 500; }
.field small { display: block; margin-top: 3px; color: var(--soft); font-size: 11px; }
.choice-list { max-height: 150px; padding: 6px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 8px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 4px; }
.shell .choice-list label { margin: 0; padding: 3px; display: flex; align-items: center; gap: 6px; color: var(--ink); font-size: 12px; font-weight: 400; }
.shell .choice-list input { width: 14px; height: 14px; flex: none; }
.form-foot { padding: 10px 14px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line-soft); }
.notice { margin-bottom: 14px; padding: 9px 12px; color: #5a4300; background: var(--amber-soft); border: 1px solid #ecd6a6; border-radius: 3px; }

.details { padding: 4px 14px 10px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 18px; }
.details div { padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.details span { display: block; color: var(--soft); font-size: 11px; }
.details strong { font-weight: 600; overflow-wrap: anywhere; }

.tasks { display: grid; }
.task { width: 100%; min-height: 54px; padding: 8px 12px; display: grid; grid-template-columns: 38px minmax(0, 1fr) 12px; align-items: center; gap: 10px; color: var(--ink); background: #fff; border: 0; border-bottom: 1px solid var(--line-soft); cursor: pointer; font: inherit; text-align: left; }
.task:last-child { border-bottom: 0; }
.task:hover { background: #f3f6fa; }
.task strong { display: block; font-size: 12px; font-weight: 600; }
.task small { color: var(--soft); font-size: 11px; }
.task b { color: #7c8794; font-size: 18px; font-weight: 400; }
.task-count { height: 30px; display: grid; place-items: center; border-radius: 4px; font-size: 13px; font-weight: 700; }
.task-count.red { color: var(--red); background: var(--red-soft); }
.task-count.amber { color: var(--amber); background: var(--amber-soft); }
.task-count.blue { color: var(--blue); background: var(--blue-soft); }
.task-count.green { color: var(--green); background: var(--green-soft); }
.task-count.gray { color: #47515c; background: #e5e8ec; }

.bars { padding: 10px 14px; display: grid; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) 22px 56px; align-items: center; gap: 8px; font-size: 11px; }
.bar-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row i { height: 8px; display: block; overflow: hidden; background: #e7eaee; border-radius: 2px; }
.bar-row em { height: 100%; display: block; width: 0; background: var(--blue); }
.bar-row b { font-weight: 700; text-align: right; }
.bar-row small { color: var(--soft); text-align: right; }

.server-grid { margin-bottom: 14px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.meters { padding: 12px 14px 14px; display: grid; gap: 13px; }
.meter-head { margin-bottom: 5px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; }
.meter-head strong { font-size: 12px; font-weight: 600; }
.meter-head span { color: var(--soft); font-size: 12px; }
.meter-bar { height: 10px; overflow: hidden; background: #e7eaee; border-radius: 2px; }
.meter-bar em { height: 100%; display: block; width: 0; background: var(--blue); transition: width .35s ease; }
.meter-bar em.warn { background: #c98a12; }
.meter-bar em.high { background: var(--red); }
.server-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
dialog label.check, .shell label.check { margin: 0; display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; cursor: pointer; }
dialog label.check input { width: 16px; height: 16px; flex: none; }

.security-row { padding: 14px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.security-row p { margin: 3px 0 0; color: var(--soft); font-size: 12px; }
.settings-stack { display: grid; gap: 14px; }
.totp-box { padding: 14px; display: grid; justify-items: center; gap: 10px; }
#totp-qr { width: 216px; height: 216px; background: #fff; border: 1px solid var(--line); image-rendering: pixelated; }
.totp-key { max-width: 100%; padding: 7px 9px; background: #f1f3f6; border-radius: 3px; font-family: "Noto Sans Mono", ui-monospace, monospace; font-size: 12px; overflow-wrap: anywhere; text-align: center; user-select: all; }
.gate { max-width: 560px; margin: 24px auto; }

.search-right { display: flex; align-items: center; gap: 14px; }
kbd { margin-left: 5px; padding: 1px 5px; color: var(--soft); background: #eceff3; border: 1px solid var(--line); border-radius: 3px; font: inherit; font-size: 10px; }
.palette { padding: 12px; }
#palette-results { margin-top: 8px; display: grid; gap: 2px; }
#palette-results button { min-height: 40px; padding: 5px 9px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--ink); background: #fff; border: 0; border-radius: 3px; cursor: pointer; font: inherit; text-align: left; }
#palette-results button:first-child, #palette-results button:hover { background: var(--blue-soft); }
#palette-results strong { font-weight: 600; }
#palette-results small { flex: none; color: var(--soft); font-size: 11px; }
#palette-results p { margin: 0; padding: 12px; color: var(--soft); text-align: center; }

dialog {
  width: min(calc(100vw - 32px), 500px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  color: var(--ink);
  background: #fff;
  border: 1px solid #9fa8b4;
  border-radius: 5px;
  font-size: 13px;
}
dialog::backdrop { background: rgba(21, 30, 42, .48); }
dialog header { min-height: 46px; padding: 6px 8px 6px 16px; display: flex; align-items: center; justify-content: space-between; background: var(--head); border-bottom: 1px solid var(--line); }
dialog h2 { margin: 0; font-size: 14px; font-weight: 700; }
#modal-close { width: 32px; height: 32px; color: var(--soft); background: none; border: 0; border-radius: 3px; cursor: pointer; font-size: 20px; }
#modal-close:hover { background: #cfd4db; }
#modal-body { max-height: calc(100dvh - 180px); overflow-y: auto; }
#modal-body > p { margin: 0; padding: 16px; line-height: 1.5; }
.modal-error { margin: 0 14px 10px; padding: 7px 10px; color: var(--red); background: var(--red-soft); border-radius: 3px; font-size: 12px; }
dialog footer { padding: 10px 14px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
.key-note { margin: 14px 14px 8px; padding: 8px 10px; color: #5a4300; background: var(--amber-soft); border-radius: 3px; font-size: 12px; }
.key-list { max-height: 260px; margin: 0 14px 14px; padding: 8px 11px; overflow-y: auto; background: #f1f3f6; border: 1px solid var(--line); border-radius: 3px; font-family: "Noto Sans Mono", ui-monospace, monospace; font-size: 13px; line-height: 1.8; user-select: all; }

#toast { position: fixed; right: 18px; bottom: 18px; z-index: 30; max-width: min(calc(100vw - 36px), 380px); padding: 10px 14px; color: #fff; background: #17324f; border-radius: 4px; font-size: 13px; }
#toast.error { background: var(--red); }

@media (max-width: 1320px) {
  .work.with-side { grid-template-columns: minmax(0, 1fr); }
}

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

@media (max-width: 860px) {
  .shell { display: block; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { min-height: 58px; }
  #nav { padding: 8px; display: flex; gap: 4px; overflow-x: auto; }
  .nav-item { flex: none; margin: 0; gap: 7px; }
  .side-foot { padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; }
  .searchbar { padding: 7px 16px; }
  #content { padding: 14px 16px 24px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(2n) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .head-actions { width: 100%; margin-left: 0; }
  .details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .details, .server-details { grid-template-columns: minmax(0, 1fr); }
  #today, kbd { display: none; }
  .searchbar input { max-width: none; }
}
