/* ===== Proxy Checker v2 — giữ phong cách cũ (nền xám nhạt, card trắng, xanh #007bff) ===== */
:root {
  --primary: #007bff;
  --primary-dark: #0056b3;
  --primary-soft: #e7f1ff;
  --bg: #f4f6f9;
  --card: #fff;
  --text: #333;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --input-border: #b8c0ca;
  --live: #1e7e34;
  --live-soft: #e6f4ea;
  --dead: #c82333;
  --dead-soft: #fdecee;
  --pending: #a15c00;
  --pending-soft: #fff4e0;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, 'SFMono-Regular', Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* === HEADER === */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--primary);
}
.topbar__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
}
.topbar h1 { font-size: 1.2rem; margin: 0; line-height: 1.3; }
.topbar h1 i { color: var(--primary); margin-right: 4px; }
.topbar p { margin: 0; font-size: .875rem; color: var(--muted); }

/* === LAYOUT === */
.container {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}
@media (min-width: 992px) {
  .container { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }
  .right-column { position: sticky; top: 16px; }
}

/* === CỘT / CARD === */
.left-column,
.right-column {
  background-color: var(--card);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}

/* === TIÊU ĐỀ & NHÃN === */
h2 {
  font-size: 1.1rem;
  margin: 0 0 10px;
  color: var(--text);
}
h2 i { color: var(--primary); margin-right: 6px; }

label {
  font-weight: 600;
  display: block;
  font-size: .9rem;
}
label i { color: var(--muted); margin-right: 4px; }

/* === FORM === */
.field { margin-top: 14px; }
.field-row { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 560px) { .field-row { grid-template-columns: 3fr 2fr; } }
.field__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

select,
textarea,
input[type="search"] {
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--input-border);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* tránh iOS tự zoom */
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; font-family: var(--mono); font-size: 14px; line-height: 1.45; }
@media (max-width: 559px) { textarea { font-size: 16px; } }
select:focus, textarea:focus, input[type="search"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, .2);
}
textarea[aria-invalid="true"] { border-color: var(--dead); }

