:root {
  --bg-dark: #0f111a;
  --bg-card: #1a1d2d;
  --primary: #00ffbd;
  --primary-hover: #00e6aa;
  --text-main: #ffffff;
  --text-muted: #8b9bb4;
  --danger: #ff4757;
  --font-main: 'Inter', -apple-system, blinkmacsystemfont, "Segoe UI", roboto, oxygen, ubuntu, cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

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

body {
  font-family: var(--font-main);
  background: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.app-background {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 50% 30%, #1a2542 0%, #0f111a 70%);
  z-index: -1;
  pointer-events: none;
}

/* --- Top Bar --- */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

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

.brand .icon {
  width: 24px;
  height: 24px;
  color: var(--primary);
}

.status-container {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

/* Renamed to .status to match client.js behavior */
.status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 5px var(--danger);
}

.connected.status {
    border: 1px solid rgba(0, 255, 189, 0.2);
}

.connected .status-dot {
  background: var(--primary);
  box-shadow: 0 0 5px var(--primary);
}

.connected .status-text {
    color: var(--primary);
}

.disconnected .status-text {
    color: var(--danger);
}

.server-config {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.server-selector-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.minimal-select {
    background: transparent;
    color: var(--text-muted);
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    text-align: right;
    appearance: none;
    padding-right: 1.5rem;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%238b9bb4%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 0 center;
    background-size: 0.65em auto;
}

.minimal-select:focus {
    outline: none;
    color: var(--text-main);
}

.minimal-select option,
#profile-select option {
    background-color: var(--bg-card);
    color: var(--text-main);
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-main);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.icon-btn svg {
  display: block;
}

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

/* --- Main Interface --- */
.main-interface {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 5vh;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.hero-section {
    text-align: center;
    width: 100%;
}

.hero-title {
    font-size: 1.5rem;
    font-weight: 300;
    margin-bottom: 2rem;
    opacity: 0.8;
}

.input-cluster {
    margin-bottom: 3rem;
    width: 100%;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

#url-input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    font-size: 2rem;
    color: var(--text-main);
    padding: 0.5rem 0;
    text-align: center;
    font-weight: 300;
    transition: all 0.3s ease;
}

#url-input::placeholder {
  color: rgba(255, 255, 255, 0.2);
}

#url-input:focus {
    outline: none;
    border-bottom-color: var(--primary);
}

.controls-cluster {
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
}

.setting-pill {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
}

.setting-pill label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
}

#profile-select {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
}
#profile-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* --- Combined Action Button --- */
.action-area {
    display: flex;
    justify-content: center;
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.circle-action-btn {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    position: relative;
    border: none;
    outline: none;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.circle-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Start State Styling */
.circle-action-btn .btn-content {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.circle-action-btn .start-state {
    border: 4px solid rgba(0, 255, 189, 0.3);
    color: var(--primary);
    transition: all 0.3s ease;
}

.circle-action-btn:not(.running):hover .start-state {
    border-color: var(--primary);
    background: rgba(0, 255, 189, 0.05);
    box-shadow: 0 0 30px rgba(0, 255, 189, 0.2);
}

.circle-action-btn:not(.running):active {
    transform: scale(0.95);
}

.btn-label {
    font-size: 2rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Running State Styling */
.circle-action-btn .running-state {
    /* No border here, handled by SVG */
}

.progress-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg); /* Start from top */
}

.progress-ring-circle-bg {
    fill: transparent;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 4;
}

.progress-ring-circle {
    fill: transparent;
    stroke: var(--primary);
    stroke-width: 4;
    stroke-dasharray: 283; /* 2 * pi * 45 */
    stroke-dashoffset: 283; /* Start empty */
    transition: stroke-dashoffset 0.5s ease;
    stroke-linecap: round;
}

/* Indeterminate spin animation when we don't know % yet or just to show activity */
.circle-action-btn.running .progress-ring {
    animation: slow-spin 4s linear infinite;
}

@keyframes slow-spin {
    from { transform: rotate(-90deg); }
    to { transform: rotate(270deg); }
}

.inner-status {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#btn-progress-percent {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.cancel-label {
    position: absolute;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--danger);
    text-transform: uppercase;
    opacity: 0;
    transition: opacity 0.2s ease;
    background: rgba(15, 17, 26, 0.9); /* visual cover */
    padding: 0.5rem 1rem;
    border-radius: 4px;
}

/* Hover on running button shows Cancel */
.circle-action-btn.running:hover .cancel-label {
    opacity: 1;
}

.circle-action-btn.running:hover #btn-progress-percent {
    opacity: 0.1; /* Dim percentage */
}

.circle-action-btn.running:hover .progress-ring-circle {
    stroke: var(--danger); /* Turn ring red */
}

/* Status Display Below */
.status-display {
    text-align: center;
    margin-top: 1rem;
    min-height: 60px;
    animation: fadeIn 0.5s ease;
}

.stage-text {
    display: block;
    color: var(--primary);
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.detail-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    max-width: 500px;
    margin: 0 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hidden {
    display: none !important;
}

.big-go-btn:hover::after {
    animation-play-state: running;
}

.big-go-btn:disabled {
    border-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.2);
    cursor: not-allowed;
    transform: none;
}

.btn-text-large {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 2px;
}

@keyframes ripple {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.2); opacity: 0; }
}

/* --- Progress Section --- */
.progress-display {
    margin-top: 3rem;
    text-align: center;
}

