/* Xray Checker Admin — matches monitoring UI theme */
:root {
  --bg-primary: #0f1114;
  --bg-secondary: #1a1d21;
  --bg-tertiary: #23262b;
  --border: #2d3138;
  --border-hover: #3e434b;
  --text-primary: #cdcdcd;
  --text-secondary: #9ca3af;
  --text-muted: #5c6370;
  --hover-bg: rgba(255, 255, 255, 0.08);
  --accent: #294bff;
  --accent-hover: #1e3dd4;
  --color-green: #3aff82;
  --color-red: #ff3232;
  --color-yellow: #ffae00;
  --header-h: 56px;
  --radius: 10px;
  --radius-lg: 14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-primary);
  color: var(--text-secondary);
  line-height: 1.5;
  min-height: 100vh;
  font-size: 14px;
}

a { color: inherit; text-decoration: none; }

.text-muted { color: var(--text-muted); }

/* ===== AUTH / LOGIN ===== */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

.auth-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(41, 75, 255, 0.18), transparent),
    radial-gradient(ellipse 50% 40% at 80% 80%, rgba(58, 255, 130, 0.06), transparent),
    var(--bg-primary);
  pointer-events: none;
}

.auth-container {
  position: relative;
  width: 100%;
  max-width: 420px;
}

.auth-card {
  padding: 2.5rem 2rem;
}

.auth-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.brand-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  background: rgba(41, 75, 255, 0.15);
  border: 1px solid rgba(41, 75, 255, 0.3);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4f8cff;
}

.brand-icon svg { width: 28px; height: 28px; }

.auth-brand h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.auth-brand p { margin-top: 0.25rem; font-size: 0.875rem; }

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.75rem;
}

/* ===== APP LAYOUT ===== */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  height: var(--header-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { flex-shrink: 0; }

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9375rem;
}

.brand svg { width: 20px; height: 20px; color: #4f8cff; }

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 0 0 auto;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
}

.tool-btn-grid.tool-btn-active {
  background: rgba(58, 255, 130, 0.1);
  border-color: rgba(58, 255, 130, 0.25);
  color: var(--color-green);
}

body.grid-fullscreen-mode .app-header {
  height: 2.5rem;
  padding: 0 0.75rem;
  gap: 0.5rem;
}

body.grid-fullscreen-mode .header-left,
body.grid-fullscreen-mode .header-nav,
body.grid-fullscreen-mode .header-tools,
body.grid-fullscreen-mode .user-badge {
  display: none !important;
}

body.grid-fullscreen-mode .header-center {
  flex: 1;
  justify-content: flex-start;
}

body.grid-fullscreen-mode .header-right {
  gap: 0.375rem;
}

body.grid-fullscreen-mode .monitor-main {
  height: calc(100vh - 2.5rem);
}

body.grid-fullscreen-mode .monitor-frame {
  height: 100%;
}

@media (max-width: 768px) {
  .header-center .grid-mode-label { display: none; }
  body.grid-fullscreen-mode .header-left .brand span { display: none; }
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 0.875rem;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s;
  white-space: nowrap;
}

.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }

.nav-link:hover {
  color: var(--text-primary);
  background: var(--hover-bg);
}

.nav-link.active {
  color: var(--color-green);
  background: rgba(58, 255, 130, 0.1);
  border: 1px solid rgba(58, 255, 130, 0.2);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 0;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

.tool-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2rem;
  font-size: 0.6875rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 0 0.625rem;
  border-radius: 8px;
  line-height: 1;
  white-space: nowrap;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  height: 2rem;
  min-width: 2rem;
  padding: 0 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.6875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.tool-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

.tool-btn-active {
  background: rgba(58, 255, 130, 0.1);
  border-color: rgba(58, 255, 130, 0.25);
  color: var(--color-green);
}

.tool-btn-active #xc-refresh-icon {
  animation: monitor-spin 2s linear infinite;
}

.tool-btn-icon-only {
  width: 2rem;
  min-width: 2rem;
  padding: 0;
  position: relative;
}

.tool-btn-icon-only .tool-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.tool-icon {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
  display: block;
}

.tool-countdown {
  min-width: 2rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  height: 2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 0 0.625rem;
  border-radius: 8px;
  flex-shrink: 0;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
}

.mobile-menu-btn svg { width: 22px; height: 22px; }

/* ===== MAIN CONTENT ===== */
.page-main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-header p { margin-top: 0.25rem; font-size: 0.875rem; }

.monitor-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: calc(100vh - var(--header-h));
}

