/* Panel design tokens — shared by every page (login, payment, device, choose_device).
   Page-specific layout vars (--content-max, --gutter, --row-x) stay scoped in choose_device.css. */
:root {
    --ink: #322e2e;
    --paper: #f2f1f0;
    --muted: #90847a;
    --line: #d9d4cf;
    --line-soft: rgba(204, 198, 193, 0.45);
    --ok: #3d8b51;
    --danger: #b0413e;
    --shadow: 0 1px 2px rgba(50, 46, 46, 0.04), 0 2px 6px rgba(50, 46, 46, 0.04);
    --shadow-floating: 0 2px 4px rgba(50, 46, 46, 0.06), 0 18px 44px rgba(50, 46, 46, 0.1);
    --font-display: 'NeutralFace', 'FontAll', Arial, Helvetica, sans-serif;
    --font-text: 'FontAll', Arial, Helvetica, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    --text-l: 1.25rem;
    --text-m: 0.9375rem;
    --text-s: 0.8125rem;
    --text-xs: 0.75rem;
    --w-text: 400;
    --w-emphasis: 500;
    --dur: 200ms;
    --dur-slow: 350ms;
    --spring: cubic-bezier(0.16, 1, 0.3, 1);
}

/* 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;
    touch-action: manipulation;
}

/* Disable text selection on interactive controls only */
button, label, .action-button, .share-button, .toggle-label, .legacy-mode-toggle {
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}

/* Global font rules: display font only for page and modal titles */
h1, h2 {
    font-family: 'NeutralFace', 'FontAll', Arial, Helvetica, sans-serif;
    font-weight: 400;
}

h3, h4, h5, h6 {
    font-family: 'FontAll', Arial, Helvetica, sans-serif;
    font-weight: 400;
}

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;
    height: 100dvh;
    overflow: hidden;
    background: linear-gradient(135deg, #f5f4f3 0%, #ebe9e7 100%);
    color: var(--ink);
    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: var(--muted);
}
.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: var(--ink);
    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: var(--danger);
}

.connect-button {
    background: var(--ink);
    color: var(--paper);
    border: 1px solid var(--ink);
    padding: 13px 26px;
    border-radius: 999px;
    font-size: 1rem;
    font-weight: var(--w-emphasis);
    cursor: pointer;
    transition: background var(--dur) ease, border-color var(--dur) ease;
    text-decoration: none;
}

.connect-button:hover {
    background: #1f1b18;
    border-color: #1f1b18;
    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 var(--ink);
    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: var(--ink);
    margin-bottom: 0.5rem;
    font-weight: 400;
}

.loading-screen p {
    color: var(--muted);
    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(176, 65, 62, 0.3);
    max-width: 400px;
    margin: 0 auto;
}

.error-message h3 {
    font-size: 1.5rem;
    color: var(--danger);
    margin-bottom: 0.5rem;
    font-weight: 400;
}

.error-message p {
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.retry-button {
    background: var(--danger);
    color: #fff;
    border: 1px solid var(--danger);
    padding: 11px 24px;
    border-radius: 999px;
    font-size: 1rem;
    font-weight: var(--w-emphasis);
    cursor: pointer;
    transition: background var(--dur) ease;
}

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

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

/* Shared button language: ink pill (submit/primary) + ghost pill (cancel/secondary) */
.cancel-button {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
    padding: 11px 24px;
    border-radius: 999px;
    font-size: 1rem;
    font-weight: var(--w-emphasis);
    cursor: pointer;
    transition: border-color var(--dur) ease, background var(--dur) ease;
}

.cancel-button:hover {
    background: transparent;
    border-color: var(--muted);
}

.submit-button {
    background: var(--ink);
    color: var(--paper);
    border: 1px solid var(--ink);
    padding: 11px 24px;
    border-radius: 999px;
    font-size: 1rem;
    font-weight: var(--w-emphasis);
    cursor: pointer;
    transition: background var(--dur) ease, border-color var(--dur) ease;
}

.submit-button:hover:not(:disabled) {
    background: #1f1b18;
    border-color: #1f1b18;
}

.submit-button:disabled {
    background: var(--line);
    border-color: var(--line);
    cursor: not-allowed;
    color: var(--muted);
}

.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(61, 139, 81, 0.1);
    color: var(--ok);
    border: 1px solid rgba(61, 139, 81, 0.22);
}

