/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Variables for theming */
:root {
    /* Light mode colors */
    --bg-primary: #f5f7fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f7fafc;
    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --text-tertiary: #718096;
    --text-muted: #a0aec0;
    --border-color: #e2e8f0;
    --border-color-hover: #cbd5e0;
    --shadow-sm: rgba(0, 0, 0, 0.1);
    --shadow-md: rgba(0, 0, 0, 0.15);
    --shadow-lg: rgba(0, 0, 0, 0.2);
}

/* Dark mode colors */
[data-theme="dark"] {
    --bg-primary: #1a202c;
    --bg-secondary: #2d3748;
    --bg-tertiary: #374151;
    --text-primary: #f7fafc;
    --text-secondary: #e2e8f0;
    --text-tertiary: #cbd5e0;
    --text-muted: #a0aec0;
    --border-color: #4a5568;
    --border-color-hover: #718096;
    --shadow-sm: rgba(0, 0, 0, 0.3);
    --shadow-md: rgba(0, 0, 0, 0.4);
    --shadow-lg: rgba(0, 0, 0, 0.5);
}

/* System preference detection */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-primary: #1a202c;
        --bg-secondary: #2d3748;
        --bg-tertiary: #374151;
        --text-primary: #f7fafc;
        --text-secondary: #e2e8f0;
        --text-tertiary: #cbd5e0;
        --text-muted: #a0aec0;
        --border-color: #4a5568;
        --border-color-hover: #718096;
        --shadow-sm: rgba(0, 0, 0, 0.3);
        --shadow-md: rgba(0, 0, 0, 0.4);
        --shadow-lg: rgba(0, 0, 0, 0.5);
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    border-radius: 10px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.header-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
}

#last-update {
    font-size: 0.9rem;
    opacity: 0.9;
}

