/* Use the provided CSS variables and base styles */
:root {
    --color-background-light: #F9F7F3;
    --color-panel-background: #ECE6D8;
    --color-text-dark: #4A4A4A;
    --color-text-light: #F9F7F3;
    --color-border-subtle: #D1C7B1;
    --color-accent-primary: #6B8E23;
    --color-accent-secondary: #d7611f;
    --color-accent-tertiary: #4F6F52;
    --border-radius-base: 10px;
    --padding-base: 15px;
    --margin-base: 20px;
    --font-monospace: 'Roboto Mono', 'SF Mono', 'Ubuntu Mono', 'Cascadia Code', monospace;
    --font-size-body: 1em;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--font-monospace);
    font-size: var(--font-size-body);
    background-color: var(--color-background-light);
    color: var(--color-text-dark);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* Login page specific styles */
body.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
}

/* Style the login container box to match landing-box */
.login-page .login-container.panel {
    background-color: var(--color-panel-background);
    padding: 40px;
    border-radius: var(--border-radius-base);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 500px;
    width: 100%;
    min-height: auto; /* Override panel's min-height */
}

/* Main layout */
#admin-dashboard {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--padding-base);
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--padding-base);
}

/* Header */
#header-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--padding-base);
    background: var(--color-panel-background);
    border-radius: var(--border-radius-base);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    margin-bottom: var(--margin-base);
}

.admin-badge {
    background: var(--color-accent-secondary);
    color: var(--color-text-light);
    padding: 8px 16px;
    border-radius: var(--border-radius-base);
    font-weight: bold;
    font-size: 0.9em;
}

/* Grid layout for dashboard sections */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--padding-base);
}

/* Panel styling */
.panel {
    background: var(--color-panel-background);
    border-radius: var(--border-radius-base);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    padding: var(--padding-base);
    min-height: 200px;
}

.panel-header {
    font-size: 1.2em;
    color: var(--color-accent-tertiary);
    margin: 0 0 var(--padding-base) 0;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
    width: auto; /* style.css's .panel-header (interpreter/broadcaster) sets
                    width:100%, which as a flex item of .panel-header-actions
                    claims the whole row and forces the button to wrap every
                    time; a plain block element fills its container at
                    width:auto anyway, so this is a no-op for standalone use */
}

.panel-icon {
    font-size: 1.3em;
}

/* Button styles */
.glossais-button {
    font-family: var(--font-monospace);
    font-size: 1em;
    padding: 12px 24px;
    border-radius: var(--border-radius-base);
    border: none;
    cursor: pointer;
    margin: 5px;
    transition: all 0.2s;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    width: auto; /* style.css's .glossais-button (written for the interpreter
                    page) sets width/height: 100%, which leaks in here since
                    this rule never used to override it */
    height: auto;
    /* Reset native <button> chrome so it renders identically to an <a>
       with the same classes (some browsers apply UA button styling that
       anchors never get) */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-color: transparent; /* variant classes (.button-primary etc.) set the real background */
    line-height: normal;
    vertical-align: middle;
}

/* Firefox adds an invisible inner border/padding to <button> (but not <a>)
   via this pseudo-element, making otherwise-identical buttons render
   slightly smaller/off-center compared to anchors */
.glossais-button::-moz-focus-inner {
    border: 0;
    padding: 0;
}

.button-primary {
    background: var(--color-accent-primary);
    color: var(--color-text-light);
}

.button-primary:hover {
    background: var(--color-accent-tertiary);
}

.button-secondary {
    background: var(--color-accent-secondary);
    color: var(--color-text-light);
}

.button-secondary:hover {
    background: #b8541a;
}

.button-danger {
    background: #dc3545;
    color: var(--color-text-light);
}

.button-danger:hover {
    background: #c82333;
}

.button-small {
    padding: 8px 16px;
    font-size: 0.9em;
    margin: 0;
}

/* Status indicators */
.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
}

.status-healthy { background: #4caf50; }
.status-warning { background: #ff9800; }
.status-error { background: #d32f2f; }

/* KPI cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.kpi-card {
    background: #fff;
    border-radius: var(--border-radius-base);
    padding: 15px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.kpi-value {
    font-size: 2em;
    font-weight: bold;
    color: var(--color-accent-primary);
    margin: 0;
}

.kpi-label {
    font-size: 0.9em;
    color: var(--color-text-dark);
    margin: 5px 0 0 0;
}

/* Session list */
.session-list {
    max-height: 300px;
    overflow-y: auto;
    background: #fff;
    border-radius: var(--border-radius-base);
    padding: 0;
    margin: 0;
}

.session-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid var(--color-border-subtle);
    transition: background 0.2s;
}

.session-item:hover {
    background: #f5f5f5;
}

.session-item:last-child {
    border-bottom: none;
}

.session-info {
    flex: 1;
}

.session-id {
    font-weight: bold;
    color: var(--color-accent-primary);
    font-size: 0.9em;
}

.session-details {
    font-size: 0.8em;
    color: #666;
    margin-top: 2px;
}

/* Feedback items */
.feedback-item {
    background: #fff;
    border-radius: var(--border-radius-base);
    padding: 12px;
    margin-bottom: 10px;
    border-left: 4px solid var(--color-accent-primary);
}

.feedback-rating {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 5px;
}

.stars {
    color: #ffc107;
}

.feedback-text {
    font-size: 0.9em;
    color: #666;
}

/* System health */
.health-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border-subtle);
}

