:root {
  --bg: #f4f8fb;
  --surface: #ffffff;
  --surface-header: #f7fafc;
  --line: #d7e1ea;
  --text: #263445;
  --ink: #0f3f46;
  --muted: #66788a;
  --accent: #2563eb;
  --accent-soft: #edf4ff;
  --green: #10b981;
  --green-soft: #e8faf3;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fff4d6;
  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 12px 30px rgba(15, 23, 42, 0.12);
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { width: 100%; min-width: 0; overflow-x: hidden; }
body {
  margin: 0;
  width: 100%;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-thumb { background: #c7d3df; border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

button,
input,
select,
textarea {
  min-width: 0;
  font: inherit;
  border-radius: var(--radius);
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  padding: 6px 9px;
  background: var(--surface);
  color: var(--text);
}

textarea { line-height: 1.45; }

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

button {
  min-height: 32px;
  padding: 5px 12px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}

button:hover { background: #f7fafc; border-color: #bdcad7; }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover { background: #1d4ed8; }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); border-color: #fca5a5; }
button:disabled { cursor: not-allowed; opacity: 0.58; }
button:disabled:hover { background: var(--surface); border-color: var(--line); }

mark {
  padding: 0 2px;
  border-radius: 3px;
  background: #fde68a;
  color: #713f12;
}

.code {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--warning-soft);
  color: var(--warning);
  font-weight: 800;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.app {
  display: none;
  grid-template-columns: minmax(184px, 210px) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  min-width: 0;
}
.app.is-visible { display: grid; }

.sidebar {
  min-height: 0;
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.sidebar-brand {
  min-height: 60px;
  padding: 0 16px;
  font-size: 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #eef7f5;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

.brand-logo { width: 28px; height: 28px; color: var(--accent); flex-shrink: 0; }

.nav {
  flex: 1;
  min-height: 0;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-item {
  border: 0;
  background: transparent;
  color: var(--text);
  justify-content: flex-start;
  padding: 8px 12px;
  height: 34px;
  border-radius: var(--radius);
  font-size: 12px;
}
.nav-item:hover { background: #eef7f5; color: var(--ink); }
.nav-item.active { background: var(--accent); color: white; }
.nav-item span { width: 18px; text-align: center; flex-shrink: 0; }

.main-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  position: relative;
}

.topbar {
  min-height: 50px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto auto minmax(160px, 1fr);
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  flex-shrink: 0;
}

.topbar h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}

.endpoint {
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.endpoint-url {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.endpoint-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #1d4ed8;
  white-space: nowrap;
}

.endpoint-badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 12px;
  flex-direction: column;
  gap: 12px;
}
.view.active { display: flex; }

.dashboard-top {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  flex-shrink: 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 12px;
  border-radius: var(--radius);
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  min-height: 70px;
}

.stat-card label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 3px;
}

.stat-card b { font-size: 20px; color: var(--ink); line-height: 1.2; }

.dashboard-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 400px);
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.panel {
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  min-height: 36px;
  padding: 6px 12px;
  background: var(--surface-header);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.panel-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0;
}

.panel-body {
  padding: 10px;
  overflow: auto;
  flex: 1;
  position: relative;
  min-height: 0;
  min-width: 0;
}

.messages-view-layout {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 12px;
  height: 100%;
  min-height: 0;
}

.message-list-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.toolbar-compact {
  display: flex;
  gap: 8px;
  padding: 0 0 8px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar-compact input,
.toolbar-compact select {
  width: auto;
  flex: 1 1 140px;
}

.toolbar-compact button { flex: 0 0 auto; }

.message-maintenance {
  display: flex;
  gap: 6px;
  padding-bottom: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 11px;
}

.message-maintenance .muted-label { color: var(--muted); }
.message-maintenance input { width: 72px; min-height: 28px; padding: 3px 6px; font-size: 11px; }
.message-maintenance button { min-height: 28px; padding: 3px 9px; font-size: 11px; }

.item-row {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  background: var(--surface);
  min-width: 0;
}
.item-row:hover { background: #f7fafc; }
.item-row.active { background: #eef7f5; border-left: 3px solid var(--accent); padding-left: 9px; }
.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.item-title {
  font-weight: 650;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.link-view-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
  grid-template-rows: minmax(230px, 1fr) minmax(250px, 1.3fr);
  grid-template-areas: "list detail" "preset detail";
  gap: 12px;
  height: 100%;
  min-height: 0;
}
.link-list-panel { grid-area: list; }
.link-detail-panel { grid-area: detail; }
.preset-panel { grid-area: preset; }
.link-head-meta { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; flex: 1; }
.link-head-meta #selectedLinkPreview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 280px;
}
.link-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.link-actions button { width: 100%; }
.state-btn.enable { color: #047857; border-color: #a7f3d0; background: var(--green-soft); }
.state-btn.disable { color: #9a3412; border-color: #fed7aa; background: #fff7ed; }
.state-btn.enable.is-selected { background: var(--green); border-color: var(--green); color: white; }
.state-btn.disable.is-selected { background: var(--warning); border-color: var(--warning); color: white; }
.state-btn.is-selected:disabled { opacity: 1; }
.state-btn.enable.is-selected:disabled:hover { background: var(--green); border-color: var(--green); }
.state-btn.disable.is-selected:disabled:hover { background: var(--warning); border-color: var(--warning); }

.keyword-list-actions,
.preset-form {
  display: flex;
  gap: 8px;
  align-items: end;
  min-width: 0;
}

.keyword-list-actions input { width: 190px; min-height: 30px; }
.keyword-list-actions button { min-height: 30px; }
.preset-form { margin-bottom: 12px; }
.preset-form .form-field:first-child { flex: 1 1 120px; }
.preset-form .form-field:nth-child(2) { flex: 2 1 180px; }
.preset-form button { min-height: 34px; }

.keyword-table-header {
  display: grid;
  grid-template-columns: minmax(110px, 150px) 76px minmax(150px, 1fr) 132px 66px;
  gap: 10px;
  padding: 7px 12px;
  background: var(--surface-header);
  border-bottom: 1px solid var(--line);
  font-weight: 800;
  font-size: 11px;
  color: var(--muted);
}
.keyword-row {
  display: grid;
  grid-template-columns: minmax(110px, 150px) 76px minmax(150px, 1fr) 132px 66px;
  gap: 10px;
  padding: 9px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  align-items: center;
  width: 100%;
  text-align: left;
  background: var(--surface);
  cursor: pointer;
}
.keyword-row:hover { background: #f7fafc; }
.keyword-row.active { background: #eef7f5; }
.keyword-row > * { min-width: 0; }

.compact-form { display: grid; gap: 10px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.form-field { display: grid; gap: 4px; min-width: 0; }
.form-field label { font-size: 11px; font-weight: 800; color: var(--muted); }
.form-field textarea {
  height: 96px;
  min-height: 96px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.preset-item { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; min-height: 34px; }
.preset-btn {
  flex: 1;
  text-align: center;
  padding: 5px 8px;
  border: 0;
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preset-btn strong {
  display: block;
  font-size: 12px;
  color: var(--ink);
  text-align: center;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preset-del { border: 0; border-left: 1px solid var(--line); background: var(--surface); width: 30px; color: var(--danger); cursor: pointer; }

.settings-view-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  height: 100%;
  overflow: auto;
  padding-bottom: 24px;
}

.settings-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-style: normal;
  font-weight: 800;
  background: #e2e8f0;
  color: var(--ink);
  white-space: nowrap;
}
.tag.green { background: #d1fae5; color: #065f46; }
.tag.blue { background: #dbeafe; color: #1e40af; }
.tag.red { background: #fee2e2; color: #991b1b; }

.toast {
  position: fixed;
  bottom: 64px;
  right: 20px;
  max-width: min(360px, calc(100vw - 32px));
  background: #0f172a;
  color: white;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-weight: 650;
  z-index: 1000;
  display: none;
  box-shadow: var(--shadow-md);
}

.modal {
  position: fixed;
  inset: 0;
  padding: 16px;
  background: rgba(15, 23, 42, 0.42);
  display: none;
  place-items: center;
  z-index: 2000;
}
.modal.open { display: grid; }
.modal-panel { width: min(360px, 100%); box-shadow: var(--shadow-md); }
.modal .panel-body { padding: 16px; line-height: 1.5; color: var(--text); }
.modal-text { margin: 0; }
.field { display: grid; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 800; }

.login {
  display: none;
  place-items: center;
  background: var(--bg);
  flex: 1;
  min-height: 0;
  padding: 20px;
}
.login.is-visible { display: grid; }
.login-box {
  width: min(100%, 360px);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.detail h3 { margin: 0 0 8px; color: var(--ink); font-size: 16px; overflow-wrap: anywhere; }
.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 10px;
}
.detail-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
  background: var(--surface-header);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 13px;
}

.trend-chart {
  min-height: 220px;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 20px 12px 10px;
  overflow-x: auto;
}
.chart-bar {
  min-width: 44px;
  flex: 1;
  display: grid;
  align-items: end;
  gap: 4px;
  height: 100%;
  text-align: center;
  font-size: 10px;
  color: var(--muted);
}
.bar-fill { width: 100%; min-height: 2px; border-radius: 3px 3px 0 0; background: var(--accent); }

.admin-list { display: flex; flex-direction: column; min-width: 0; }
.admin-row {
  display: grid;
  grid-template-columns: minmax(140px, 180px) minmax(72px, 92px) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  min-width: 0;
}
.admin-row > * { min-width: 0; }
.token-row { grid-template-columns: minmax(140px, 170px) minmax(180px, 1fr) auto; }
.session-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}
.session-row > strong { grid-column: 1; }
.session-row > :nth-child(2) { grid-column: 2; justify-self: end; }
.session-row > :nth-child(3),
.session-row > .session-actions { grid-column: 1 / -1; }
.token-cell {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.token-cell code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.token-cell small {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.token-actions {
  flex-wrap: nowrap;
  justify-content: flex-end;
}
.token-actions button { padding-inline: 8px; }
.session-actions {
  flex-direction: column;
  align-items: flex-start;
}
.session-actions small {
  max-width: 100%;
  color: var(--muted);
  text-align: left;
  overflow-wrap: anywhere;
}

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

.client-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}
.client-top {
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-width: 0;
}
.client-top > div:first-child { min-width: 0; }
.client-top h1 { margin: 0; font-size: 20px; color: var(--ink); overflow-wrap: anywhere; }
.status {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.status.live { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.client-bar { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 12px; }
.client-list { display: flex; flex-direction: column; gap: 14px; }
.client-card {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.client-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}
.content { font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; white-space: pre-wrap; color: var(--ink); }
.client-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.icp-footer {
  min-height: 46px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  color: var(--muted);
  z-index: 1000;
  flex-shrink: 0;
  width: 100%;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
}
.icp-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  white-space: nowrap;
}
.icp-item:hover { color: var(--accent); }
.icp-icon { width: 16px; height: 16px; vertical-align: middle; flex-shrink: 0; }

@media (max-width: 1180px) {
  .dashboard-main { grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); }
  .link-view-grid { grid-template-columns: minmax(0, 1fr) minmax(330px, 390px); }
}

@media (max-width: 1024px) {
  body { overflow: hidden; }

  .app.is-visible {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .sidebar {
    order: 2;
    flex-direction: row;
    width: 100%;
    border-right: 0;
    border-top: 1px solid var(--line);
    background: var(--surface);
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .sidebar-brand,
  .sidebar > div:last-child { display: none; }

  .nav {
    flex-direction: row;
    padding: 0;
    width: 100%;
    justify-content: space-around;
    align-items: stretch;
    gap: 0;
  }

  .nav-item {
    flex: 1 1 0;
    min-height: 54px;
    height: auto;
    border-radius: 0;
    padding: 6px 2px;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    font-size: 11px;
  }
  .nav-item span { width: auto; font-size: 18px; }

  .main-shell {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    width: 100%;
  }

  .topbar {
    min-height: 56px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px 12px;
  }
  .topbar h1 { grid-column: 1; grid-row: 1; }
  .top-actions { grid-column: 2; grid-row: 1; justify-content: flex-end; }
  .endpoint {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
    font-size: 10px;
    line-height: 1.3;
  }
  .endpoint-url { white-space: normal; overflow-wrap: anywhere; }

  .view {
    overflow-y: auto;
    padding: 10px;
    width: 100%;
  }
  #settingsView {
    padding-bottom: calc(120px + env(safe-area-inset-bottom));
  }
  .dashboard-main,
  .messages-view-layout,
  .link-view-grid,
  .settings-view-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
    gap: 12px;
  }
  .settings-view-layout {
    display: block;
    overflow: visible;
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
    margin-bottom: calc(96px + env(safe-area-inset-bottom));
  }
  .settings-column {
    display: block;
    flex: none;
    min-height: auto;
  }
  .settings-column + .settings-column,
  .settings-column > .panel + .panel {
    margin-top: 12px;
  }
  .settings-column > .panel {
    display: block;
    flex: none !important;
    height: auto;
    min-height: auto !important;
    overflow: hidden;
  }
  .settings-view-layout .panel-head {
    display: flex;
  }
  .settings-view-layout .panel-body {
    display: block;
    flex: none;
    overflow: visible;
  }

  .dashboard-top { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat-card { min-height: 64px; padding: 10px; }
  .stat-card b { font-size: 18px; }

  .message-list-panel { min-height: 320px; flex: none; }
  .messages-view-layout > .panel { min-height: 360px; flex: none; }

  .link-detail-panel { order: 1; flex: none; }
  .preset-panel { order: 2; min-height: 180px; flex: none; }
  .link-list-panel { order: 3; min-height: 360px; flex: none; }

  .form-row { grid-template-columns: 1fr; }
  .link-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .preset-form,
  .keyword-list-actions { flex-wrap: wrap; }
  .keyword-list-actions input { width: min(100%, 220px); flex: 1 1 170px; }

  .admin-row,
  .token-row,
  .session-row {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 6px;
  }
  .row-actions { justify-content: flex-start; }
  .session-actions { align-items: flex-start; }
  .session-actions small { text-align: left; }

  .client-top {
    padding: 14px 16px;
    flex-direction: column;
    align-items: flex-start;
  }
  .client-bar { grid-template-columns: 1fr; gap: 10px; }
}

@media (max-width: 640px) {
  button { min-height: 36px; padding: 6px 10px; }
  input,
  select,
  textarea { min-height: 38px; }

  .login { padding: 14px; }
  .login-box { padding: 24px 18px; }

  .top-actions button { min-height: 34px; padding: 5px 9px; }
  .dashboard-top { grid-template-columns: 1fr 1fr; }
  .trend-chart {
    gap: 6px;
    padding: 16px 8px 8px;
  }
  .chart-bar { min-width: 34px; }
  .item-title {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .toolbar-compact {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar-compact > * { width: 100%; flex: none; }

  .message-maintenance { align-items: center; }
  .message-maintenance .muted-label { flex: 1 0 100%; }
  .message-maintenance input { width: 72px; min-height: 36px; }
  .message-maintenance button { min-height: 36px; font-size: 12px; }
  .token-actions { flex-wrap: nowrap; justify-content: flex-start; }

  .panel-head {
    min-height: 42px;
    align-items: center;
    flex-wrap: wrap;
  }

  .link-head-meta {
    justify-content: flex-start;
    flex-basis: 100%;
  }
  .link-head-meta #selectedLinkPreview { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }

  .keyword-table-header { display: none; }
  .keyword-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 10px;
    align-items: start;
    padding: 11px 12px;
  }
  .keyword-row > strong { grid-column: 1; }
  .keyword-row > :nth-child(2) { grid-column: 2; justify-self: end; }
  .keyword-row > :nth-child(3),
  .keyword-row > :nth-child(4) {
    grid-column: 1 / -1;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }
  .keyword-row > :nth-child(5) { grid-column: 2; grid-row: 1; justify-self: end; margin-top: 22px; }

  .preset-form { display: grid; grid-template-columns: 1fr; }
  .preset-form button { width: 100%; }
  .preset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .link-actions { grid-template-columns: 1fr 1fr; }

  .client-wrap { padding: 12px; gap: 12px; }
  .client-card { padding: 14px; }
  .client-meta { display: grid; gap: 4px; }
  .client-actions { display: grid; grid-template-columns: 1fr; }
  .client-actions button { width: 100%; }

  .icp-footer {
    min-height: auto;
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    flex-direction: column;
    gap: 3px;
    font-size: 10px;
    line-height: 1.25;
  }
  .icp-icon { width: 14px; height: 14px; }

  .toast {
    right: 12px;
    bottom: 76px;
  }
}
