/* ========== KNX2HA – Style Sheet ========== */

/* ---------- Variables ---------- */
:root {
    --bg-dark: #1a1a2e;
    --bg-mid: #16213e;
    --bg-card: #1e2a45;
    --bg-input: #0f1729;
    --accent: #ff6b35;
    --accent-hover: #ff8555;
    --accent-dim: rgba(255, 107, 53, 0.15);
    --text-primary: #e8eaf0;
    --text-secondary: #8892a4;
    --text-muted: #5a6478;
    --border: #2a3550;
    --border-focus: #ff6b35;
    --success: #3fb950;
    --error: #f85149;
    --warning: #d29922;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

code {
    font-family: 'Courier New', 'Consolas', monospace;
    background: var(--bg-input);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--accent);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.hidden { display: none !important; }

/* ---------- Screens ---------- */
.screen { display: none; }
.screen.active { display: flex; }

/* ---------- Auth Screen ---------- */
#auth-screen {
    min-height: 100vh;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at 50% 0%, rgba(255, 107, 53, 0.08) 0%, transparent 60%),
                var(--bg-dark);
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 2rem;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2.5rem;
}

.logo-icon {
    margin-bottom: 1rem;
}

.auth-logo h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.accent {
    color: var(--accent);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

/* ---------- Auth Forms ---------- */
.auth-form {
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.auth-form h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.form-hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.input-group {
    position: relative;
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

.input-group input {
    width: 100%;
    padding: 0.75rem 2.75rem 0.75rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color var(--transition);
    outline: none;
}

.input-group input:focus {
    border-color: var(--border-focus);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.toggle-pw {
    position: absolute;
    right: 0.65rem;
    bottom: 0.6rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem;
    transition: color var(--transition);
}

.toggle-pw:hover { color: var(--text-secondary); }

/* ---------- Password Requirements ---------- */
.pw-requirements {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
}

.req {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-muted);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.req.met {
    color: var(--success);
    border-color: var(--success);
    background: rgba(63, 185, 80, 0.1);
}

/* ---------- Error / Lockout ---------- */
.error-msg {
    color: var(--error);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    padding: 0.5rem 0.75rem;
    background: rgba(248, 81, 73, 0.1);
    border-radius: var(--radius);
    border: 1px solid rgba(248, 81, 73, 0.2);
}

.lockout-msg {
    color: var(--warning);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    padding: 0.5rem 0.75rem;
    background: rgba(210, 153, 34, 0.1);
    border-radius: var(--radius);
    border: 1px solid rgba(210, 153, 34, 0.2);
    text-align: center;
}

.error-box {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 1rem;
    background: rgba(248, 81, 73, 0.08);
    border: 1px solid rgba(248, 81, 73, 0.2);
    border-radius: var(--radius);
    color: var(--error);
    margin-bottom: 1.5rem;
}

.error-box strong { display: block; margin-bottom: 0.25rem; }
.error-box p { font-size: 0.85rem; color: var(--text-secondary); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    width: 100%;
    justify-content: center;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover { color: var(--text-primary); }

.btn-link {
    background: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-decoration: underline;
    width: 100%;
    justify-content: center;
    margin-top: 0.5rem;
    padding: 0.4rem;
}

.btn-link:hover { color: var(--text-secondary); }

.btn-sm {
    padding: 0.45rem 0.85rem;
    font-size: 0.8rem;
}

/* ---------- App Header ---------- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-mid);
    border-bottom: 1px solid var(--border);
}

.header-left { display: flex; align-items: center; }

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

.header-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.header-right { display: flex; align-items: center; gap: 0.5rem; }

/* ---------- App Screen Layout ---------- */
#app-screen {
    flex-direction: column;
    min-height: 100vh;
}

#app-screen.active { display: flex; }

/* ---------- Step Indicator ---------- */
.step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    gap: 0;
    background: var(--bg-mid);
    border-bottom: 1px solid var(--border);
}

.step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    border-radius: 20px;
    cursor: default;
    transition: all var(--transition);
}

.step-number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--bg-input);
    border: 2px solid var(--border);
    color: var(--text-muted);
    transition: all var(--transition);
}

.step-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
    transition: color var(--transition);
}

