:root {
  --bg-main: #ffffff;
  --bg-header: #f5f5f5;
  --bg-input: #ffffff;
  --bg-hover: #eeeeee;
  --fg-primary: #111111;
  --fg-secondary: #666666;
  --border-color: #dddddd;
  --modal-bg: #ffffff;
  --bar-bg: #f0f0f0;

  --ok: #2e7d32;
  --warn: #ef6c00;
  --bad: #c62828;
  --accent: #1565c0;
  --ws-bg: #e3f2fd;
  --code-bg: #ffffff;
  --code-text: #111111;
}

[data-theme="dark"] {
  --bg-main: #1e1e1e;
  --bg-header: #2d2d2d;
  --bg-input: #252526;
  --bg-hover: #37373d;
  --fg-primary: #e0e0e0;
  --fg-secondary: #aaaaaa;
  --border-color: #444444;
  --modal-bg: #252526;
  --bar-bg: #333333;

  --ok: #66bb6a;
  --ws-bg: #0d47a1;
  --accent: #64b5f6;
  --code-bg: #282c34;
  --code-text: #abb2bf;
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  margin: 0; padding: 20px;
  background-color: var(--bg-main);
  color: var(--fg-primary);x
  overflow-x: hidden; touch-action: pan-x pan-y;
  transition: background-color 0.3s, color 0.3s;
}

h1 { margin: 0 0 10px; font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.row { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; }

input, select {
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-input);
  color: var(--fg-primary);
}
input { flex: 1; }

button { padding: 8px 16px; background: #222; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
[data-theme="dark"] button { background: #444; }
button:disabled { opacity: 0.3; cursor: not-allowed; background: #999; }

.legend { margin: 10px 0 20px; font-size: 12px; color: var(--fg-secondary); display: flex; gap: 15px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend span::before { content: ""; display: block; width: 10px; height: 10px; border-radius: 2px; }

.legend .dns::before { background: #9e9e9e; }
.legend .connect::before { background: #8d6e63; }
.legend .ssl::before { background: #6a1b9a; }
.legend .ttfb::before { background: var(--accent); }
.legend .download::before { background: #43a047; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  border: 1px solid var(--border-color);
  padding: 6px 8px; vertical-align: middle; white-space: nowrap;
}
th {
  background: var(--bg-header);
  color: var(--fg-primary);
  position: sticky; top: 0; z-index: 10;
  text-align: center;
}
th.sortable:hover { background: var(--bg-hover); }

.col-type, .col-btn,
th:nth-child(1), td:nth-child(1),
th:nth-child(3), td:nth-child(3),
th:nth-child(5), td:nth-child(5)
{ width: 1%; white-space: nowrap; }

.col-type {
    cursor: help; 
}

.col-url { width: auto; max-width: 1px; }
.col-url div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.col-bar { width: 1%; min-width: 300px; }

.ws-row { background-color: var(--ws-bg) !important; color: var(--fg-primary); }
.ws-text { color: var(--accent); font-weight: bold; }

.bar-container { position: relative; height: 10px; background: var(--bar-bg); border-radius: 5px; overflow: hidden; }
.bar {
position: absolute; top: 0; height: 100%; border-radius: 5px;
background: linear-gradient(90deg,
  #9e9e9e 0%, #9e9e9e var(--dnsEnd,0%),
  #8d6e63 var(--dnsEnd,0%), #8d6e63 var(--connEnd,0%),
  #6a1b9a var(--connEnd,0%), #6a1b9a var(--sslEnd,0%),
  var(--accent) var(--sslEnd,0%), var(--accent) var(--ttfbEnd,0%),
  #43a047 var(--ttfbEnd,0%), #43a047 100%
);
}
.bar.ws { background: #1565c0 !important; }

.btn-detail { background: #666; color: white; border-radius: 3px; border:none; }
.btn-detail:hover { background: #444; }

.modal-overlay {
display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.5); z-index: 1000;
justify-content: center; align-items: center;
}

.modal-window {
  background: var(--modal-bg);
  width: 80%; height: 80%;
  border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.5);
  display: flex; flex-direction: column; overflow: hidden;
  color: var(--fg-primary);
}

.modal-header {
  padding: 15px; border-bottom: 1px solid var(--border-color);
  background: var(--bg-header);
  display: flex; justify-content: space-between; align-items: center;
}

.modal-title { font-weight: bold; font-size: 16px; }
.modal-close {
  background: transparent;
  color: var(--fg-primary);
  border: none;
  font-size: 24px;
  font-weight: bold;
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover {
  background-color: var(--bad);
  color: #ffffff;
}

[data-theme="dark"] .modal-close:hover {
  background-color: #ff5252;
}
.modal-body {
  flex: 1; padding: 15px; overflow: auto;
  background: var(--code-bg);
  color: var(--code-text);
  border-top: 1px solid var(--border-color);
}

.modal-pre {
margin: 0; font-family: "Menlo", "Consolas", monospace; font-size: 13px; white-space: pre-wrap; word-break: break-all;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}
th.sortable:hover {
  background: var(--bg-hover);
}

th.sortable::after {
  content: '';
  display: none;
  margin-left: 5px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  vertical-align: middle;
}

th.sortable.asc::after {
  display: inline-block;
  border-bottom: 5px solid var(--fg-primary);
}

th.sortable.desc::after {
  display: inline-block;
  border-top: 5px solid var(--fg-primary);
}
.table-wrapper {
  width: 100%; overflow-x: auto; margin-bottom: 20px;
}

#tbl td:nth-child(3) {
    cursor: help;
}

.filter-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-controls select,
.filter-controls button {
  padding: 0 10px;
  height: 38px;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 12px;
  vertical-align: middle;
}

#clearFilter {
  background: #909090;
  color: white;
  border: 1px solid var(--border-color);
}

#themeSelect {
  margin-left: auto;
  cursor: pointer;
}

@media (max-width: 768px) {
  .filter-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .filter-controls select,
  .filter-controls button {
    width: 100%;
    height: 42px;
    margin: 0;
    font-size: 14px;
  }

  #filterCategory { grid-column: 1 / 2; }

  #filterValue { grid-column: 2 / 3; }

  #clearFilter { grid-column: 1 / 2; }

  #themeSelect { grid-column: 2 / 3; margin-left: 0; }
}

#mobileTooltip {
  visibility: hidden;
  min-width: 200px;
  max-width: 90%;
  background-color: rgba(50, 50, 50, 0.95);
  color: #fff;
  text-align: center;
  border-radius: 20px;
  padding: 12px 20px;

  position: fixed;
  z-index: 10000;
  left: 50%;
  bottom: 50px;
  transform: translateX(-50%);

  font-size: 14px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.3s, visibility 0.3s;
  pointer-events: none;
}

#mobileTooltip.show {
  visibility: visible;
  opacity: 1;
}

[data-theme="dark"] #mobileTooltip {
  background-color: rgba(255, 255, 255, 0.9);
  color: #111;
}

#status {
  margin-bottom: 5px;
  font-size: 13px;
  font-weight: 500;

  color: #555555;
  transition: color 0.3s;
}

[data-theme="dark"] #status {
  color: #cccccc;
}

.status-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  min-height: 20px;
}

.spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

[data-theme="dark"] .spinner {
  border-top-color: #64b5f6;
  border-right-color: #64b5f6;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}