/* Общи стилове за Вход / Регистрация / Табло */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: radial-gradient(circle at top, #1f2937 0, #020617 55%, #000 100%);
    font-family: system-ui, -apple-system, sans-serif;
    color: #e5e7eb;
}

.auth-box {
    width: 100%;
    max-width: 400px;
    padding: 32px;
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.98), rgba(2, 6, 23, 0.98));
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 16px;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
}

.auth-box h1 {
    margin: 0 0 8px;
    font-size: 1.5rem;
    font-weight: 700;
    color: #4ade80;
    text-align: center;
}

.auth-box .subtitle {
    margin: 0 0 24px;
    font-size: 0.9rem;
    color: #9ca3af;
    text-align: center;
}

.auth-form label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #e5e7eb;
}

.auth-form input {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid rgba(148, 163, 184, 0.4);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.95);
    color: #e5e7eb;
    font-size: 1rem;
    box-sizing: border-box;
}

.auth-form input:focus {
    outline: none;
    border-color: rgba(34, 197, 94, 0.7);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.auth-form button[type="submit"] {
    width: 100%;
    padding: 14px;
    margin-top: 8px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #4ade80, #22c55e);
    color: #022c22;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s, transform 0.15s;
}

.auth-form button[type="submit"]:hover {
    filter: brightness(1.05);
}

.auth-form button[type="submit"]:active {
    transform: scale(0.98);
}

.auth-form button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-error {
    margin-bottom: 16px;
    padding: 10px 12px;
    background: rgba(248, 113, 113, 0.15);
    border: 1px solid rgba(248, 113, 113, 0.4);
    border-radius: 8px;
    color: #fecaca;
    font-size: 0.9rem;
    display: none;
}

.auth-error.visible {
    display: block;
}

.auth-links {
    margin-top: 20px;
    text-align: center;
    font-size: 0.9rem;
}

.auth-links a {
    color: #4ade80;
    text-decoration: none;
}

.auth-links a:hover {
    text-decoration: underline;
}

.auth-footer {
    margin-top: 16px;
    text-align: center;
    font-size: 0.8rem;
    color: #9ca3af;
}
.auth-footer a {
    color: #9ca3af;
    text-decoration: none;
}
.auth-footer a:hover {
    text-decoration: underline;
    color: #d1d5db;
}

/* Dashboard */
.dashboard-page {
    min-height: 100vh;
    padding: 0;
    background: radial-gradient(circle at top, #1f2937 0, #020617 55%, #000 100%);
    font-family: system-ui, -apple-system, sans-serif;
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
}

.dashboard-header {
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.15);
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(12px);
}

.dashboard-brand h1 {
    margin: 0;
    font-size: 1.35rem;
    color: #4ade80;
}

.dashboard-brand-link {
    display: inline-block;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.dashboard-brand-link:hover {
    opacity: 0.9;
}

.dashboard-brand-link:focus-visible {
    outline: 2px solid rgba(74, 222, 128, 0.6);
    outline-offset: 4px;
}

.dashboard-header .user-email {
    margin: 4px 0 0;
    font-size: 0.85rem;
    color: #9ca3af;
}

.dashboard-header .user-uid-hint {
    margin: 2px 0 0;
    font-size: 0.75rem;
    color: #64748b;
}

.dashboard-header .user-uid-hint code {
    font-size: 0.7rem;
    background: rgba(0,0,0,0.25);
    padding: 2px 6px;
    border-radius: 4px;
    word-break: break-all;
}

.show-uid-btn {
    margin-top: 4px;
    padding: 0;
    border: none;
    background: none;
    color: #64748b;
    font-size: 0.75rem;
    cursor: pointer;
    text-decoration: underline;
}

.show-uid-btn:hover {
    color: #94a3b8;
}

.dashboard-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: 28px 24px 40px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.dashboard-top {
    width: 100%;
    display: flex;
    justify-content: center;
}

.dashboard-top .devices-card {
    width: 100%;
    max-width: 100%;
}

.dashboard-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

.dashboard-history,
.dashboard-mode {
    min-width: 0;
}

@media (max-width: 768px) {
    .dashboard-layout {
        padding: 20px 16px 32px;
        gap: 24px;
    }
    .dashboard-bottom {
        grid-template-columns: 1fr;
    }
}

.logout-btn {
    padding: 10px 18px;
    border: 1px solid rgba(248, 113, 113, 0.5);
    border-radius: 10px;
    background: rgba(248, 113, 113, 0.15);
    color: #fecaca;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: rgba(248, 113, 113, 0.25);
}

.mode-card {
    padding: 24px 26px;
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.97) 0%, rgba(2, 6, 23, 0.98) 100%);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 18px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

.mode-card h2 {
    margin: 0 0 8px;
    font-size: 1rem;
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: 0.03em;
}

.mode-card p {
    margin: 0 0 18px;
    font-size: 0.85rem;
    line-height: 1.55;
    color: #94a3b8;
}

.mode-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.mode-btn {
    flex: 1;
    min-width: 120px;
    padding: 14px 18px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(15, 23, 42, 0.8);
    color: #94a3b8;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    border-color: rgba(34, 197, 94, 0.5);
    color: #e2e8f0;
}

.mode-btn.active {
    background: linear-gradient(135deg, rgba(74, 222, 128, 0.22), rgba(34, 197, 94, 0.18));
    border-color: rgba(34, 197, 94, 0.5);
    color: #86efac;
}

.mode-btn.danger.active {
    background: rgba(248, 113, 113, 0.2);
    border-color: #f97373;
    color: #fecaca;
}

.sensor-status-msg {
    margin-top: 18px;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
}

.sensor-status-msg.away {
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.25);
    color: #fecaca;
}

