/* ============================================================
   BA-Stack Manager · HaDiKo Design System
   ============================================================ */

/* --- Reset & Base ------------------------------------------ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --color-bg: #eaeaea;            /* desk */
    --surface-lowest: #f8f9fa;
    --color-white: #ffffff;         /* sheet */
    --color-primary: #3b773b;
    --color-primary-hover: #224422;
    --color-light-green-bg: #f0f7f0;
    --green-a08: rgba(59, 119, 59, .08);
    --green-a15: rgba(59, 119, 59, .15);
    --color-text: #212529;
    --color-muted: #6c757d;
    --color-danger: #d25f5d;
    --color-danger-bg: #fbeeee;
    --radius: 7px;
    --shadow-card: 0 15px 35px rgba(59, 119, 59, .06);
    --shadow-card-hover: 0 20px 45px rgba(59, 119, 59, .12);
    --font: 'Dosis', 'Helvetica Neue', Arial, sans-serif;
    --font-content: 'Roboto Slab', Georgia, serif;
    --transition: .18s ease;
}

html {
    font-family: var(--font);
    color: var(--color-text);
    background: var(--color-bg);
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

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

button {
    font-family: var(--font);
    cursor: pointer;
    border: none;
    outline: none;
}

/* --- Header ----------------------------------------------- */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: 62px;
    background: var(--color-white);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0;
}

.header-logo-link {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.header-logo {
    display: block;
    height: 26px;
    width: auto;
    transition: opacity var(--transition);
}

.header-logo:hover {
    opacity: 0.75;
}

.header-divider {
    width: 1px;
    height: 24px;
    background: var(--color-bg);
    margin: 0 16px;
    flex-shrink: 0;
}

.header-title-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.header-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.header-subtitle {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-muted);
    line-height: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-logout,
.btn-login {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 700;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    line-height: 1;
}

.btn-logout {
    background: transparent;
    color: var(--color-muted);
    border: 1px solid transparent;
}

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

.btn-login {
    background: var(--color-primary);
    color: var(--color-white);
    border: 1px solid transparent;
}

.btn-login:hover {
    background: var(--color-primary-hover);
}

/* --- Main Content ------------------------------------------ */
.main-content {
    padding: 28px 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

/* --- Labels ----------------------------------------------- */
.label-section {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-muted);
}

/* --- Buttons ---------------------------------------------- */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--color-primary);
    color: var(--color-white);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 9px 16px;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    line-height: 1;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 119, 59, 0.25);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary.btn-full {
    width: 100%;
}

.btn-secondary {
    background: var(--color-white);
    color: var(--color-primary);
    border: 1px solid var(--green-a15);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-light-green-bg);
    border-color: var(--color-primary);
}

/* --- Action Output ---------------------------------------- */
.action-output {
    background: #1a1d21;
    border-top: 3px solid var(--color-primary);
    animation: slideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.action-output-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    max-width: 1400px;
    margin: 0 auto;
}

.action-output-title {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
}

.action-output-close {
    background: transparent;
    color: rgba(255, 255, 255, 0.4);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color var(--transition), background var(--transition);
}

.action-output-close:hover {
    color: rgba(255, 255, 255, 0.8);
    background: rgba(255, 255, 255, 0.08);
}

.action-output-content {
    font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', 'Menlo', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    color: #e0e6d3;
    padding: 16px 24px;
    max-height: 320px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-width: 1400px;
    margin: 0 auto;
}

.action-output-content::-webkit-scrollbar {
    width: 6px;
}

.action-output-content::-webkit-scrollbar-track {
    background: transparent;
}

.action-output-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

/* --- Service Cards ---------------------------------------- */
.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.service-card {
    background: var(--color-white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: transform var(--transition), box-shadow var(--transition);
    position: relative;
    border: 1px solid var(--green-a08);
}

.service-card--clickable {
    cursor: pointer;
}

.service-card--clickable:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-card-hover);
}

.service-card--clickable:active {
    transform: translateY(-1px);
}

.card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.card-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.card-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-text);
    white-space: normal;
    overflow: visible;
    overflow-wrap: anywhere;
}

.card-category {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--color-muted);
    white-space: nowrap;
    background: var(--color-bg);
    padding: 3px 7px;
    border-radius: 4px;
}