.health-item:last-child {
    border-bottom: none;
}

/* Config forms */
.config-form {
    background: #fff;
    border-radius: var(--border-radius-base);
    padding: 15px;
}

.form-group {
    margin-bottom: 15px;
}

.form-label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--color-accent-tertiary);
}

.form-input, .form-textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--border-radius-base);
    font-family: var(--font-monospace);
    font-size: 0.9em;
    background: var(--color-background-light);
}

.form-textarea {
    height: 100px;
    resize: vertical;
}

.form-input:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--color-accent-primary);
    box-shadow: 0 0 0 2px rgba(107, 142, 35, 0.2);
}

/* Error message styling */
.error-message {
    color: #d32f2f;
    margin-bottom: 15px;
    text-align: center;
    padding: 10px;
    border-radius: var(--border-radius-base);
    background-color: rgba(211, 47, 47, 0.1);
}

/* Logout button styles */
.navbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.navbar-button {
    background-color: var(--color-accent-tertiary);
    color: var(--color-text-light);
    padding: 8px 16px;
    border-radius: var(--border-radius-base);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9em;
    transition: background-color 0.2s;
}

.navbar-button:hover {
    background-color: #3d563f;
}

/* System status styling */
#system-status {
    margin: 0 auto 20px;
    width: 100%;
    max-width: 600px;
}

.status-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
    max-width: 600px;
    margin: 0 auto 20px auto;
    background: #fffef9;
    border-radius: var(--border-radius-base);
    box-shadow: 0 2px 8px rgba(107, 142, 35, 0.08), 0 0 0 2px var(--color-border-subtle);
    padding: 0;
    overflow: hidden;
}

.status-row {
    display: grid;
    grid-template-columns: 1fr 2.5fr 0.5fr;
    align-items: center;
    padding: 8px 8px 8px 14px;
    min-height: 28px;
    border-bottom: 1px solid #e2dbc7;
    background: transparent;
    font-size: 0.98em;
    transition: background 0.15s;
}

.status-row:last-child {
    border-bottom: none;
}

.status-label {
    font-weight: bold;
    color: var(--color-accent-tertiary);
    text-align: right;
    padding: 8px 14px 8px 0;
    font-size: 1.08em;
    letter-spacing: 0.02em;
}

.status-value {
    text-align: left;
    word-break: break-all;
    padding: 8px 0 8px 8px;
    font-size: 1.08em;
}

/* Header user section styling */
#header-user-section {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    row-gap: 8px;
    padding: 12px 20px;
    /* margin-bottom: 30px; */
    background-color: var(--color-panel-background);
    border-radius: var(--border-radius-base);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.user-greeting {
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: 500;
    color: var(--color-accent-tertiary);
    font-size: 1.05em;
}

.user-greeting span {
    padding-left: 5px;
    color: var(--color-text-dark);
    font-weight: 600;
}

.user-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    margin-left: auto;
}

/* Action button styling */
.session-actions a.action-button {
    text-decoration: none; /* Remove underline */
    color: var(--color-text-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background-color: rgba(107, 142, 35, 0.1);
    transition: all 0.2s ease;
}

.session-actions a.action-button:hover {
    background-color: rgba(107, 142, 35, 0.2);
    transform: translateY(-2px);
}

/* Special styling for Current Sessions Panel */
#current-sessions-panel {
    grid-column: 1 / -1; /* Make it span the full width on all screen sizes */
    overflow: hidden; /* Prevent overflow issues */
}

/* Card-based layout for mobile view */
@media (max-width: 768px) {
    .sessions-table-container {
        margin-top: 15px;
    }
    
    /* Make clickable rows more obviously clickable */
    .sessions-table tr {
        position: relative;
        transition: transform 0.2s, box-shadow 0.2s;
        cursor: pointer;
    }
    
    .sessions-table tr:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    }
    
    /* Add visual indication for clickable rows */
    .sessions-table tr::after {
        content: "→";
        position: absolute;
        top: 10px;
        right: 10px;
        font-size: 1.2em;
        color: var(--color-accent-primary);
        opacity: 0.7;
    }
    
    /* Improve UX for long-running sessions */
    .sessions-table td[data-label="Duration"] {
        font-weight: 500;
        color: var(--color-accent-secondary);
    }
}