.btn-refresh, .btn-poll {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.btn-refresh:hover, .btn-poll:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

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

/* Warning Banner */
.warning-banner {
    background-color: #fed7d7;
    border-left: 4px solid #f56565;
    color: #742a2a;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 20px;
}

/* Status Summary */
.status-summary {
    margin-bottom: 30px;
}

.status-summary h2 {
    margin-bottom: 20px;
    color: var(--text-primary);
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.status-card {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 25px;
    box-shadow: 0 2px 4px var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.status-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow-md);
}

.status-icon {
    font-size: 3rem;
    line-height: 1;
}

.status-info h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.status-counts {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 5px;
}

.status-labels {
    font-size: 0.85rem;
    color: var(--text-tertiary);
}

/* Status Colors */
.status-up, .status-ok {
    color: #48bb78;
}

.status-down, .status-critical {
    color: #f56565;
}

.status-unreachable, .status-unknown {
    color: #ed8936;
}

.status-warning {
    color: #ecc94b;
}

.status-incident {
    color: #f56565;
    font-size: 2rem;
}

/* Sections */
section {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 25px;
    margin-bottom: 30px;
    box-shadow: 0 2px 4px var(--shadow-sm);
}

section h2 {
    margin-bottom: 20px;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h2 {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

/* Incident Filters */
.incident-filters {
    display: flex;
    gap: 15px;
}

.incident-filters label {
    cursor: pointer;
    font-size: 0.9rem;
}

.incident-filters input[type="radio"] {
    margin-right: 5px;
}

/* Incidents List */
.incidents-list, .hosts-list, .services-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.incident-item, .host-item, .service-item {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    transition: all 0.2s ease;
    cursor: pointer;
    background: var(--bg-secondary);
}

.incident-item:hover, .host-item:hover, .service-item:hover {
    border-color: var(--border-color-hover);
    box-shadow: 0 2px 4px var(--shadow-sm);
}

.incident-item.active {
    border-left: 4px solid #f56565;
}

.incident-item.resolved {
    border-left: 4px solid #48bb78;
    opacity: 0.7;
}

.incident-header, .host-header, .service-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 10px;
}

.incident-title, .host-name, .service-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.incident-state, .host-state, .service-state {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.state-down, .state-critical {
    background-color: #fed7d7;
    color: #c53030;
}

.state-warning {
    background-color: #fefcbf;
    color: #975a16;
}

.state-up, .state-ok {
    background-color: #c6f6d5;
    color: #22543d;
}

.state-unreachable, .state-unknown {
    background-color: #feebc8;
    color: #9c4221;
}

.state-resolved {
    background-color: #c6f6d5;
    color: #22543d;
}

/* Acknowledgement Badge */
.ack-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    background-color: #bee3f8;
    color: #2c5282;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-left: 8px;
}

.incident-info, .host-info, .service-info {
    font-size: 0.9rem;
    color: var(--text-tertiary);
}

.incident-times {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.plugin-output {
    margin-top: 10px;
    padding: 10px;
    background-color: var(--bg-tertiary);
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* RSS Section */
.rss-section {
    text-align: center;
}

.rss-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 15px;
}

.rss-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 5px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.rss-link:hover {
    background-color: var(--bg-secondary);
    border-color: var(--border-color-hover);
}

.rss-icon {
    font-size: 1.2rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 30px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 2rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: var(--text-tertiary);
}

#incident-detail {
    margin-bottom: 30px;
}

.incident-detail-section {
    margin-bottom: 20px;
}

.incident-detail-section h3 {
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.comments-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 15px;
}

.comment {
    background-color: var(--bg-tertiary);
    border-left: 3px solid var(--border-color-hover);
    padding: 15px;
    border-radius: 5px;
}

.comment.nagios-comment {
    border-left-color: #667eea;
}

.comment-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.comment-author {
    font-weight: 600;
    color: var(--text-primary);
}

.comment-date {
    color: var(--text-muted);
}

.comment-text {
    color: var(--text-secondary);
}

/* Post-Incident Review Link */
.pir-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.pir-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* PIR Form */
.pir-form {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

/* Comment Form */
.comment-form {
    border-top: 2px solid var(--border-color);
    padding-top: 20px;
}

.comment-form h3 {
    margin-bottom: 15px;
}

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-family: inherit;
    font-size: 0.95rem;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: transform 0.2s ease;
}

.btn-primary:hover {
    transform: translateY(-1px);
}

/* Loading State */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

footer p {
    margin: 5px 0;
}

/* Theme Toggle */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    padding: 6px;
}

.theme-option {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    padding: 4px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.theme-option:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.theme-option.active {
    background-color: rgba(255, 255, 255, 0.3);
    color: white;
    font-weight: 500;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Reduce overall padding on mobile */
    .container {
        padding: 12px;
    }

    /* Header improvements */
    header {
        padding: 20px 16px;
        margin-bottom: 16px;
    }

    header h1 {
        font-size: 1.75rem;
    }

    header > div:first-child {
        flex-wrap: wrap;
    }

    header img {
        width: 40px !important;
        height: 40px !important;
    }

    .header-info {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
        width: 100%;
    }

    #last-update {
        font-size: 0.85rem;
    }

    /* Button improvements for touch */
    .btn-refresh, .btn-poll {
        padding: 10px 18px;
        font-size: 0.95rem;
        min-height: 44px;
        flex: 1;
    }

    header .header-info > div:last-child {
        width: 100%;
    }

    header .header-info > div:last-child > div {
        display: flex;
        gap: 8px;
        width: 100%;
    }

    /* Status grid - single column */
    .status-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .status-card {
        padding: 16px;
        gap: 12px;
    }

    .status-icon {
        font-size: 2.5rem;
    }

    .status-info h3 {
        font-size: 1rem;
    }

    .status-counts {
        font-size: 1.3rem;
    }

    .status-labels {
        font-size: 0.8rem;
    }

    /* Sections */
    section {
        padding: 16px;
        margin-bottom: 16px;
    }

    section h2 {
        font-size: 1.3rem;
        margin-bottom: 12px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    /* Incident filters - horizontal scroll on very small screens */
    .incident-filters {
        display: flex;
        flex-direction: row;
        gap: 12px;
        overflow-x: auto;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }

    .incident-filters label {
        white-space: nowrap;
        font-size: 0.85rem;
    }

    /* Incident/Host/Service items */
    .incident-item, .host-item, .service-item {
        padding: 12px;
    }

    .incident-header, .host-header, .service-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .incident-title, .host-name, .service-name {
        font-size: 1rem;
        word-break: break-word;
    }

    .incident-state, .host-state, .service-state {
        align-self: flex-start;
    }

    .ack-badge {
        margin-left: 0;
        margin-top: 4px;
    }

    .plugin-output {
        font-size: 0.85rem;
        padding: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Modal improvements */
    .modal {
        padding: 0;
    }

    .modal-content {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        padding: 16px;
    }

    .close {
        font-size: 1.75rem;
        top: 12px;
        right: 16px;
        padding: 8px;
        /* Larger touch target */
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #incident-detail h3 {
        font-size: 1.1rem;
    }

    /* Form improvements */
    .form-group input,
    .form-group textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }

    .btn-primary {
        width: 100%;
        padding: 14px 24px;
        font-size: 1rem;
        min-height: 48px;
    }

    /* Theme toggle */
    .theme-toggle {
        width: 100%;
        justify-content: space-between;
        padding: 8px;
    }

    .theme-option {
        flex: 1;
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    /* RSS links */
    .rss-links {
        flex-direction: column;
        gap: 12px;
    }

    .rss-link {
        width: 100%;
        justify-content: center;
    }

    /* Footer */
    footer {
        padding: 20px 16px;
        font-size: 0.85rem;
    }
}

/* Extra small devices (phones in portrait, less than 375px) */
@media (max-width: 374px) {
    .container {
        padding: 8px;
    }

    header {
        padding: 16px 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .status-counts {
        font-size: 1.1rem;
    }

    .theme-option {
        font-size: 0.75rem;
        padding: 6px 8px;
    }
}