.card-description {
    font-family: var(--font-content);
    font-size: 0.82rem;
    color: var(--color-muted);
    line-height: 1.5;
    flex: 1;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 6px;
    border-top: 1px solid var(--green-a15);
    gap: 8px;
}

.card-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--color-primary);
    transition: color var(--transition), gap var(--transition);
}

.card-link:hover {
    color: var(--color-primary-hover);
    gap: 7px;
}

/* --- Backing Row (untergeordnete Dienste, z.B. rt-db unter RT) --- */
.backing-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0 0 6px;
    font-family: var(--font);
    color: var(--color-muted);
}

.backing-branch {
    opacity: .5;
}

.backing-name {
    font-weight: 600;
    color: var(--color-text);
}

.backing-meta {
    margin-left: auto;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    background: var(--color-bg);
    padding: 2px 6px;
    border-radius: 4px;
}

/* --- Lifecycle Buttons (Start/Stop/Neustart) --------------- */
.lifecycle {
    display: flex;
    gap: 6px;
}

.btn-life {
    font-family: var(--font);
    font-weight: 700;
    font-size: .8rem;
    padding: 6px 12px;
    border-radius: 6px;
    background: var(--color-white);
    color: var(--color-primary);
    border: 1px solid var(--green-a15);
    cursor: pointer;
    transition: background var(--transition);
}

.btn-life:hover:not(:disabled) {
    background: var(--color-light-green-bg);
}

.btn-life:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.btn-start {
    background: var(--color-primary);
    color: var(--color-white);
    border-color: transparent;
}

/* --- Tool/Stack Actions (Wartung, kartengebundene Tool-Aktionen) --- */
.btn-toolaction {
    font-family: var(--font);
    font-weight: 700;
    font-size: .8rem;
    padding: 6px 12px;
    border-radius: 6px;
    margin-top: 8px;
    cursor: pointer;
    background: var(--color-light-green-bg);
    color: var(--color-primary);
    border: none;
}

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

.btn-danger:hover:not(:disabled) {
    filter: brightness(0.92);
}

/* .btn-toolaction can carry .btn-secondary too (Wartung, ungefährliche Aktion);
   compound selector wins on specificity regardless of source order. */
.btn-toolaction.btn-secondary {
    background: var(--color-white);
    color: var(--color-primary);
    border: 1px solid var(--green-a15);
}

.maintenance-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* --- Status Dots ------------------------------------------ */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background-color 0.4s ease;
}

.dot-green {
    background: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 119, 59, 0.18);
}

.dot-yellow {
    background: #c08a2d;
    box-shadow: 0 0 0 3px rgba(192, 138, 45, 0.18);
}

.dot-red {
    background: var(--color-danger);
    box-shadow: 0 0 0 3px rgba(210, 95, 93, 0.18);
}

.dot-gray {
    background: #adb5bd;
    box-shadow: 0 0 0 3px rgba(173, 181, 189, 0.18);
}

/* --- Status Badges ---------------------------------------- */
.status-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 99px;
    white-space: nowrap;
    transition: background-color 0.4s ease, color 0.4s ease;
    flex-shrink: 0;
}

.badge-green {
    background: var(--color-light-green-bg);
    color: var(--color-primary);
}

.badge-yellow {
    background: #fdf3e3;
    color: #a37121;
}

.badge-red {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.badge-gray {
    background: #f3f4f6;
    color: #6c757d;
}

/* --- Refresh Indicator ------------------------------------ */
.refresh-indicator {
    display: flex;
    align-items: center;
    cursor: default;
}

.refresh-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-primary);
    animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

/* --- Page Footer ------------------------------------------ */
.page-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 8px;
    margin-top: 8px;
}

.last-updated {
    display: flex;
    align-items: center;
    gap: 7px;
}

.last-updated-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-muted);
    opacity: 0.5;
}

#last-updated-text {
    font-size: 0.78rem;
    color: var(--color-muted);
}

.footer-admin-link {
    font-size: 0.78rem;
    color: var(--color-muted);
    font-weight: 600;
    transition: color var(--transition);
}

.footer-admin-link:hover {
    color: var(--color-primary);
}