/* Responsive design */
@media (max-width: 768px) {
    #admin-dashboard {
        padding: 10px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Make table responsive */
    .sessions-table {
        display: block;
        width: 100%;
    }
    
    .sessions-table thead {
        display: none; /* Hide table headers on mobile */
    }
    
    .sessions-table tbody {
        display: block;
        width: 100%;
    }
    
    .sessions-table tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid var(--color-border-subtle);
        border-radius: var(--border-radius-base);
        padding: 12px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        background-color: white;
    }
    
    .sessions-table td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid rgba(0,0,0,0.05);
        text-align: right;
    }
    
    .sessions-table td::before {
        content: attr(data-label);
        font-weight: bold;
        text-align: left;
        padding-right: 10px;
    }
    
    .sessions-table td:last-child {
        border-bottom: none;
    }
    
    /* Special styling for action buttons on mobile */
    .sessions-table td:last-child {
        justify-content: flex-start;
    }
    
    .sessions-table .session-actions {
        display: flex;
        gap: 10px;
        margin-top: 5px;
        justify-content: flex-start;
    }
    
    /* Improve form layouts on mobile */
    .form-row {
        flex-direction: column;
        gap: 10px;
    }
    
    /* Panel ordering for mobile view */
    .bottom-panels-container {
        grid-template-columns: 1fr !important;
    }
    
    .prompts-panel {
        order: 1;
    }
    
    .billing-panel {
        order: 2;
    }
}

/* Additional styles for the sessions table */
.panel-header-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    row-gap: 8px;
    margin-bottom: 15px;
}

.panel-header-actions .glossais-button {
    flex-shrink: 0;
    margin-left: auto; /* stays pinned right even when wrapped onto its own line */
}

.panel-header-actions .panel-header {
    /* .panel-header's own margin-bottom (meant for standalone use) skews
       align-items:center against the button; nowrap/no-shrink stops the
       title text itself from wrapping before the button drops below it */
    margin: 0;
    flex-shrink: 0;
    white-space: nowrap;
}

#current-sessions-panel {
    grid-column: 1 / -1; /* Make sessions panel span full width */
}

.sessions-table-container {
    overflow-x: auto;
    margin-bottom: 15px;
}

.sessions-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.sessions-table th, .sessions-table td {
    padding: 10px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.sessions-table th {
    background-color: rgba(0,0,0,0.05);
    font-weight: 600;
}

.sessions-table tr:hover {
    background-color: rgba(107, 142, 35, 0.1);
    transition: background-color 0.2s;
}

.session-actions {
    display: flex;
    gap: 5px;
    justify-content: flex-start;
}

.action-button {
    border: none;
    background: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.action-button:hover {
    background-color: rgba(0,0,0,0.05);
}

.action-button.delete-session {
    color: #dc3545 !important;
}

.action-button.delete-session:hover {
    background-color: rgba(220, 53, 69, 0.1);
    color: #c82333 !important;
}

.action-button.set-landing.landing-active {
    color: #28a745 !important;
    background-color: rgba(40, 167, 69, 0.1);
}

.action-button.set-landing:hover {
    background-color: rgba(40, 167, 69, 0.15);
}

.sessions-footer {
    display: flex;
    justify-content: flex-end;
}

/* Additional styles for form layout */
.button-center {
    display: flex;
    justify-content: center;
    margin-top: 20px;
}

/* Panel ordering for mobile view */
/* Form row styles already defined for mobile, adding the desktop version */
.form-row .form-group {
    flex: 1;
}

.form-select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    font-size: 14px;
}

.prompt-textarea {
    height: 150px; /* Make the textarea larger */
    font-size: 12px; /* Make text inside smaller */
    line-height: 1.4;
    padding: 10px;
    width: 100%;
}

/* Login container styles */
.login-container {
    max-width: 400px; /* Limit width on desktop */
    margin: 2rem auto; /* Center horizontally with top margin */
    padding: var(--padding-base);
    min-height: auto; /* Override panel min-height */
}

/* Mobile responsive styles for login */
@media (max-width: 768px) {
    .login-container {
        max-width: 85%; /* Make it narrower than screen on mobile */
        margin: 3rem auto 2rem; /* Position slightly lower than top */
        padding: 1.5rem;
    }
}

/* Additional mobile adjustments for very small screens */
@media (max-width: 480px) {
    .login-container {
        max-width: 90%;
        margin: 2rem auto 1rem;
        padding: 1rem;
    }
}

/* Backend Status Indicator Styles */
.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    transition: all 0.3s ease;
    font-size: 12px;
    line-height: 1;
}