.hint {
  margin: 8px 0 0; padding: 8px 10px; font-size: .85rem;
  background: var(--primary-soft); color: var(--primary-dark); border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.field-error {
  margin: 8px 0 0; padding: 8px 10px; font-size: .875rem;
  background: var(--dead-soft); color: var(--dead); border-radius: var(--radius-sm);
}

/* === NÚT === */
button {
  font: inherit;
  background-color: var(--primary);
  color: #fff;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease, color .2s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px;
}
button:hover { background-color: var(--primary-dark); }
button:focus-visible, .tab:focus-visible { outline: 3px solid rgba(0, 123, 255, .45); outline-offset: 2px; }
button:disabled { opacity: .6; cursor: not-allowed; }

.actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn-primary { flex: 1 1 220px; font-weight: 600; font-size: 1rem; background-color: var(--primary-dark); }
.btn-primary:hover { background-color: #004494; }
.btn-danger { background: var(--dead); }
.btn-danger:hover { background: #a71d2a; }
.btn-sm { padding: 6px 10px; min-height: 34px; font-size: .85rem; background-color: var(--primary-dark); }
.btn-ghost { background: #fff; color: var(--primary-dark); border-color: var(--input-border); }
.btn-ghost:hover { background: var(--primary-soft); border-color: var(--primary); }
.btn-link {
  background: none; color: var(--primary-dark); padding: 4px 6px; min-height: 32px; font-size: .85rem;
}
.btn-link:hover { background: var(--primary-soft); }
.mini-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* === TRẠNG THÁI === */
#activeProxies,
#inactiveProxies {
  height: 150px;
}

.proxy-status { margin-top: 20px; }
.proxy-status__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.proxy-status__head h2 { margin: 0; }
.active-proxy i { color: var(--live); }
.inactive-proxy i { color: var(--dead); }

.status-live, .status-die, .status-pending, .status-wait, .status-invalid {
  display: inline-flex; align-items: center; gap: 4px;
  font-weight: 600; font-size: .8rem; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.status-live { color: var(--live); background: var(--live-soft); animation: highlightGreen 1s ease; }
.status-die { color: var(--dead); background: var(--dead-soft); animation: highlightRed 1s ease; }
.status-invalid { color: #6c4a00; background: #fbecc8; }
.status-pending { color: var(--pending); background: var(--pending-soft); }
.status-wait { color: var(--muted); background: #eef1f4; font-weight: 500; }

/* === KẾT QUẢ === */
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.results-head h2 { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-top: 12px; }
.toolbar input[type="search"] { margin-top: 0; flex: 1 1 200px; max-width: 320px; padding: 7px 10px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; background: #eef1f4; padding: 4px; border-radius: 8px; }
.tab {
  background: transparent; color: var(--muted); padding: 5px 10px; min-height: 32px; font-size: .85rem; font-weight: 600; border-radius: 6px;
}
.tab:hover { background: #fff; color: var(--text); }
.tab[aria-pressed="true"] { background: #fff; color: var(--primary-dark); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.tab span { font-weight: 500; color: inherit; opacity: .8; }

/* === BẢNG === */
.table-wrap {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  max-height: calc(100vh - 230px);
  min-height: 220px;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  border-bottom: 1px solid #edf0f3;
  padding: 8px 10px;
  font-size: 14px;
  text-align: center;
}
th {
  position: sticky; top: 0; z-index: 1;
  background-color: #f2f4f7;
  color: var(--text);
  font-weight: 600; font-size: 13px;
  border-bottom: 1px solid var(--border);
}
td.col-proxy, td.col-ip { font-family: var(--mono); font-size: 13px; word-break: break-all; text-align: left; }
th.col-proxy, th.col-ip { text-align: left; }
td.col-num { color: var(--muted); width: 1%; }
td.col-ms { white-space: nowrap; color: var(--muted); }
tbody tr:hover { background: #f8fafc; }

.results[data-filter="live"] tbody tr:not(.is-live),
.results[data-filter="dead"] tbody tr:not(.is-dead),
.results[data-filter="invalid"] tbody tr:not(.is-invalid),
.results[data-filter="diff"] tbody tr:not(.is-diff) { display: none; }
.ip-diff {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px;
  font-family: var(--font); font-size: 11px; font-weight: 600; line-height: 18px; vertical-align: middle;
  color: var(--primary-dark); background: var(--primary-soft); cursor: help;
}

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty i { font-size: 2rem; opacity: .5; }
.empty p { margin: 8px 0 0; }

@media (max-width: 599px) {
  .container { padding: 12px; gap: 12px; }
  .left-column, .right-column { padding: 14px; }
  .col-type, .col-ms { display: none; }
  th, td { padding: 7px 6px; font-size: 13px; }
  .table-wrap { max-height: 70vh; }
}

/* === LOADING SPINNER === */
.loading-spinner {
  margin: 20px auto;
  border: 6px solid #f3f3f3;
  border-top: 6px solid var(--primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  display: none;
}

/* === ANIMATION === */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@keyframes highlightGreen {
  from { box-shadow: 0 0 0 4px #b7e1c1; }
  to { box-shadow: 0 0 0 0 transparent; }
}
@keyframes highlightRed {
  from { box-shadow: 0 0 0 4px #f5c2c7; }
  to { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* === PROGRESS BAR === */
#progressContainer {
  margin-top: 20px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid var(--primary);
}
.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text);
}
.progress-bar {
  width: 100%;
  height: 14px;
  background: #e2e6ea;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .08);
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-radius: 999px;
  transition: width .3s ease;
}
.is-running .progress-fill {
  background-image: linear-gradient(45deg, rgba(255, 255, 255, .18) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .18) 50%, rgba(255, 255, 255, .18) 75%, transparent 75%), linear-gradient(90deg, var(--primary), var(--primary-dark));
  background-size: 20px 20px, 100% 100%;
  animation: stripes 1s linear infinite;
}
@keyframes stripes { from { background-position: 20px 0, 0 0; } to { background-position: 0 0, 0 0; } }

.progress-info {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.progress-info span {
  display: flex; align-items: center; gap: 5px;
  background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
}
.progress-info strong { color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; }
.stat--live i { color: var(--live); }
.stat--dead i { color: var(--dead); }
.progress-note { margin: 8px 0 0; font-size: 13px; color: var(--pending); min-height: 0; }
.progress-note:empty { display: none; }

/* === TOAST === */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: #1f2933; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: .9rem; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); z-index: 10; max-width: calc(100% - 32px);
}

/* === FOOTER === */
.footer {
  text-align: center; color: var(--muted); font-size: .8rem; padding: 4px 16px 24px;
}