/* --- Login Page ------------------------------------------- */
.login-page {
    min-height: calc(100vh - 62px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    background: var(--color-white);
    border-radius: calc(var(--radius) * 1.5);
    box-shadow: var(--shadow-card);
    padding: 36px 32px;
    width: 100%;
    max-width: 360px;
    animation: fadeInUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.login-header {
    margin-bottom: 28px;
    text-align: center;
}

.login-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--color-text);
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.login-subtitle {
    font-size: 0.88rem;
    color: var(--color-muted);
    line-height: 1.4;
}

.login-error {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border: 1px solid rgba(210, 95, 93, 0.25);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 18px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-muted);
}

.form-input {
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    width: 100%;
    padding: 10px 13px;
    border: 1.5px solid #ced4da;
    border-radius: var(--radius);
    background: var(--color-white);
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
    -webkit-appearance: none;
}

.form-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 119, 59, 0.12);
}

.form-input::placeholder {
    color: #adb5bd;
    font-weight: 400;
}

.login-footer {
    margin-top: 20px;
    text-align: center;
    padding-top: 18px;
    border-top: 1px solid var(--green-a15);
}

.login-back-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-muted);
    transition: color var(--transition);
}

.login-back-link:hover {
    color: var(--color-primary);
}

/* --- Animations ------------------------------------------- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Status change flash */
@keyframes statusFlash {
    0% { opacity: 1; }
    40% { opacity: 0.4; }
    100% { opacity: 1; }
}

.status-changed {
    animation: statusFlash 0.5s ease;
}

/* --- Restart feedback overlays on card ------------------- */
.card-toast {
    position: absolute;
    bottom: 12px;
    right: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 5px;
    animation: fadeIn 0.2s ease, fadeOut 0.3s ease 1.7s forwards;
    pointer-events: none;
    z-index: 10;
}

.card-toast--success {
    background: var(--color-light-green-bg);
    color: var(--color-primary);
    border: 1px solid var(--green-a15);
}

.card-toast--error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
    border: 1px solid rgba(210, 95, 93, 0.25);
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* --- Responsive ------------------------------------------- */
@media (max-width: 640px) {
    .header-inner {
        padding: 0 16px;
    }

    .header-title-group {
        display: none;
    }

    .main-content {
        padding: 20px 16px;
    }

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

    .login-card {
        padding: 28px 22px;
    }

    .action-output-content {
        padding: 12px 16px;
    }
}

/* ── Session Countdown Timer ─────────────────────────────── */
.session-timer {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-light-green-bg);
    border: 1px solid var(--green-a15);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--color-muted);
}

.session-timer svg {
    flex-shrink: 0;
    color: var(--color-primary);
}

.timer-countdown {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--color-primary);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    min-width: 44px;
    transition: color 0.3s ease;
}

.timer-countdown.timer-warn {
    color: #c08a2d;
}

.timer-countdown.timer-danger {
    color: var(--color-danger);
    animation: timerPulse 1s ease-in-out infinite;
}

.timer-countdown.timer-extended {
    color: var(--color-primary);
    animation: timerBounce 0.4s ease;
}

@keyframes timerPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.55; }
}

@keyframes timerBounce {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.timer-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.btn-extend {
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: calc(var(--radius) - 1px);
    padding: 4px 10px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition);
    white-space: nowrap;
}

.btn-extend:hover {
    background: var(--color-primary-hover);
}

.btn-extend:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Service Groups ──────────────────────────────────────── */
.service-group {
    margin-bottom: 8px;
}

.service-group--infra .services-grid {
    /* slightly more compact grid for infra services */
}

.services-grid--compact {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.service-card--infra {
    /* Infra cards: slightly subdued appearance */
    opacity: 0.92;
}

.service-card--infra:hover {
    opacity: 1;
}

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 72px 24px;
    text-align: center;
}

.empty-state-icon {
    color: var(--color-muted);
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
}

.empty-state-text {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--color-muted);
    max-width: 280px;
    line-height: 1.5;
}

/* ── Timer responsive ────────────────────────────────────── */
@media (max-width: 768px) {
    .session-timer {
        gap: 6px;
        padding: 5px 8px;
    }
    .timer-label {
        display: none;
    }
}

@media (max-width: 560px) {
    .session-timer {
        display: none !important; /* on very small screens, rely on the countdown showing elsewhere */
    }
}
