/* ===== LIGHT THEME (default) ===== */
:root {
    --dsn-bg-primary: #ffffff;
    --dsn-bg-secondary: #f9fafb;
    --dsn-bg-tertiary: #f3f4f6;
    --dsn-text-primary: #333639;
    --dsn-text-secondary: #667085;
    --dsn-text-muted: #9ca3af;
    --dsn-text-inverse: #ffffff;
    --dsn-border: #e5e7eb;
    --dsn-border-focus: #155EEF;
    --dsn-input-bg: #ffffff;
    --dsn-input-border: #d1d5db;
    --dsn-input-placeholder: #9ca3af;
    --dsn-accent: #155EEF;
    --dsn-accent-hover: #1249c4;
    --dsn-accent-light: #e0f0ff;
    --dsn-error: #dc2626;
    --dsn-error-bg: #fef2f2;
    --dsn-success: #16a34a;
    --dsn-success-bg: #f0fdf4;
    --dsn-warning: #d97706;
    --dsn-warning-bg: #fffbeb;
    --dsn-modal-overlay: rgba(0, 0, 0, 0.5);
    --dsn-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --dsn-shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
    --dsn-dropdown-bg: #ffffff;
    --dsn-dropdown-hover: #f3f4f6;
    --dsn-dropdown-selected: #e0f0ff;
    --dsn-offline-bg: #fef3c7;
    --dsn-offline-text: #92400e;
    --dsn-offline-border: #f59e0b;
    --dsn-danger: #dc2626;
    --dsn-danger-hover: #b91c1c;
}

/* ===== DARK THEME ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --dsn-bg-primary: #1a1a2e;
        --dsn-bg-secondary: #16213e;
        --dsn-bg-tertiary: #0f3460;
        --dsn-text-primary: #e0e0e0;
        --dsn-text-secondary: #a0aec0;
        --dsn-text-muted: #718096;
        --dsn-text-inverse: #1a1a2e;
        --dsn-border: #2d3748;
        --dsn-border-focus: #4d8aff;
        --dsn-input-bg: #16213e;
        --dsn-input-border: #2d3748;
        --dsn-input-placeholder: #718096;
        --dsn-accent: #4d8aff;
        --dsn-accent-hover: #3b76e8;
        --dsn-accent-light: #1e3a5f;
        --dsn-error: #f87171;
        --dsn-error-bg: #3b1111;
        --dsn-success: #4ade80;
        --dsn-success-bg: #0f2d1a;
        --dsn-warning: #fbbf24;
        --dsn-warning-bg: #3b2f0a;
        --dsn-modal-overlay: rgba(0, 0, 0, 0.7);
        --dsn-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
        --dsn-shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.5);
        --dsn-dropdown-bg: #16213e;
        --dsn-dropdown-hover: #0f3460;
        --dsn-dropdown-selected: #1e3a5f;
        --dsn-offline-bg: #3b2f0a;
        --dsn-offline-text: #fbbf24;
        --dsn-offline-border: #d97706;
        --dsn-danger: #f87171;
        --dsn-danger-hover: #ef4444;
    }
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--dsn-bg-secondary);
    color: var(--dsn-text-primary);
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ===== PORTAL CONTAINER ===== */
.dsn-portal-container {
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ===== STATE MANAGEMENT ===== */
.dsn-state {
    display: none;
}

.dsn-state.dsn-active {
    display: block;
}

.dsn-hidden {
    display: none !important;
}

/* ===== CENTERED CONTENT (auth screens) ===== */
.dsn-centered-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px 16px;
    text-align: center;
    max-width: 400px;
    margin: 0 auto;
}

/* ===== TYPOGRAPHY ===== */
.dsn-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--dsn-text-primary);
    margin-bottom: 8px;
}

.dsn-subtitle {
    font-size: 16px;
    color: var(--dsn-text-secondary);
    margin-bottom: 32px;
}

.dsn-text-secondary {
    color: var(--dsn-text-secondary);
    margin-bottom: 16px;
}

