/* Custom font faces */
@font-face {
    font-family: 'NeutralFace';
    src: url('../fonts/heading-NeutralFace.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'FontAll';
    src: url('../fonts/font-all.woff') format('woff');
    font-weight: 100 1000;
    font-style: normal;
    font-display: swap;
}

a {
    color: #8a7f76;
    text-decoration: underline;
    font-weight: 400;
    transition: color 0.2s ease;
}

a:hover {
    color: #6b6158;
}

* {
    -webkit-user-drag: none;
    -moz-user-drag: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* Allow text selection for input elements and text areas */
input, textarea, [contenteditable="true"] {
    -webkit-user-select: text;
    -moz-user-select: text;
    user-select: text;
}

/* Global font rules */
h1, h2, h3, h4, h5, h6 {
    font-family: 'NeutralFace', 'FontAll', Arial, Helvetica, sans-serif;
}

input, select, textarea, button {
    font-family: 'FontAll', Arial, Helvetica, sans-serif;
}

/* Base styles */
body {
    font-family: 'FontAll', Arial, Helvetica, sans-serif;
    font-weight: 400;
    margin: 0;
    height: 100vh;
    overflow: hidden;
    background: linear-gradient(135deg, #f5f4f3 0%, #ebe9e7 100%);
    color: #1a1a1a;
    display: flex;
    flex-direction: column;
}

/* Buttons */
button, select {
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    background: #ccc6c1;
    color: #222;
    cursor: pointer;
    transition: background 0.2s;
}
@media (hover: hover) {
    button:hover,
    .index-page button:hover {
        background: #ab9f95;
    }
}
button:disabled {
    background: #e5e1dd;
    cursor: not-allowed;
    color: #999;
}
.index-page button {
    padding: 15px 25px;
    font-size: 18px;
}

/* Main container */
#main-container {
    position: relative;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f2f1f0;
    overflow: hidden;
}

/* Status */
#status {
    color: #1a1a1a;
    font-weight: 400;
    font-size: 18px;
    text-align: center;
    max-width: 80%;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border-radius: 16px;
}
.error {
    color: red;
}

.connect-button {
    background: #ccc6c1;
    color: #222;
    border: none;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 400;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
}

.connect-button:hover {
    background: #ab9f95;
    text-decoration: none;
}

/* Loading Screen */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    min-height: 200px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(26, 26, 26, 0.1);
    border-top: 4px solid #1a1a1a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-screen h3 {
    font-size: 1.5rem;
    color: #1a1a1a;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.loading-screen p {
    color: #666;
    font-size: 1rem;
    margin: 0;
}

/* Error Message */
.error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(220, 38, 38, 0.3);
    max-width: 400px;
    margin: 0 auto;
}

.error-message h3 {
    font-size: 1.5rem;
    color: #dc2626;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.error-message p {
    color: #666;
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.retry-button {
    background: #dc2626;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 400;
    cursor: pointer;
    transition: background 0.2s ease;
}

.retry-button:hover {
    background: #b91c1c;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1rem;
}

.cancel-button {
    background: #ccc6c1;
    color: #222;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 400;
    cursor: pointer;
    transition: background 0.2s ease;
}

.cancel-button:hover {
    background: #ab9f95;
}

.submit-button {
    background: #ccc6c1;
    color: #222;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 400;
    cursor: pointer;
    transition: background 0.2s ease;
}

.submit-button:hover:not(:disabled) {
    background: #ab9f95;
}

.submit-button:disabled {
    background: #e5e1dd;
    cursor: not-allowed;
    color: #999;
}

.form-status {
    margin-top: 1rem;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 400;
    display: none;
}

.form-status.success {
    background: rgba(74, 222, 128, 0.1);
    color: #16a34a;
    border: 1px solid rgba(74, 222, 128, 0.2);
}

.form-status.error {
    background: rgba(248, 113, 113, 0.1);
    color: #dc2626;
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.form-status.info {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
    border: 1px solid rgba(59, 130, 246, 0.2);
}


/* Index page overrides */
.index-page #main-container {
    flex-direction: column;
}
.index-page #status {
    margin-bottom: 20px;
}
.index-page #generate-button {
    border-radius: 12px;
}

/* Shared layout container (login, payment_failure) */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, #f5f4f3 0%, #ebe9e7 100%);
}

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