.sensor-status-msg.home {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.25);
    color: #bbf7d0;
}

.devices-card {
    padding: 28px 28px 32px;
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.97) 0%, rgba(2, 6, 23, 0.98) 100%);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 18px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

.devices-card h2 {
    margin: 0 0 20px;
    font-size: 1.15rem;
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: 0.03em;
}

.duplicate-names-warning {
    margin-bottom: 16px;
    padding: 12px 14px;
    background: rgba(251, 191, 36, 0.15);
    border: 1px solid rgba(251, 191, 36, 0.5);
    border-radius: 10px;
    color: #fef3c7;
    font-size: 0.9rem;
    line-height: 1.5;
}

.device-item {
    padding: 16px 18px;
    margin-bottom: 12px;
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.device-item:hover {
    border-color: rgba(148, 163, 184, 0.25);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

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

.device-item.device-tint-0 {
    background: rgba(34, 197, 94, 0.12);
    border-left: 4px solid rgba(34, 197, 94, 0.7);
}
.device-item.device-tint-1 {
    background: rgba(59, 130, 246, 0.12);
    border-left: 4px solid rgba(59, 130, 246, 0.7);
}
.device-item.device-tint-2 {
    background: rgba(251, 191, 36, 0.12);
    border-left: 4px solid rgba(251, 191, 36, 0.7);
}
.device-item.device-tint-3 {
    background: rgba(168, 85, 247, 0.12);
    border-left: 4px solid rgba(168, 85, 247, 0.7);
}

.device-item .name {
    font-weight: 600;
    color: #e5e7eb;
}

.device-item .device-name-wrap {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.device-item .sensor-icon {
    font-size: 1.6rem;
    line-height: 1;
    min-width: 1.6rem;
    text-align: center;
}

.device-item .device-last-seen {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-left: 6px;
    font-weight: normal;
}

.device-item .device-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.device-item .device-battery {
    font-size: 0.8rem;
    color: #9ca3af;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(148, 163, 184, 0.2);
}

.device-item .device-power {
    font-size: 0.8rem;
    padding: 2px 8px;
    border-radius: 6px;
    font-weight: 600;
}

.device-item .device-power.usb {
    color: #93c5fd;
    background: rgba(59, 130, 246, 0.2);
}

.device-item .device-power.no-battery {
    color: #fecaca;
    background: rgba(248, 113, 113, 0.25);
}

.device-item .status {
    font-size: 0.85rem;
    padding: 4px 10px;
    border-radius: 999px;
}

.device-item .status.open {
    background: rgba(248, 113, 113, 0.2);
    color: #fecaca;
}

.device-item .status.closed {
    background: rgba(34, 197, 94, 0.2);
    color: #bbf7d0;
}

.devices-empty {
    color: #9ca3af;
    font-size: 0.9rem;
}

/* История – последни промени отворено/затворено */
.history-card {
    padding: 24px 26px;
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.97) 0%, rgba(2, 6, 23, 0.98) 100%);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 18px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

.history-card h2 {
    margin: 0 0 8px;
    font-size: 1rem;
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: 0.03em;
}

.history-desc {
    margin: 0 0 16px;
    font-size: 0.85rem;
    color: #94a3b8;
    line-height: 1.5;
}

.history-controls {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.history-controls > span {
    font-size: 0.9rem;
    color: #9ca3af;
}

.history-limit-btn {
    padding: 8px 16px;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.8);
    color: #94a3b8;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-limit-btn:hover {
    border-color: rgba(34, 197, 94, 0.45);
    color: #e2e8f0;
}

.history-limit-btn.active {
    background: rgba(74, 222, 128, 0.18);
    border-color: rgba(34, 197, 94, 0.5);
    color: #86efac;
}

.history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 420px;
    overflow-y: auto;
}

.history-item {
    padding: 14px 16px;
    margin-bottom: 10px;
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 14px;
    font-size: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    transition: border-color 0.2s, background 0.2s;
}

.history-item:hover {
    background: rgba(15, 23, 42, 0.55);
    border-color: rgba(148, 163, 184, 0.22);
}

.history-item:last-child {
    margin-bottom: 0;
}

.history-item.history-tint-0 {
    border-left: 4px solid rgba(34, 197, 94, 0.8);
    background: rgba(34, 197, 94, 0.08);
}
.history-item.history-tint-1 {
    border-left: 4px solid rgba(59, 130, 246, 0.8);
    background: rgba(59, 130, 246, 0.08);
}
.history-item.history-tint-2 {
    border-left: 4px solid rgba(251, 191, 36, 0.8);
    background: rgba(251, 191, 36, 0.08);
}
.history-item.history-tint-3 {
    border-left: 4px solid rgba(168, 85, 247, 0.8);
    background: rgba(168, 85, 247, 0.08);
}

.history-item .history-name {
    font-weight: 600;
    color: #e5e7eb;
}

.history-item .sensor-icon {
    font-size: 1.5rem;
    line-height: 1;
    min-width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

.history-item .history-status {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.history-item.open .history-status {
    background: rgba(248, 113, 113, 0.2);
    color: #fecaca;
}

.history-item.closed .history-status {
    background: rgba(34, 197, 94, 0.2);
    color: #bbf7d0;
}

.history-item .history-time {
    margin-left: auto;
    font-size: 0.8rem;
    color: #9ca3af;
}

.history-empty {
    padding: 16px;
    text-align: center;
    color: #9ca3af;
    font-size: 0.9rem;
}

.back-home {
    display: inline-block;
    margin-top: 24px;
    color: #4ade80;
    text-decoration: none;
    font-size: 0.9rem;
}

.back-home:hover {
    text-decoration: underline;
}

.dashboard-footer {
    padding: 18px 24px;
    text-align: center;
    border-top: 1px solid rgba(148, 163, 184, 0.15);
    background: rgba(15, 23, 42, 0.35);
    font-size: 0.9rem;
}

.dashboard-footer .footer-sep {
    margin: 0 0.5em;
    color: #6b7280;
}

.dashboard-footer a {
    color: #4ade80;
    text-decoration: none;
}

.dashboard-footer a:hover {
    text-decoration: underline;
}