.step.active .step-number {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.step.active .step-label { color: var(--text-primary); }

.step.completed .step-number {
    background: var(--success);
    border-color: var(--success);
    color: #fff;
}

.step.completed .step-label { color: var(--text-secondary); }

.step-line {
    width: 40px;
    height: 2px;
    background: var(--border);
    margin: 0 0.5rem;
    transition: background var(--transition);
}

.step-line.completed { background: var(--success); }

/* ---------- Main Content ---------- */
.app-main {
    flex: 1;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.step-content { display: none; }
.step-content.active { display: block; }

.step-header {
    margin-bottom: 2rem;
}

.step-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.step-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.optional-badge {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 4px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ---------- Drop Zone ---------- */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 3rem 2rem;
    text-align: center;
    transition: all var(--transition);
    cursor: pointer;
    background: var(--bg-mid);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    background: var(--accent-dim);
}

.drop-zone-small {
    padding: 2rem 1.5rem;
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.drop-text {
    font-size: 1.1rem;
    font-weight: 500;
}

.drop-or {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.drop-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.5rem;
}

/* ---------- Loading / Spinner ---------- */
.loading {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

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

.progress-bar {
    width: 100%;
    max-width: 300px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 1rem auto 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
}

/* ---------- Results Table ---------- */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.results-header h3 {
    font-size: 1.1rem;
}

.results-stats {
    display: flex;
    gap: 0.5rem;
}

.stat-badge {
    font-size: 0.8rem;
    padding: 0.3rem 0.65rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
}

.filter-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-input,
.filter-select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    transition: border-color var(--transition);
}

.filter-input { flex: 1; min-width: 150px; }

.filter-input:focus,
.filter-select:focus {
    border-color: var(--border-focus);
}

.filter-select {
    appearance: none;
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238892a4'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
}

.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}

#ga-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

#ga-table th {
    background: var(--bg-card);
    padding: 0.65rem 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

#ga-table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

#ga-table tbody tr:hover {
    background: rgba(255, 107, 53, 0.04);
}

#ga-table tbody tr:last-child td {
    border-bottom: none;
}

#ga-table input[type="checkbox"] {
    accent-color: var(--accent);
    cursor: pointer;
}

#ga-table select {
    padding: 0.3rem 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.8rem;
    outline: none;
}

#ga-table select:focus {
    border-color: var(--accent);
}

/* Type badges */
.type-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.type-badge.light      { background: rgba(250, 204, 21, 0.15); color: #facc15; }
.type-badge.switch      { background: rgba(96, 165, 250, 0.15); color: #60a5fa; }
.type-badge.cover       { background: rgba(52, 211, 153, 0.15); color: #34d399; }
.type-badge.climate     { background: rgba(248, 113, 113, 0.15); color: #f87171; }
.type-badge.sensor      { background: rgba(192, 132, 252, 0.15); color: #c084fc; }
.type-badge.binary_sensor { background: rgba(251, 146, 60, 0.15); color: #fb923c; }
.type-badge.unknown     { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }

/* ---------- Comparison Cards ---------- */
.comparison-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.comparison-card {
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}

.comparison-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.75rem;
}

.comparison-icon.skip {
    background: rgba(248, 81, 73, 0.1);
    color: var(--error);
}

.comparison-icon.add {
    background: rgba(63, 185, 80, 0.1);
    color: var(--success);
}

.comparison-value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.comparison-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ---------- Step Actions ---------- */
.step-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.step-actions .btn-primary {
    width: auto;
}

/* ---------- YAML Preview ---------- */
.yaml-preview-container {
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.yaml-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.yaml-preview-header h3 {
    font-size: 0.9rem;
    font-weight: 600;
}

.yaml-preview-actions {
    display: flex;
    gap: 0.5rem;
}

.yaml-code {
    padding: 1.25rem;
    font-family: 'Courier New', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.7;
    overflow-x: auto;
    color: var(--text-primary);
    max-height: 500px;
    overflow-y: auto;
    white-space: pre;
    tab-size: 2;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--success);
    color: #fff;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 100;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- Footer ---------- */
.app-footer {
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ---------- Current User ---------- */
.current-user {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 0.3rem 0.65rem;
    background: var(--bg-input);
    border-radius: 20px;
    border: 1px solid var(--border);
}

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

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

.modal-header h2 { font-size: 1.15rem; }

.modal-body {
    padding: 1.5rem;
}

.modal-body h3 {
    font-size: 0.95rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.modal-body .input-group { margin-bottom: 0.75rem; }
.modal-body .btn-primary { margin-top: 0.5rem; }

.success-msg {
    color: var(--success);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: rgba(63, 185, 80, 0.1);
    border-radius: var(--radius);
    border: 1px solid rgba(63, 185, 80, 0.2);
}

/* ---------- User List ---------- */
.user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.user-item .user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-item .role-badge {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 600;
}

.user-item .btn-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem;
    font-size: 1.1rem;
    transition: color var(--transition);
}

.user-item .btn-delete:hover { color: var(--error); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .step-label { display: none; }
    .step-indicator { padding: 1rem; }
    .app-main { padding: 1.5rem 1rem; }
    .filter-bar { flex-direction: column; }
    .comparison-cards { grid-template-columns: 1fr; }
    .step-actions { flex-direction: column; }
    .step-actions .btn { width: 100%; justify-content: center; }
    .yaml-preview-header { flex-direction: column; align-items: flex-start; }
    .yaml-preview-actions { width: 100%; }
    .yaml-preview-actions .btn { flex: 1; justify-content: center; }
}
