:root {
    --page-pad: clamp(0.5rem, 2vw, 1rem);
    --section-gap: clamp(0.375rem, 1vw, 0.75rem);
    --card-pad: clamp(0.5rem, 1.4vw, 0.875rem);
    --radius: 0.5rem;
    --border-width: 0.0625rem;
    --accent-width: 0.3125rem;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    letter-spacing: 0;
    margin: 0;
    min-height: 100vh;
    padding: var(--page-pad);
}

@supports (min-height: 100dvh) {
    body {
        min-height: 100dvh;
    }
}

.container {
    background-color: #ffffff;
    border-radius: var(--radius);
    box-shadow: 0 0.625rem 1.875rem rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    gap: clamp(0.375rem, 1vw, 0.75rem);
    margin: 0 auto;
    max-width: 68.75rem;
    min-height: auto;
    padding: clamp(0.75rem, 2vw, 1.25rem);
    width: min(100%, 68.75rem);
}

@supports (min-height: 100dvh) {
    .container {
        min-height: auto;
    }
}

h1 {
    color: #007bff;
    font-size: 1.75rem;
    line-height: 1.1;
    margin: 0;
    text-align: center;
}

.subtitle {
    color: #6c757d;
    font-size: 1rem;
    margin: 0;
    text-align: center;
}

.alert {
    border-radius: calc(var(--radius) * 0.8);
    font-size: 0.95rem;
    font-weight: bold;
    margin-bottom: 0;
    padding: clamp(0.5rem, 1.5vw, 0.75rem);
    text-align: center;
}

.alert.success {
    background-color: #d4edda;
    border: var(--border-width) solid #c3e6cb;
    color: #155724;
}

.alert.error {
    background-color: #f8d7da;
    border: var(--border-width) solid #f5c6cb;
    color: #721c24;
}

.services {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: clamp(0.375rem, 1vw, 0.625rem);
    min-height: 0;
}

.service {
    align-items: start;
    border: var(--border-width) solid #e9ecef;
    border-left-width: var(--accent-width);
    border-radius: var(--radius);
    display: grid;
    gap: clamp(0.375rem, 1vw, 0.625rem) clamp(0.5rem, 1.5vw, 0.875rem);
    grid-template-areas:
        "name status"
        "actions actions";
    grid-template-columns: minmax(0, 1fr) auto;
    padding: var(--card-pad);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.service.active {
    background-color: #f6fff8;
    border-left-color: #28a745;
}

.service.inactive {
    border-left-color: #dc3545;
}

.service-name {
    color: #333;
    font-size: 1.1rem;
    font-weight: 600;
    grid-area: name;
    line-height: 1.2;
    min-width: 0;
}

.service-link {
    align-items: center;
    color: inherit;
    display: inline-flex;
    gap: 0.375rem;
    max-width: 100%;
    overflow-wrap: anywhere;
    text-decoration: none;
}

.service-link:hover,
.service-link:focus-visible {
    text-decoration: underline;
}

.service-link .link-icon {
    flex: 0 0 auto;
    font-size: 0.9em;
    opacity: 0.6;
}

.status {
    align-items: center;
    display: flex;
    font-size: 0.95rem;
    grid-area: status;
    font-weight: 500;
    justify-content: flex-start;
    line-height: 1.2;
    white-space: nowrap;
}

.status-dot {
    border-radius: 50%;
    display: inline-block;
    flex: 0 0 auto;
    height: 0.625rem;
    margin-right: 0.5rem;
    width: 0.625rem;
}

.status-dot.active {
    background-color: #28a745;
}

.status-dot.inactive {
    background-color: #dc3545;
}

button {
    background-color: #007bff;
    border: none;
    border-radius: calc(var(--radius) * 0.6);
    color: white;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.2;
    min-height: 2.4rem;
    min-width: 0;
    overflow-wrap: anywhere;
    padding: clamp(0.5rem, 1.4vw, 0.75rem) clamp(0.625rem, 1.8vw, 0.875rem);
    transition: background-color 0.2s;
    width: 100%;
}

button:hover:not(:disabled) {
    background-color: #0056b3;
}

button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
    opacity: 0.7;
}

.service-actions {
    display: grid;
    gap: clamp(0.375rem, 1vw, 0.5rem);
    grid-area: actions;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.service-actions button[data-action="start"] {
    background-color: #007bff;
}

.service-actions button[data-action="restart"] {
    background-color: #ffc107;
    color: #333;
}

.service-actions button[data-action="restart"]:hover:not(:disabled) {
    background-color: #e0a800;
}

.service-actions button[data-action="stop"] {
    background-color: #dc3545;
    color: #fff;
}

.service-actions button[data-action="stop"]:hover:not(:disabled) {
    background-color: #c82333;
}

.global-actions {
    flex-shrink: 0;
    margin-top: clamp(0.25rem, 1vw, 0.5rem);
    text-align: center;
}

.global-actions button {
    background-color: #dc3545;
    max-width: 22rem;
}

.global-actions button:hover:not(:disabled) {
    background-color: #c82333;
}

.note {
    background-color: #e9f7fe;
    border: var(--border-width) solid #b3e0ff;
    border-radius: calc(var(--radius) * 0.8);
    color: #007bff;
    flex-shrink: 0;
    font-size: 0.9rem;
    margin-top: clamp(0.25rem, 1vw, 0.5rem);
    padding: clamp(0.5rem, 1.5vw, 0.75rem);
    text-align: center;
}

#loading-overlay {
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    inset: 0;
    justify-content: center;
    position: fixed;
    z-index: 1000;
}

.spinner {
    animation: spin 1s linear infinite;
    border: 0.5rem solid #f3f3f3;
    border-radius: 50%;
    border-top-color: #007bff;
    height: 3.75rem;
    width: 3.75rem;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 56.25em) {
    .service {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .status {
        white-space: normal;
    }

}

@media (max-width: 43.75em) {
    :root {
        --page-pad: clamp(0.375rem, 2vw, 0.625rem);
        --card-pad: clamp(0.5rem, 2.5vw, 0.75rem);
    }

    .container {
        border-radius: 0;
        padding: clamp(0.625rem, 2.5vw, 0.875rem);
        width: 100%;
    }

    h1 {
        font-size: 1.35rem;
    }

    .subtitle,
    .status,
    .note {
        font-size: 0.85rem;
    }

    .service-name {
        font-size: 0.95rem;
    }

    .service {
        align-items: stretch;
        grid-template-areas:
            "name status"
            "actions actions";
    }

    .service-actions {
        gap: clamp(0.25rem, 1vw, 0.375rem);
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    button {
        font-size: 0.82rem;
        min-height: 2.25rem;
        padding: 0.5rem 0.25rem;
    }
}

@media (max-width: 25em) {
    .service {
        grid-template-areas:
            "name"
            "status"
            "actions";
        grid-template-columns: 1fr;
    }

    button {
        font-size: 0.78rem;
    }

    .note {
        text-align: left;
    }
}