.monitor-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--bg-primary);
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.section-card {
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.section-head {
  margin-bottom: 1.25rem;
  padding-bottom: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.section-head h2 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.section-head p { font-size: 0.8125rem; margin-top: 0.125rem; }

/* ===== FORM ===== */
.fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input[type="text"],
.field input[type="url"],
.field input[type="password"],
.field input[type="number"],
.field select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: border-color 0.15s;
  appearance: none;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(41, 75, 255, 0.15);
}

.field-check { display: flex; align-items: center; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: normal;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.subscriptions-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.875rem; }

.subscription-row {
  display: grid;
  grid-template-columns: 1fr minmax(7rem, 9rem) 2.5rem 2.25rem;
  gap: 0.5rem;
  align-items: center;
}

.subscription-row input[type="url"],
.subscription-row input[type="text"] {
  min-width: 0;
}

.sub-name { font-size: 0.8125rem; }

.sub-color-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  cursor: pointer;
  overflow: hidden;
  flex-shrink: 0;
}

.sub-color-wrap:hover { border-color: var(--border-hover); }

.sub-color {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.sub-color::-webkit-color-swatch-wrapper { padding: 0; }
.sub-color::-webkit-color-swatch { border: none; border-radius: 4px; }
.sub-color::-moz-color-swatch { border: none; border-radius: 4px; }

@media (max-width: 640px) {
  .subscription-row {
    grid-template-columns: 1fr 2.5rem 2.25rem;
    grid-template-rows: auto auto;
  }
  .subscription-row .sub-url { grid-column: 1 / -2; }
  .subscription-row .sub-name { grid-column: 1; }
  .subscription-row .sub-color-wrap { grid-row: 2; grid-column: 2; }
  .subscription-row .btn-icon { grid-row: 1 / 3; grid-column: 3; align-self: center; }
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5625rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { border-color: var(--border-hover); color: var(--text-primary); }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-secondary { background: var(--bg-tertiary); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover { background: var(--hover-bg); color: var(--text-primary); }

.btn-danger {
  background: rgba(255, 50, 50, 0.12);
  border-color: rgba(255, 50, 50, 0.25);
  color: #ff6b6b;
}

.btn-danger:hover { background: rgba(255, 50, 50, 0.2); }

.btn-icon { padding: 0.5rem; }
.btn-icon svg { width: 16px; height: 16px; }
.btn-sm {
  padding: 0 0.75rem;
  height: 2rem;
  font-size: 0.8125rem;
  display: inline-flex;
  align-items: center;
}
.btn-lg { padding: 0.75rem 1.5rem; font-size: 0.9375rem; }
.btn-block { width: 100%; }

.form-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg-primary) 60%, transparent);
  padding: 1.25rem 0 0.5rem;
  margin-top: 0.5rem;
}

/* ===== ALERTS ===== */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  border: 1px solid;
}

.alert-error {
  background: rgba(255, 50, 50, 0.1);
  border-color: rgba(255, 50, 50, 0.25);
  color: #ff8a8a;
}

.alert-success {
  background: rgba(58, 255, 130, 0.1);
  border-color: rgba(58, 255, 130, 0.25);
  color: #6bffb0;
}

.code-block {
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.8125rem;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .mobile-menu-btn { display: flex; }

  .header-nav {
    display: none;
    position: absolute;
    top: var(--header-h);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 0.5rem;
    gap: 0.25rem;
  }

  body.nav-open .header-nav { display: flex; }

  .nav-link { width: 100%; padding: 0.75rem 1rem; }

  .header-right .user-badge { display: none; }

  .header-tools .tool-badge { display: none; }

  .tool-countdown { min-width: 1.75rem; }

  .auth-card { padding: 2rem 1.25rem; }

  .fields-grid { grid-template-columns: 1fr; }

  .page-main { padding: 1rem 0.75rem 2rem; }

  .section-card { padding: 1rem; }

  .form-actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 0.875rem 1rem;
    z-index: 50;
  }

  .page-main { padding-bottom: 5rem; }
}

@media (max-width: 480px) {
  .auth-layout { padding: 1rem; }
  .brand span { display: none; }
  .nav-link span { display: inline; }
}

@media (min-width: 769px) {
  .app-header { padding: 0 1.5rem; }
  .page-main { padding: 2rem 1.5rem 3rem; }
}

.monitor-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 4rem);
  color: var(--text-muted, #94a3b8);
  gap: 1rem;
}

.monitor-loading--hidden { display: none; }

.monitor-spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--border, #2a3441);
  border-top-color: var(--accent, #3b82f6);
  border-radius: 50%;
  animation: monitor-spin 0.8s linear infinite;
}

@keyframes monitor-spin { to { transform: rotate(360deg); } }

.monitor-frame--hidden { display: none; }
