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

:root {
    --primary-color: #007AFF;
    --danger-color: #FF3B30;
    --success-color: #34C759;
    --background: #F2F2F7;
    --surface: #FFFFFF;
    --text-primary: #000000;
    --text-secondary: #8E8E93;
    --border: #C6C6C8;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.4;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    min-height: 100vh;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 12px;
}

header {
    background: var(--surface);
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    box-shadow: 0 1px 4px var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 22px;
    font-weight: 700;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background: var(--success-color);
}

.status-dot.error {
    background: var(--danger-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.login-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.login-box {
    background: var(--surface);
    padding: 40px 30px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
    width: 100%;
    max-width: 400px;
}

.login-box h2 {
    margin-bottom: 20px;
    text-align: center;
}

.login-box input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 20px;
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.filter-section {
    background: var(--surface);
    padding: 10px 12px;
    border-radius: 8px;
    box-shadow: 0 1px 4px var(--shadow);
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.filter-section label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    min-width: 100px;
}

.room-filter,
.state-filter {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--surface);
    color: var(--text-primary);
    font-family: inherit;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    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='%23000' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.room-filter:focus,
.state-filter:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
}

.devices-section {
    background: var(--surface);
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 1px 4px var(--shadow);
}

.devices-section h2 {
    font-size: 16px;
    margin-bottom: 10px;
    font-weight: 600;
}

.devices-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.device-item {
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    background: var(--background);
    border-radius: 6px;
    border: 1px solid var(--border);
    gap: 6px;
}

.device-item > .device-info {
    display: flex;
    flex-direction: column;
}

.device-item > .device-status {
    align-self: flex-start;
}

.device-item > .device-actions {
    align-self: flex-end;
    margin-top: auto;
}

.device-info {
    flex: 1;
}

.device-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.device-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.device-type-badge {
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.device-room {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.device-last-contact {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
    font-style: italic;
}

.blind-graphic {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.blind-window {
    width: 60px;
    height: 80px;
    border: 2px solid var(--border);
    border-radius: 4px;
    background: linear-gradient(to bottom, #E8F4F8 0%, #D0E8F0 100%);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.blind-single {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, #4A5568 0%, #2D3748 100%);
    transition: height 0.3s ease;
    border-top: 1px solid rgba(0, 0, 0, 0.2);
}

.blind-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, #4A5568 0%, #2D3748 100%);
    transition: height 0.3s ease;
    border-bottom: 1px solid rgba(0, 0, 0, 0.2);
}

.blind-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, #4A5568 0%, #2D3748 100%);
    transition: height 0.3s ease;
    border-top: 1px solid rgba(0, 0, 0, 0.2);
}

.blind-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.blind-control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.blind-control-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 50px;
    flex-shrink: 0;
}

.blind-slider {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    min-width: 100px;
}

.blind-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 1px 3px var(--shadow);
}

.blind-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px var(--shadow);
}

.blind-value {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 35px;
    text-align: right;
    flex-shrink: 0;
}

.powerview-details {
    margin-top: 6px;
    padding: 6px;
    background: var(--background);
    border-radius: 4px;
    font-size: 11px;
}

.device-detail {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 2px;
    line-height: 1.3;
}

.device-detail:last-child {
    margin-bottom: 0;
}

.detail-label {
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 70px;
    flex-shrink: 0;
    font-size: 11px;
}

.detail-value {
    color: var(--text-primary);
    font-weight: 400;
}

.detail-raw {
    color: var(--text-secondary);
    font-size: 11px;
    font-style: italic;
}

.battery-good {
    color: var(--success-color);
}

.battery-medium {
    color: #FF9500;
}

.battery-low {
    color: var(--danger-color);
}

.signal-good {
    color: var(--success-color);
}

.signal-medium {
    color: #FF9500;
}

.signal-low {
    color: var(--danger-color);
}

.brightness-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 6px 0;
    padding: 6px;
    background: var(--background);
    border-radius: 6px;
    flex-wrap: wrap;
    width: 100%;
}

.brightness-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}

.brightness-slider {
    flex: 1;
    min-width: 120px;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.brightness-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 2px 4px var(--shadow);
}

.brightness-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px var(--shadow);
}

.brightness-value {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 40px;
    text-align: center;
}

.hub-group {
    background: var(--background);
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 12px;
    overflow: hidden;
}

.hub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.hub-name {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
}

.hub-status {
    display: flex;
    align-items: center;
}

.hub-devices {
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hub-devices .device-item {
    margin: 0;
    border: 1px solid var(--border);
    background: var(--surface);
}

.room-controls {
    background: var(--surface);
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
}

.room-controls-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.room-controls-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.room-control-btn {
    padding: 6px 12px;
    font-size: 12px;
    white-space: nowrap;
}

.device-type {
    font-size: 14px;
    color: var(--text-secondary);
}

.device-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 12px;
}

.status-badge {
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.status-badge.on {
    background: var(--success-color);
    color: white;
}

.status-badge.position {
    background: var(--primary-color);
    color: white;
}

.status-badge.off {
    background: var(--text-secondary);
    color: white;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
}

.btn-primary:active {
    background: #0051D5;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:active {
    background: #D70015;
}

.btn-secondary {
    background: var(--surface);
    color: var(--primary-color);
    border: 1px solid var(--border);
}

.btn-secondary:active {
    background: var(--background);
}

.btn-large {
    width: 100%;
    padding: 12px;
    font-size: 15px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.actions-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 13px;
}

.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 13px;
}

.error-message {
    background: #FFF3F3;
    color: var(--danger-color);
    padding: 8px 10px;
    border-radius: 6px;
    margin-top: 12px;
    border: 1px solid #FFE5E5;
    font-size: 12px;
}

.hidden {
    display: none !important;
}

/* iPhone safe area support */
@supports (padding: max(0px)) {
    body {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

/* Touch target sizes for mobile */
.btn {
    min-height: 36px; /* Slightly reduced but still touchable */
    -webkit-tap-highlight-color: transparent;
}

/* Prevent text selection on buttons */
.btn {
    user-select: none;
    -webkit-user-select: none;
}

/* Improve button feedback on mobile */
.btn:active {
    transform: scale(0.98);
    transition: transform 0.1s;
}

/* Responsive typography */
@media (max-width: 480px) {
    h1 {
        font-size: 20px;
    }
    
    .device-name {
        font-size: 13px;
    }
    
    .container {
        padding: 10px;
    }
}

