:root {
    /* Braun Palette */
    --device-bg: #e5e5e0; /* Classic off-white/beige */
    --page-bg: #d0cec7; /* Slightly darker surrounding */
    --text-main: #1a1a1a;
    --text-muted: #666666;
    
    --accent-orange: #e55300;
    --accent-orange-hover: #cc4a00;
    --accent-green: #526f58;
    --accent-green-hover: #435b48;
    --accent-dark: #333333;
    
    --border-light: #ffffff;
    --border-dark: #b8b8b8;
    --input-bg: #f4f4f2;
}

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

body {
    font-family: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-color: var(--page-bg);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
}

/* Device Casing */
.app-container {
    width: 100%;
    max-width: 750px;
    background-color: var(--device-bg);
    border-radius: 24px;
    padding: 2.5rem;
    box-shadow: 
        inset 2px 2px 4px var(--border-light),
        inset -2px -2px 6px rgba(0,0,0,0.05),
        10px 15px 30px rgba(0,0,0,0.15),
        0 0 0 1px rgba(0,0,0,0.05); /* subtle edge */
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-dark);
    margin-bottom: 0.5rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo svg {
    color: var(--text-main);
}

h1 {
    font-weight: 600;
    font-size: 1.75rem;
    letter-spacing: -0.03em;
    color: var(--text-main);
}

h2 {
    font-size: 1.1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* Cards / Sections (Clean division, no typical web cards) */
.card {
    padding: 1.5rem 0;
}

/* Inputs - Recessed look */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.input-group:last-child {
    margin-bottom: 0;
}

label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
}

input[type="url"],
input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 0.875rem 1rem;
    background-color: var(--input-bg);
    border: none;
    border-radius: 6px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    box-shadow: 
        inset 2px 2px 5px rgba(0,0,0,0.1),
        inset -1px -1px 2px #ffffff;
    transition: all 0.2s ease;
}

input[type="url"]:focus,
input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    background-color: #ffffff;
}

input::placeholder {
    color: #a0a0a0;
}

/* Autocomplete dropdown styles */
.input-with-dropdown {
    position: relative;
    width: 100%;
}

.autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background-color: var(--input-bg);
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    max-height: 220px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
}

.autocomplete-dropdown.hidden {
    display: none;
}

.dropdown-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-main);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.15s ease;
    text-align: left;
}

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

.dropdown-item:hover,
.dropdown-item.focused {
    background-color: rgba(229, 83, 0, 0.08);
    color: var(--accent-orange);
}

.dropdown-item-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: auto;
}

.dropdown-loading, .dropdown-no-results {
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-style: italic;
}

/* Settings Card */
.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 1rem 0;
    border-top: 1px solid var(--border-dark);
}

.settings-header h2 {
    margin: 0;
}

.chevron {
    color: var(--text-main);
    transition: transform 0.3s ease;
}

.settings-card.open .chevron {
    transform: rotate(180deg);
}

.settings-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.4s ease;
}

.settings-card.open .settings-content {
    max-height: 1500px;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 2.5rem 1.5rem;
}

.setting-group h3 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    padding-bottom: 0.5rem;
}

/* Toggles - Physical Switch Look */
.toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    margin-bottom: 1rem;
}

.toggle input {
    display: none;
}

.slider {
    position: relative;
    width: 40px;
    height: 22px;
    background: #cccccc;
    border-radius: 12px;
    transition: 0.3s;
    box-shadow: inset 1px 1px 3px rgba(0,0,0,0.2);
}

.slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    background: #ffffff;
    box-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    transition: 0.3s;
}

.toggle input:checked + .slider {
    background: var(--accent-green);
}

.toggle input:checked + .slider::before {
    transform: translateX(18px);
}

.label-text {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Color Picker */
.color-input {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.color-picker-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--input-bg);
    border-radius: 6px;
    padding: 0.25rem 0.5rem 0.25rem 0.25rem;
    box-shadow: inset 1px 1px 3px rgba(0,0,0,0.1);
}

input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 4px;
}

.color-val {
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Physical Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.1s ease;
    border: none;
    user-select: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn-primary {
    background: var(--accent-orange);
    color: white;
    width: 100%;
    padding: 1.125rem;
    font-size: 1.1rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-radius: 8px;
    box-shadow: 
        0 4px 0 #bc4502,
        0 5px 10px rgba(0,0,0,0.2),
        inset 0 1px 1px rgba(255,255,255,0.3);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(4px);
    box-shadow: 
        0 0 0 #bc4502,
        0 1px 2px rgba(0,0,0,0.2),
        inset 0 1px 3px rgba(0,0,0,0.2);
}

.btn-secondary {
    background: var(--accent-dark);
    color: white;
    box-shadow: 
        0 3px 0 #1a1a1a,
        0 4px 6px rgba(0,0,0,0.15),
        inset 0 1px 1px rgba(255,255,255,0.2);
}

.btn-secondary:active:not(:disabled) {
    transform: translateY(3px);
    box-shadow: 
        0 0 0 #1a1a1a,
        0 1px 2px rgba(0,0,0,0.2);
}

/* Override for connected state */
.btn-secondary.connected {
    background: var(--accent-green) !important;
    box-shadow: 
        0 3px 0 #3b503f !important,
        0 4px 6px rgba(0,0,0,0.15) !important,
        inset 0 1px 1px rgba(255,255,255,0.2) !important;
}

.btn-secondary.connected:active:not(:disabled) {
    transform: translateY(3px) !important;
    box-shadow: 
        0 0 0 #3b503f !important,
        0 1px 2px rgba(0,0,0,0.2) !important !important;
}


/* Action Bar */
.action-bar {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--border-dark);
}

/* Status Message */
.status-message {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    margin-top: 1rem;
    border-radius: 6px;
    background: #e8f5e9;
    border: 1px solid #c8e6c9;
    color: #2e7d32;
    opacity: 1;
    transition: opacity 0.3s ease;
    font-weight: 500;
}

.status-message.hidden {
    opacity: 0;
    pointer-events: none;
    position: absolute;
}

.status-message.error {
    background: #ffebee;
    border: 1px solid #ffcdd2;
    color: #c62828;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-bottom-color: transparent;
    border-radius: 50%;
    animation: rotation 1s linear infinite;
}

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

@media (max-width: 640px) {
    body {
        padding: 1rem;
        align-items: flex-start;
    }
    
    .app-container {
        padding: 1.5rem;
        border-radius: 16px;
    }
    
    .settings-grid {
        grid-template-columns: 1fr;
    }
}