.form-status.error {
    background: rgba(176, 65, 62, 0.1);
    color: var(--danger);
    border: 1px solid rgba(176, 65, 62, 0.22);
}

/* No blue in the brand — "info"/in-progress reads as a neutral warm note */
.form-status.info {
    background: rgba(144, 132, 122, 0.12);
    color: var(--ink);
    border: 1px solid rgba(144, 132, 122, 0.25);
}


/* Index page overrides */
.index-page #main-container {
    flex-direction: column;
}
.index-page #status {
    margin-bottom: 20px;
}
.index-page #generate-button {
    background: var(--ink);
    color: var(--paper);
    border: 1px solid var(--ink);
    border-radius: 999px;
    font-weight: var(--w-emphasis);
    transition: background var(--dur) ease, border-color var(--dur) ease;
}
.index-page #generate-button:hover {
    background: #1f1b18;
    border-color: #1f1b18;
}

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

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

.form-group label {
    font-weight: 400;
    color: var(--ink);
    font-size: 14px;
}

.form-group input {
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #ffffff;
    font-size: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--muted);
    box-shadow: 0 0 0 3px rgba(144, 132, 122, 0.12);
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    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;
    /* Never taller than the viewport: cap the box and let .modal-body scroll,
       so the modal stays centered instead of being pinned to the top on phones. */
    max-height: calc(100dvh - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.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);
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--ink);
    font-weight: 400;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--muted);
    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: var(--ink);
}

.modal-body {
    padding: 2rem;
    overflow-y: auto;
    min-height: 0;
}

.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: var(--ink);
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.modal-body .form-group input {
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #ffffff;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-body .form-group input:focus {
    outline: none;
    border-color: var(--muted);
    box-shadow: 0 0 0 3px rgba(144, 132, 122, 0.12);
}

/* Format-hint borders for inputs (non-blocking visual cue) */
.modal-body .form-group input.input-hint-valid,
.modal-body .form-group input.input-hint-valid:focus {
    border-color: var(--ok);
    box-shadow: 0 0 0 3px rgba(61, 139, 81, 0.30);
}

.modal-body .form-group input.input-hint-invalid,
.modal-body .form-group input.input-hint-invalid:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(176, 65, 62, 0.30);
}

/* 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: var(--muted);
    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%;
        /* keep auto margins so the flex overlay centers it; the ::before/::after
           spacers provide the gap. A fixed margin here pins it to the top. */
        margin: auto;
    }

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

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

.secondary-button {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: var(--w-emphasis);
    cursor: pointer;
    transition: border-color var(--dur) ease, background var(--dur) ease;
}

.secondary-button:hover {
    background: transparent;
    border-color: var(--muted);
}

.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%;
    height: 100dvh;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.modal .modal-content {
    background-color: white;
    margin: auto;
    padding: 0;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    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: var(--muted);
    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: var(--ink);
    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: var(--ink);
    font-size: 14px;
}

.modal .form-group select,
.modal .form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #ffffff;
    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: var(--muted);
    box-shadow: 0 0 0 3px rgba(144, 132, 122, 0.12);
}

.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: var(--ink);
    color: var(--paper);
    border: 1px solid var(--ink);
    padding: 12px 24px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: var(--w-emphasis);
    cursor: pointer;
    transition: background var(--dur) ease, border-color var(--dur) ease;
    width: 100%;
}

.primary-button:hover {
    background: #1f1b18;
    border-color: #1f1b18;
}

/* 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);
}