*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    [x-cloak] { display: none !important; }

    :root {
      --bg:         #0f1117;
      --surface:    #1a1d27;
      --surface2:   #12151f;
      --border:     #2a2d3e;
      --accent:     #2e5ce6;
      --accent-dim: #1e3a8a;
      --red:        #e74c3c;
      --green:      #2ecc71;
      --yellow:     #f39c12;
      --blue:       #7ec8ff;
      --purple:     #c084fc;
      --text:       #cdd6f4;
      --muted:      #8b8fa8;
      --muted2:     #4a4e6a;
      --font:       'Segoe UI', Arial, sans-serif;
      --mono:       'Courier New', Courier, monospace;
    }

    body {
      background: var(--bg);
      color: var(--text);
      font-family: var(--font);
      min-height: 100vh;
    }

    /* ── TOP BAR ── */
    .topbar {
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      padding: 0 32px;
      height: 58px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      position: sticky;
      top: 0;
      z-index: 100;
    }
    .topbar-logo {
      display: flex;
      align-items: center;
      gap: 12px;
    }
    .topbar-logo .badge {
      background: var(--accent);
      color: #fff;
      font-size: 10px;
      font-weight: 700;
      letter-spacing: 1.5px;
      padding: 3px 8px;
      border-radius: 4px;
      text-transform: uppercase;
    }
    .topbar h1 {
      font-size: 17px;
      font-weight: 700;
      color: #fff;
      letter-spacing: .3px;
    }
    .topbar-right {
      display: flex;
      align-items: center;
      gap: 16px;
    }
    .btn {
      background: var(--accent);
      color: #fff;
      border: none;
      border-radius: 6px;
      padding: 7px 16px;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      transition: opacity .15s;
      letter-spacing: .5px;
    }
    .btn:hover { opacity: .85; }
    .btn.secondary {
      background: var(--surface2);
      border: 1px solid var(--border);
      color: var(--muted);
    }
    .btn.danger { background: var(--red); }

    /* ── AUTH GATE ── */
    #auth-gate {
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: calc(100vh - 58px);
    }
    .auth-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 10px;
      padding: 40px 48px;
      width: 360px;
    }
    .auth-card h2 {
      font-size: 18px;
      margin-bottom: 6px;
      color: #fff;
    }
    .auth-card p {
      font-size: 12px;
      color: var(--muted);
      margin-bottom: 24px;
    }
    .input-group { margin-bottom: 16px; }
    .input-group label {
      display: block;
      font-size: 11px;
      font-weight: 700;
      letter-spacing: 1px;
      text-transform: uppercase;
      color: var(--muted);
      margin-bottom: 6px;
    }
    .input-group input, .input-group select {
      width: 100%;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 9px 12px;
      color: var(--text);
      font-size: 13px;
      outline: none;
      transition: border-color .15s;
    }
    .input-group input:focus, .input-group select:focus {
      border-color: var(--accent);
    }

    /* ── MAIN LAYOUT ── */
    .layout {
      display: grid;
      grid-template-columns: 240px 1fr;
      min-height: calc(100vh - 58px);
    }

    /* ── SIDEBAR ── */
    .sidebar {
      background: var(--surface);
      border-right: 1px solid var(--border);
      padding: 20px 0 0;
      position: sticky;
      top: 58px;
      height: calc(100vh - 58px);
      overflow-y: auto;
      display: flex;
      flex-direction: column;
    }
    .sidebar-nav { flex: 1; }
    .sidebar-bottom {
      margin-top: auto;
      border-top: 1px solid var(--border);
      padding: 4px 0;
    }
    .sidebar-section-title {
      font-size: 10px;
      font-weight: 700;
      letter-spacing: 1.5px;
      text-transform: uppercase;
      color: var(--muted2);
      padding: 0 20px 6px;
      margin-top: 20px;
      border-top: 1px solid var(--border);
      padding-top: 14px;
    }
    .sidebar-section-title:first-child {
      border-top: none;
      margin-top: 0;
      padding-top: 0;
    }
    .sidebar-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 9px 20px;
      font-size: 13px;
      color: var(--muted);
      cursor: pointer;
      border-left: 3px solid transparent;
      transition: background .1s, color .1s;
      user-select: none;
    }
    .sidebar-item:hover { background: var(--surface2); color: var(--text); }
    .sidebar-item.active {
      border-left-color: var(--accent);
      color: #fff;
      background: var(--surface2);
    }
    .sidebar-sub-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 6px 20px 6px 36px;
      font-size: 12px;
      color: var(--muted);
      cursor: pointer;
      border-left: 3px solid transparent;
      transition: background .1s, color .1s;
      user-select: none;
    }
    .sidebar-sub-item:hover { background: var(--surface2); color: var(--text); }
    .sidebar-sub-item.active {
      border-left-color: var(--yellow);
      color: var(--text);
      background: var(--surface2);
    }
    .sidebar-item .dot, .sidebar-sub-item .dot {
      width: 7px; height: 7px;
      border-radius: 50%;
      flex-shrink: 0;
    }
    .dot-all    { background: var(--accent); }
    .dot-site   { background: var(--yellow); }
    .dot-keys   { background: var(--muted2); }
    .badge-count {
      margin-left: auto;
      background: var(--accent-dim);
      color: var(--blue);
      font-size: 10px;
      font-weight: 700;
      padding: 1px 7px;
      border-radius: 10px;
    }

    /* ── MAIN CONTENT ── */
    .main { padding: 28px 32px; }

    /* ── STATS ROW ── */
    .stats-row {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
      gap: 16px;
      margin-bottom: 28px;
    }
    .stat-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 20px 22px;
    }
    .stat-card .label {
      font-size: 10px;
      font-weight: 700;
      letter-spacing: 1.5px;
      text-transform: uppercase;
      color: var(--muted2);
      margin-bottom: 6px;
    }
    .stat-card .value {
      font-size: 26px;
      font-weight: 700;
      color: #fff;
      line-height: 1;
    }
    .stat-card .sub {
      font-size: 11px;
      color: var(--muted);
      margin-top: 4px;
    }

    /* ── SECTION HEADER ── */
    .section-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 16px;
    }
    .section-title {
      font-size: 13px;
      font-weight: 700;
      letter-spacing: 1.2px;
      text-transform: uppercase;
      color: var(--muted);
    }

    /* ── TABLE ── */
    .table-wrap {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      overflow: hidden;
      margin-bottom: 24px;
    }
    table { width: 100%; border-collapse: collapse; }
    th {
      background: var(--surface2);
      padding: 10px 16px;
      font-size: 10px;
      font-weight: 700;
      letter-spacing: 1.2px;
      text-transform: uppercase;
      color: var(--muted2);
      text-align: left;
      border-bottom: 1px solid var(--border);
    }
    td {
      padding: 11px 16px;
      font-size: 12px;
      color: var(--text);
      border-bottom: 1px solid var(--border);
      vertical-align: top;
    }
    tr:last-child td { border-bottom: none; }
    tr:hover td { background: rgba(46,92,230,.04); }
    .truncate {
      max-width: 240px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    /* ── STATUS BADGES ── */
    .pill {
      display: inline-block;
      padding: 2px 9px;
      border-radius: 10px;
      font-size: 10px;
      font-weight: 700;
      letter-spacing: .5px;
      text-transform: uppercase;
    }
    .pill-pending  { background: #f39c1222; color: var(--yellow); border: 1px solid #f39c1244; }
    .pill-running  { background: #2e5ce622; color: var(--blue);   border: 1px solid #2e5ce644; }
    .pill-done     { background: #2ecc7122; color: var(--green);  border: 1px solid #2ecc7144; }
    .pill-error    { background: #e74c3c22; color: var(--red);    border: 1px solid #e74c3c44; }

    /* ── DETAIL MODAL ── */
    #modal-overlay {
      position: fixed; inset: 0;
      background: rgba(0,0,0,.65);
      z-index: 200;
      display: none;
      align-items: flex-start;
      justify-content: center;
      padding: 40px 20px;
      overflow-y: auto;
    }
    #modal-overlay.open { display: flex; }
    #uptime-modal-overlay {
      position: fixed; inset: 0;
      background: rgba(0,0,0,.65);
      z-index: 200;
      display: none;
      align-items: flex-start;
      justify-content: center;
      padding: 40px 20px;
      overflow-y: auto;
    }
    #uptime-modal-overlay.open { display: flex; }
    .modal {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 10px;
      width: 100%;
      max-width: 860px;
      padding: 32px;
      position: relative;
    }
    .modal-close {
      position: absolute;
      top: 16px; right: 20px;
      background: none;
      border: none;
      color: var(--muted);
      font-size: 20px;
      cursor: pointer;
    }
    .modal-close:hover { color: #fff; }
    .modal h2 {
      font-size: 16px;
      font-weight: 700;
      color: #fff;
      margin-bottom: 6px;
    }
    .modal .meta {
      font-size: 11px;
      color: var(--muted);
      margin-bottom: 20px;
    }
    .modal-section { margin-bottom: 20px; }
    .modal-section-title {
      font-size: 10px;
      font-weight: 700;
      letter-spacing: 1.5px;
      text-transform: uppercase;
      color: var(--muted2);
      margin-bottom: 8px;
    }
    .log-raw {
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 12px 14px;
      font-family: var(--mono);
      font-size: 11px;
      color: #e06c75;
      word-break: break-all;
      line-height: 1.6;
    }
    .analysis-box {
      background: #0f1a2e;
      border: 1px solid var(--accent);
      border-radius: 6px;
      padding: 16px;
      color: var(--text);
      font-size: 13px;
      line-height: 1.8;
      white-space: pre-wrap;
      word-break: break-word;
    }

    /* ── PAGINATION ── */
    .pagination {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-top: 12px;
    }
    .page-info { font-size: 12px; color: var(--muted); margin: 0 8px; }

    /* ── KEYS PANEL ── */
    .key-new-form {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 20px 24px;
      margin-bottom: 20px;
      display: flex;
      gap: 12px;
      align-items: flex-end;
    }
    .key-new-form .input-group { margin: 0; flex: 1; }
    .key-result {
      background: var(--surface2);
      border: 1px solid var(--green);
      border-radius: 6px;
      padding: 12px 16px;
      font-size: 12px;
      margin-top: 12px;
    }
    .key-result .key-value {
      font-family: var(--mono);
      color: var(--green);
      word-break: break-all;
      margin-top: 4px;
      font-size: 13px;
    }

    /* ── UPTIME ── */
    .uptime-add-form {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 20px 24px;
      margin-bottom: 20px;
      display: flex;
      gap: 12px;
      align-items: flex-end;
      flex-wrap: wrap;
    }
    .uptime-add-form .input-group { margin: 0; flex: 1; min-width: 180px; }
    .uptime-status-up   { color: var(--green); font-weight: 700; }
    .uptime-status-down { color: var(--red);   font-weight: 700; }
    .uptime-ms { color: var(--muted); font-size: 11px; font-family: var(--mono); }

    /* ── EMPTY STATE ── */
    .empty {
      text-align: center;
      padding: 60px 20px;
      color: var(--muted2);
      font-size: 13px;
    }
    .empty .big { font-size: 36px; margin-bottom: 12px; }

    /* ── SPINNER ── */
    .spinner {
      display: inline-block;
      width: 14px; height: 14px;
      border: 2px solid var(--border);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin .6s linear infinite;
      vertical-align: middle;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* ── TOAST ── */
    #toast {
      position: fixed;
      bottom: 24px; right: 24px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 12px 20px;
      font-size: 12px;
      color: var(--text);
      z-index: 300;
      opacity: 0;
      transform: translateY(8px);
      transition: opacity .2s, transform .2s;
      pointer-events: none;
    }
    #toast.show { opacity: 1; transform: none; }

    @media (max-width: 720px) {
      .layout { grid-template-columns: 1fr; }
      .sidebar { display: none; }
      .main { padding: 16px; }
    }
