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

.hidden {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #1a1a1a;
    color: #e0e0e0;
    line-height: 1.5;
    padding: 20px;
}

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

header {
    margin-bottom: 35px;
    text-align: center;
}

h1 {
    font-size: 26px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 15px;
    color: #999;
}

main {
    background: #252525;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 25px;
    margin-bottom: 20px;
}

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

label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: #ccc;
    font-weight: 500;
}

.required {
    color: #e74c3c;
}

.file-input-wrapper {
    position: relative;
}

.file-input-wrapper input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.file-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 10px 14px;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 3px;
}

.file-label:hover {
    background: #2f2f2f;
    border-color: #444;
}

.file-button {
    background: #3a3a3a;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 13px;
    color: #ddd;
}

.file-name {
    flex: 1;
    font-size: 14px;
    color: #888;
}

input[type="password"] {
    width: 100%;
    padding: 10px 14px;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 3px;
    color: #e0e0e0;
    font-size: 17px;
    -webkit-text-size-adjust: 100%;
}

input[type="password"]:focus {
    outline: none;
    border-color: #555;
    background: #2f2f2f;
    font-size: 17px;
    -webkit-text-size-adjust: 100%;
}

input[type="file"],
input[type="text"],
input[type="email"],
input[type="number"],
textarea,
select {
    -webkit-text-size-adjust: 100%;
    font-size: 17px;
}

.btn-submit {
    width: 100%;
    padding: 12px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 3px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-submit:hover {
    background: #c0392b;
}

.btn-submit:disabled {
    background: #555;
    cursor: not-allowed;
}

.loader {
    display: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.btn-submit.loading .loader {
    display: block;
}

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

footer {
    text-align: center;
    padding: 20px 0;
}

footer p {
    font-size: 13px;
    color: #777;
}

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

    /* prevent the overlay itself from scrolling; modal-content will scroll */
    overflow: hidden;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #252525;
    border: 1px solid #333;
    border-radius: 4px;
    max-width: 700px;
    width: 100%;
    /* limit height relative to viewport so only this element scrolls */
    max-height: calc(100vh - 40px);
    overflow-y: auto;

    /* ensure content never overflows viewport on small screens */
    box-sizing: border-box;
    margin: 0 12px; /* leave small side gutters to avoid horizontal scroll */
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #333;
    position: relative; /* added to allow absolute centering of the title */
}

.modal-header h2 {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    pointer-events: none; /* ensures the close button remains clickable */
    text-align: center;

    /* prevent overflow: limit width and allow wrapping */
    max-width: calc(100% - 90px); /* leave space for the close button */
    white-space: normal;
    word-break: break-word;
    overflow-wrap: break-word;
    padding-right: 8px;
}

/* Ensure close button still sits at top-right */
.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #888;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
}

/* Mobile: stop absolute-centering so long titles wrap nicely */
@media (max-width: 460px) {
    .modal-header {
        /* keep relative positioning but allow normal flow for the title */
        align-items: flex-start;
        padding: 14px 16px;
    }

    .modal-header h2 {
        position: static;
        transform: none;
        left: auto;
        top: auto;
        margin: 0 auto 6px;
        max-width: 100%;
        text-align: center;
        pointer-events: none;
    }

    .modal-close {
        right: 12px;
        top: 12px;
        transform: none;
    }
}

.modal-body {
    padding: 25px;
}

.status-badge {
    display: block; /* changed from inline-block to block so it fills available width */
    width: 100%;
    box-sizing: border-box; /* ensure padding doesn't cause overflow */
    padding: 6px 14px;
    border-radius: 3px;
    font-size: 18px;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 20px;
    text-align: center; /* center text inside the full-width badge */
}

.status-badge.valid {
    background: #27ae60;
    color: white;
}

.status-badge.revoked {
    background: #e74c3c;
    color: white;
}

.status-badge.expired {
    background: #f39c12;
    color: white;
}

.modal-section {
    margin-bottom: 25px;
}

.modal-section:last-child {
    margin-bottom: 0;
}

.modal-section h3 {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #333;
    text-align: center;
}

.modal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.modal-item {
    background: #2a2a2a;
    padding: 12px;
    border-radius: 3px;
    border: 1px solid #333;
}

.modal-label {
    display: block;
    font-size: 12px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    font-weight: 500;
}

.modal-value {
    display: block;
    font-size: 14px;
    color: #e0e0e0;
    word-break: break-word;
}

.modal-value.revoked {
    color: #e74c3c;
}

.udid-list {
    background: #2a2a2a;
    border: 1px solid #333;
    border-radius: 3px;
    padding: 15px;
    max-height: 250px;
    overflow-y: auto;
}

.udid-item {
    padding: 8px 0;
    border-bottom: 1px solid #333;
    font-size: 13px;
    color: #ccc;
    font-family: 'Monaco', 'Courier New', monospace;
}

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

.modal-footer {
    padding: 15px 25px;
    border-top: 1px solid #333;
    text-align: right;
}

.btn-modal-close {
    padding: 8px 18px;
    background: #3a3a3a;
    color: #ddd;
    border: 1px solid #444;
    border-radius: 3px;
    font-size: 14px;
    cursor: pointer;
}

.btn-modal-close:hover {
    background: #444;
    border-color: #555;
}

/* Error modal specific styles */
.modal-error .modal-body {
    text-align: center;
    padding: 30px 25px;
}

.error-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.error-message {
    font-size: 15px;
    color: #e0e0e0;
    line-height: 1.6;
}

/* Mobile responsiveness */
@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 20px 10px;
    }

    h1 {
        font-size: 22px;
    }

    main {
        padding: 20px;
    }

    .modal-content {
        max-height: 90vh;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 15px;
    }

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

    /* place modal at the top of the viewport on mobile so header is visible immediately */
    .modal {
        align-items: flex-start;
        padding-top: 18px;
        padding-bottom: 18px;
        /* Do not allow the overlay to scroll — content will scroll */
    }

    /* ensure the modal content uses full available width minus gutters */
    .modal-content {
        max-width: calc(100% - 24px);
        margin: 0 12px;
        max-height: calc(100vh - 36px); /* slightly larger on mobile spacing */
    }

    /* ...existing code... */
}

/* Prevent background scrolling when we add the class via JS */
body.modal-open {
    position: fixed;
    left: 0;
    right: 0;
    /* top is set inline in JS to -scrollY so page doesn't jump */
    overflow: hidden;
}