.form-group label {
    font-weight: 400;
    color: #1a1a1a;
    font-size: 14px;
}

.form-group input {
    padding: 12px 16px;
    border: 1px solid rgba(204, 198, 193, 0.5);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.8);
    font-size: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #ab9f95;
    box-shadow: 0 0 0 3px rgba(171, 159, 149, 0.1);
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    backdrop-filter: blur(4px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-overlay::before,
.modal-overlay::after {
    content: '';
    flex: 0 0 20px;
}

.modal-content {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(204, 198, 193, 0.3);
    max-width: 500px;
    width: 90%;
    position: relative;
    margin: auto;
    flex-shrink: 0;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid rgba(204, 198, 193, 0.2);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: #1a1a1a;
    font-weight: 500;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease, color 0.2s ease;
}

.modal-close:hover {
    background: rgba(204, 198, 193, 0.2);
    color: #1a1a1a;
}

.modal-body {
    padding: 2rem;
}

.modal-body .edit-device-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-body .form-group {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.modal-body .form-group label {
    font-weight: 400;
    color: #1a1a1a;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.modal-body .form-group input {
    padding: 12px 16px;
    border: 1px solid rgba(204, 198, 193, 0.5);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.8);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-body .form-group input:focus {
    outline: none;
    border-color: #ab9f95;
    box-shadow: 0 0 0 3px rgba(171, 159, 149, 0.1);
}

/* Edit device form - extends .modal-body .form-group */
.edit-device-form .form-group {
    margin-bottom: 1rem;
}

.edit-device-form .form-group:last-child {
    margin-bottom: 0;
}

.edit-device-form .form-help {
    font-size: 0.875rem;
    color: #666;
    margin-top: 0.25rem;
}


.footer-info {
    display: block;
    text-align: center;
    margin: 1.5rem 0 0;
    padding: 1.5rem 0 0;
    border-top: 1px solid rgba(204, 198, 193, 0.3);
}

.modal-body .form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* Responsive modal */
@media (max-width: 768px) {
    .modal-content {
        max-width: 100%;
        width: 95%;
        margin: 10px;
    }

    .modal-header,
    .modal-body {
        padding: 1.5rem;
    }

    .modal-body .form-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
}

.secondary-button {
    background: transparent;
    color: #666;
    border: 1px solid rgba(204, 198, 193, 0.5);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.secondary-button:hover {
    background: rgba(204, 198, 193, 0.2);
    border-color: #ab9f95;
}

.secondary-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Share-style Modal (used in device.html and choose_device.html) */
.modal {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal .modal-content {
    background-color: white;
    margin: 0;
    padding: 0;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.modal .modal-header h3 {
    margin: 0;
    color: #333;
}

.modal .close {
    color: #666;
    font-size: 1.5rem;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal .close:hover {
    color: #1a1a1a;
    background: rgba(204, 198, 193, 0.2);
}

.modal .modal-body {
    padding: 20px;
}

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

.modal .form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 400;
    color: #1a1a1a;
    font-size: 14px;
}

.modal .form-group select,
.modal .form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid rgba(204, 198, 193, 0.5);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.modal .form-group select:focus,
.modal .form-group input:focus {
    outline: none;
    border-color: #ab9f95;
    box-shadow: 0 0 0 3px rgba(171, 159, 149, 0.1);
}

.share-link-container {
    display: flex;
    gap: 10px;
    align-items: center;
}

.share-link-container input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid rgba(204, 198, 193, 0.5);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-family: monospace;
}

.share-link-container button {
    white-space: nowrap;
}

.primary-button {
    background: #ccc6c1;
    color: #222;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
    transition: background 0.2s ease;
    width: 100%;
}

.primary-button:hover {
    background: #ab9f95;
}

/* Toast notification */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(76, 175, 80, 0.95);
    color: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    text-align: left;
    max-width: 350px;
    transform: translateX(calc(100% + 30px));
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.3, 0.27, 1.2);
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast strong {
    display: block;
    margin-bottom: 4px;
}

.toast p {
    margin: 0;
    font-size: 0.9em;
    opacity: 0.9;
}

.toast-error {
    background: rgba(220, 38, 38, 0.95);
}

.toast-success {
    background: rgba(76, 175, 80, 0.95);
}