.gauge-loader {
    width: 150px;
    height: 150px;
    position: relative;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner-ring {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { 100% { transform: rotate(360deg); } }

.progress-stats {
    display: flex;
    flex-direction: column;
}

#progress-percent {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

.stage-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.detail-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 2rem;
    word-break: break-word;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.progress-bar-container {
    width: 100%;
    max-width: 400px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin: 1.5rem auto 2rem;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.spinner-ring.stopped {
    animation: none;
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(0, 255, 189, 0.3);
}

.tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    font-size: 10px;
    cursor: help;
    margin-left: 0.5rem;
    position: relative;
}

.tooltip-icon:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    padding: 0.5rem 0.8rem;
    border-radius: 4px;
    font-size: 0.8rem;
    white-space: pre-wrap;
    width: max-content;
    max-width: 200px;
    margin-bottom: 0.5rem;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    text-align: left;
    font-weight: 400;
}

/* --- Filter Bar --- */
.filter-bar {
    display: flex;
    justify-content: flex-start;
    gap: 0.5rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.filter-btn.active {
    background: rgba(0, 255, 189, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

.audit-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-danger-outline {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.5rem 2rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-danger-outline:hover {
    background: rgba(255, 71, 87, 0.1);
}

/* --- Results --- */
.results-container {
    width: 100%;
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 12px;
    margin-top: 3rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.results-header h2 {
    font-weight: 300;
    margin-bottom: 1.5rem;
    color: var(--text-main);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 1rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
}

/* Style for metric items created by JS */
.metric-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
}

.metric-value {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: block;
}

.metric-label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* JS Compatible Color Classes */
.score-good { color: var(--primary); }
.score-average { color: #ffaa00; }
.score-poor { color: var(--danger); }

.metric-good { color: var(--primary); }
.metric-ok { color: #ffaa00; }
.metric-bad { color: var(--danger); }

/* --- Report Section --- */
.report-container {
    width: 100%;
    margin-top: 2rem;
    padding-bottom: 4rem;
}

.report-actions-bar {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.btn-primary {
    background: var(--primary);
    color: #000;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 30px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-main);
    padding: 0.75rem 2rem;
    border-radius: 30px;
    cursor: pointer;
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
}

#report-frame {
    width: 100%;
    height: 100vh;
    min-height: 800px;
    border: none;
    background: white;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
}

/* --- Report Summary Styles (Core Vitals) --- */
.summary-metrics {
    margin-bottom: 3rem; 
}
.summary-metrics h3 {
    margin-bottom: 1.5rem;
    color: var(--text-main);
    font-weight: 600;
    font-size: 1.2rem;
    border-left: 4px solid var(--primary);
    padding-left: 1rem;
}

.vitals-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .vitals-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 500px) {
    .vitals-grid {
        grid-template-columns: 1fr;
    }
}

.summary-metric {
    background: rgba(255,255,255,0.05);
    padding: 2rem 1.5rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: transform 0.2s, background 0.2s;
    border: 1px solid rgba(255,255,255,0.05);
}

.summary-metric:hover {
    transform: translateY(-2px);
    background: rgba(255,255,255,0.08);
}

.summary-metric-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.8rem;
    font-weight: 600;
}
.summary-metric-value {
    font-weight: 800;
    font-size: 2rem;
    color: var(--text-main);
}



/* --- Modal & Hidden --- */
.hidden {
    display: none !important;
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-content h3 {
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1.5rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}
.form-group input {
    width: 100%;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: white;
}
.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}
.btn-text:hover { color: white; }

/* Error status */
.error-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: #2a1515;
    border-left: 4px solid var(--danger);
    padding: 1rem 1.5rem;
    border-radius: 4px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.error-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: #ff8a93;
}

/* --- Audit Details Styling --- */
.audit-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-top: 2rem;
}

.audit-item {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.2s, border-color 0.2s;
}

.audit-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

.audit-header {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    cursor: pointer;
    gap: 1.2rem;
    user-select: none;
}

.audit-status {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1rem;
    flex-shrink: 0;
}

.audit-pass .audit-status { color: var(--primary); background: rgba(0, 255, 189, 0.15); box-shadow: 0 0 10px rgba(0,255,189,0.1); }
.audit-average .audit-status { color: #ffaa00; background: rgba(255, 170, 0, 0.15); }
.audit-fail .audit-status { color: var(--danger); background: rgba(255, 71, 87, 0.15); box-shadow: 0 0 10px rgba(255,71,87,0.1); }

.audit-title {
    flex: 1;
    font-weight: 500;
    color: var(--text-main);
    font-size: 1.05rem;
}

.audit-arrow {
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.audit-arrow.rotated {
    transform: rotate(90deg);
    color: var(--primary);
}

.audit-content {
    padding: 0 1.5rem 1.5rem 4.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(0, 0, 0, 0.1);
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.6;
    animation: fadeIn 0.3s ease;
}

.audit-content.hidden {
    display: none;
}

.audit-description {
    margin-bottom: 0.5rem;
}

.audit-display-value {
    font-weight: 700;
    color: var(--text-main);
    margin-top: 0.5rem;
}

.audit-table {
    width: 100%;
    margin-top: 1rem;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.audit-table th {
    text-align: left;
    padding: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    font-weight: 600;
}

.audit-table td {
    padding: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile Menu Placeholder Area */
#mobile-menu-placeholder {
    width: 100%;
    margin-bottom: 2rem;
    min-height: 0;
}

#mobile-menu-placeholder:not(:empty) {
    display: flex;
    justify-content: center;
}

@media (max-width: 768px) {
    .main-interface {
        padding-top: 2rem;
    }
    
    .hero-title {
        font-size: 1.2rem;
    }
    
    #url-input {
        font-size: 1.5rem;
    }

    /* Ensure the moved menu allows wrapping on small screens */
    #mobile-menu-placeholder .status-container {
        flex-wrap: wrap;
        justify-content: center;
        gap: 1rem;
    }
}