.dsn-text-muted {
    color: var(--dsn-text-muted);
    font-size: 14px;
}

.dsn-required {
    color: var(--dsn-error);
}

/* ===== BUTTONS ===== */
.dsn-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background-color 0.15s, opacity 0.15s;
    width: 100%;
    max-width: 300px;
}

.dsn-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

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

.dsn-button-primary:hover:not(:disabled) {
    background: var(--dsn-accent-hover);
}

.dsn-button-outline {
    background: transparent;
    color: var(--dsn-accent);
    border: 1px solid var(--dsn-accent);
}

.dsn-button-outline:hover:not(:disabled) {
    background: var(--dsn-accent-light);
}

.dsn-button-text {
    background: transparent;
    color: var(--dsn-text-secondary);
    padding: 8px 16px;
}

.dsn-button-text:hover {
    color: var(--dsn-text-primary);
}

.dsn-button-danger-text {
    background: transparent;
    color: var(--dsn-danger);
    padding: 8px 16px;
}

.dsn-button-danger-text:hover {
    color: var(--dsn-danger-hover);
}

.dsn-button-small {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 14px;
    width: auto;
    max-width: none;
}

.dsn-button-full {
    max-width: 100%;
}

/* ===== INPUTS ===== */
.dsn-input, .dsn-select, .dsn-textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    font-size: 16px;
    color: var(--dsn-text-primary);
    background: var(--dsn-input-bg);
    border: 1px solid var(--dsn-input-border);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.dsn-input:focus, .dsn-select:focus, .dsn-textarea:focus {
    border-color: var(--dsn-border-focus);
    box-shadow: 0 0 0 3px var(--dsn-accent-light);
}

.dsn-input::placeholder, .dsn-textarea::placeholder {
    color: var(--dsn-input-placeholder);
}

.dsn-input[readonly] {
    background: var(--dsn-bg-tertiary);
    cursor: default;
}

.dsn-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca3af' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.dsn-textarea {
    resize: vertical;
    min-height: 80px;
}

.dsn-code-input {
    text-align: center;
    font-size: 24px;
    letter-spacing: 8px;
    font-weight: 600;
    max-width: 240px;
}

/* ===== FORM LAYOUT ===== */
.dsn-form-container {
    width: 100%;
    padding: 16px;
    padding-bottom: 32px;
    max-width: 600px;
    margin: 0 auto;
}

.dsn-form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--dsn-border);
}

.dsn-form-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--dsn-text-primary);
}

.dsn-form-group {
    margin-bottom: 16px;
    position: relative;
    width: 100%;
}

.dsn-form-row {
    display: flex;
    gap: 12px;
}

.dsn-form-group-half {
    flex: 1;
}

.dsn-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--dsn-text-secondary);
    margin-bottom: 6px;
}

/* ===== SEARCH / DROPDOWN ===== */
.dsn-search-input-wrapper {
    position: relative;
}

.dsn-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--dsn-dropdown-bg);
    border: 1px solid var(--dsn-border);
    border-radius: 8px;
    box-shadow: var(--dsn-shadow-lg);
    max-height: 280px;
    overflow-y: auto;
    margin-top: 4px;
}

.dsn-dropdown-action {
    display: block;
    width: 100%;
    padding: 12px 14px;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid var(--dsn-border);
    color: var(--dsn-accent);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    min-height: 44px;
}

.dsn-dropdown-action:hover {
    background: var(--dsn-dropdown-hover);
}

.dsn-dropdown-results {
    max-height: 240px;
    overflow-y: auto;
}

.dsn-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    cursor: pointer;
    min-height: 44px;
    border-bottom: 1px solid var(--dsn-border);
}

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

.dsn-dropdown-item:hover {
    background: var(--dsn-dropdown-hover);
}