.status-indicator.success {
    color: #28a745;
    text-shadow: 0 0 3px rgba(40, 167, 69, 0.5);
}

.status-indicator.error {
    color: #dc3545;
    text-shadow: 0 0 3px rgba(220, 53, 69, 0.5);
}

.status-indicator.checking {
    color: #fd7e14;
    text-shadow: 0 0 3px rgba(253, 126, 20, 0.5);
    animation: pulse 1.5s ease-in-out infinite alternate;
}

@keyframes pulse {
    from {
        opacity: 0.6;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1.1);
    }
}

#backend-status-text {
    font-size: 0.9em;
    font-weight: 500;
}

/* QR Code Popup Modal */
.qr-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.qr-modal-overlay.active {
    display: flex;
}

.qr-modal-content {
    background-color: var(--color-panel-background);
    border-radius: var(--border-radius-base);
    padding: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 90%;
    max-height: 90%;
    animation: slideIn 0.3s ease-out;
    position: relative;
}

.qr-modal-content h2 {
    color: var(--color-accent-tertiary);
    margin: 0 0 20px 0;
    font-size: 1.3em;
}

.qr-code-link {
    display: inline-block;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease;
    text-decoration: none;
}

.qr-code-link:hover {
    transform: scale(1.05);
}

.qr-code-link img {
    display: block;
    max-width: 400px;
    width: 100%;
    height: auto;
    border-radius: var(--border-radius-base);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.qr-link-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: var(--color-accent-primary);
    color: var(--color-text-light);
    padding: 8px 12px;
    border-radius: var(--border-radius-base);
    font-size: 0.85em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.qr-link-icon {
    font-size: 1.1em;
}

.qr-copy-link-btn {
    margin: 20px auto 0 auto;
    padding: 12px 24px;
    background-color: var(--color-accent-primary);
    color: var(--color-text-light);
    border: none;
    border-radius: var(--border-radius-base);
    font-family: var(--font-monospace);
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.qr-copy-link-btn:hover {
    background-color: var(--color-accent-tertiary);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.qr-copy-link-btn:active {
    transform: translateY(0);
}

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

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

/* Mobile responsive for QR modal */
@media (max-width: 768px) {
    .qr-modal-content {
        padding: 20px;
    }
    
    .qr-code-link img {
        max-width: 300px;
    }
    
    .qr-link-indicator {
        font-size: 0.75em;
        padding: 6px 10px;
    }
}

/* --- New-session mode buttons and the full-auto balloon --------------- */

.new-session-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Positioning context for the balloon; the button keeps its own sizing. */
.balloon-anchor {
    position: relative;
    display: inline-flex;
    z-index: 1;
}

.mode-balloon {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10000;
    width: 240px;
    max-width: 85vw;
    padding: 16px;
    background: var(--color-panel-background);
    color: var(--color-text-dark);
    border: 2px solid var(--color-accent-primary);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(107, 142, 35, 0.25), 0 0 0 1px rgba(107, 142, 35, 0.1);
    font-size: 0.9em;
    line-height: 1.5;
    text-align: left;
    /* Hidden by default without display:none, so the fade can animate and
       screen readers can still reach it via aria-describedby. */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.95);
    transition: opacity 0.2s ease-out, transform 0.2s ease-out, visibility 0.2s;
    pointer-events: none;
    white-space: normal;
}

/* The arrow, pointing up at the button. Two triangles so the
   2px border reads continuously across the notch. */
.mode-balloon::before,
.mode-balloon::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 10px solid transparent;
}
.mode-balloon::before {
    border-bottom-color: var(--color-accent-primary);
}
.mode-balloon::after {
    border-bottom-color: var(--color-panel-background);
    margin-bottom: -2px;
}

.balloon-anchor:hover .mode-balloon,
.balloon-anchor:focus-within .mode-balloon,
.mode-balloon.balloon-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.balloon-content {
    display: flex;
    gap: 0;
    align-items: flex-start;
}

.balloon-column {
    flex: 1;
    min-width: 0;
}

.balloon-divider {
    display: none;
}

.balloon-title {
    display: block;
    margin: 0 0 10px 0;
    color: var(--color-accent-primary);
    font-weight: 700;
    font-size: 1.05em;
}

.balloon-list {
    margin: 0;
    padding-left: 0;
    list-style: none;
}

.balloon-list li {
    margin-bottom: 8px;
    line-height: 1.4;
    font-size: 0.92em;
}

.balloon-list li:last-child {
    margin-bottom: 0;
}

.mode-balloon .balloon-footer {
    display: block;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--color-border-subtle);
    opacity: 0.85;
}

@media (max-width: 768px) {
    .new-session-actions {
        flex-wrap: wrap;
    }
    .mode-balloon {
        width: 260px;
        padding: 14px;
    }
}