.dsn-dropdown-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--dsn-accent-light);
    color: var(--dsn-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.dsn-dropdown-item-info {
    flex: 1;
    min-width: 0;
}

.dsn-dropdown-item-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--dsn-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dsn-dropdown-item-detail {
    font-size: 12px;
    color: var(--dsn-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dsn-dropdown-loading, .dsn-dropdown-empty {
    padding: 16px;
    text-align: center;
    color: var(--dsn-text-muted);
    font-size: 14px;
}

/* ===== SELECTED DISPLAY ===== */
.dsn-selected-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--dsn-bg-tertiary);
    border: 1px solid var(--dsn-border);
    border-radius: 8px;
    gap: 12px;
}

.dsn-selected-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.dsn-selected-name {
    font-weight: 500;
    color: var(--dsn-text-primary);
}

.dsn-selected-detail {
    font-size: 13px;
    color: var(--dsn-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dsn-selected-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ===== CHECKBOX ===== */
.dsn-checkbox-wrapper {
    transition: opacity 0.15s;
}

.dsn-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--dsn-text-secondary);
    min-height: 44px;
}

.dsn-checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--dsn-accent);
}

/* ===== ERROR / SUCCESS MESSAGES ===== */
.dsn-error-message {
    color: var(--dsn-error);
    background: var(--dsn-error-bg);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin: 8px 0;
    width: 100%;
    text-align: left;
}

.dsn-success-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--dsn-success-bg);
    color: var(--dsn-success);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: bold;
    margin-bottom: 16px;
}

.dsn-error-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--dsn-error-bg);
    color: var(--dsn-error);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: bold;
    margin-bottom: 16px;
}

/* ===== SPINNER ===== */
.dsn-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--dsn-border);
    border-top-color: var(--dsn-accent);
    border-radius: 50%;
    animation: dsn-spin 0.8s linear infinite;
    margin-bottom: 16px;
}

.dsn-spinner-small {
    width: 18px;
    height: 18px;
    border: 2px solid var(--dsn-border);
    border-top-color: var(--dsn-accent);
    border-radius: 50%;
    animation: dsn-spin 0.8s linear infinite;
}

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

/* ===== LOCATION CARD ===== */
.dsn-location-card {
    padding: 16px;
    background: var(--dsn-bg-tertiary);
    border: 1px solid var(--dsn-border);
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 500;
    width: 100%;
    text-align: center;
}

.dsn-location-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--dsn-border);
    width: 100%;
}

/* ===== OFFLINE BANNER ===== */
.dsn-offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20000;
    background: var(--dsn-offline-bg);
    color: var(--dsn-offline-text);
    text-align: center;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid var(--dsn-offline-border);
}

/* ===== MODAL ===== */
.dsn-modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--dsn-modal-overlay);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 10vh 16px 16px;
    z-index: 10000;
    overflow-y: auto;
}

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

.dsn-modal-content {
    background: var(--dsn-bg-primary);
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    max-height: 70vh;
    max-height: 70dvh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--dsn-shadow-lg);
}

.dsn-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--dsn-border);
}

.dsn-modal-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--dsn-text-primary);
}

.dsn-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--dsn-text-muted);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dsn-modal-body {
    overflow-y: auto;
    padding: 16px;
    flex: 1;
}

.dsn-modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--dsn-border);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.dsn-modal-footer .dsn-button {
    width: auto;
    max-width: none;
}

/* ===== GOOGLE SIGN-IN WRAPPER ===== */
.dsn-google-btn-wrapper {
    margin: 16px 0;
}

/* ===== RESPONSIVE ===== */

/* Large phone / small tablet */
@media (min-width: 481px) {
    .dsn-form-container {
        padding: 24px;
    }
}

/* Tablet / desktop */
@media (min-width: 769px) {
    .dsn-form-container {
        padding: 32px;
    }
}

/* Small phone adjustments */
@media (max-width: 360px) {
    .dsn-form-row {
        flex-direction: column;
        gap: 0;
    }

    .dsn-code-input {
        letter-spacing: 4px;
    }
}
