/**
 * سامانه هوشمند — طراحی پنل کاربری
 * پالت: slate + emerald (حفظ طیف پروژه)
 * امضا: Ambient Home Mesh — هالهٔ نوری خانهٔ هوشمند + شبکهٔ گره‌ها
 */

:root {
    --ink: #020617;
    --surface: #070d18;
    --panel: rgba(15, 23, 42, 0.78);
    --panel-solid: #0f172a;
    --panel-2: #1e293b;
    --line: rgba(51, 65, 85, 0.85);
    --line-soft: rgba(148, 163, 184, 0.1);
    --text: #f1f5f9;
    --text-soft: #cbd5e1;
    --muted: #94a3b8;
    --faint: #64748b;
    --emerald: #10b981;
    --emerald-bright: #34d399;
    --emerald-deep: #064e3b;
    --emerald-glow: rgba(16, 185, 129, 0.22);
    --danger: #f87171;
    --radius: 1.15rem;
    --radius-sm: 0.85rem;
    --shadow-panel: 0 18px 50px -28px rgba(0, 0, 0, 0.75), 0 0 0 1px rgba(16, 185, 129, 0.04);
    --font: 'IRANSans', Tahoma, sans-serif;
}

* { font-family: var(--font); }

html { scroll-behavior: smooth; }

body.user-app {
    background-color: var(--ink);
    color: var(--text-soft);
    min-height: 100vh;
    position: relative;
}

/* ---------- Ambient mesh background ---------- */
body.user-app::before,
.auth-shell::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(ellipse 55% 40% at 85% 8%, rgba(16, 185, 129, 0.16), transparent 60%),
        radial-gradient(ellipse 45% 35% at 10% 90%, rgba(6, 78, 59, 0.35), transparent 55%),
        radial-gradient(ellipse 30% 25% at 50% 45%, rgba(16, 185, 129, 0.05), transparent 70%),
        linear-gradient(180deg, #020617 0%, #070d18 50%, #020617 100%);
}

body.user-app::after,
.auth-shell::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.35;
    background-image:
        radial-gradient(circle at center, rgba(52, 211, 153, 0.45) 0.6px, transparent 0.8px);
    background-size: 28px 28px;
    mask-image: radial-gradient(ellipse 70% 60% at 50% 30%, #000 10%, transparent 75%);
    -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 30%, #000 10%, transparent 75%);
}

.user-shell,
.auth-shell > * {
    position: relative;
    z-index: 1;
}

/* ---------- Brand mark ---------- */
.brand-mark {
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 0.85rem;
    background:
        linear-gradient(145deg, #34d399 0%, #10b981 55%, #059669 100%);
    color: #020617;
    display: grid;
    place-items: center;
    font-weight: 900;
    letter-spacing: -0.04em;
    box-shadow:
        0 0 0 1px rgba(52, 211, 153, 0.35),
        0 10px 28px -10px rgba(16, 185, 129, 0.65);
    position: relative;
}

.brand-mark::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 1rem;
    border: 1px solid rgba(52, 211, 153, 0.2);
    opacity: 0.7;
    animation: brandPulse 4.5s ease-in-out infinite;
}

@keyframes brandPulse {
    0%, 100% { transform: scale(1); opacity: 0.45; }
    50% { transform: scale(1.06); opacity: 0.9; }
}

.brand-mark-lg {
    width: 4.25rem;
    height: 4.25rem;
    border-radius: 1.35rem;
    font-size: 1.85rem;
}

.brand-mark-lg::after {
    inset: -6px;
    border-radius: 1.55rem;
}

/* ---------- Sidebar ---------- */
.user-sidebar {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.96) 0%, rgba(2, 6, 23, 0.98) 100%);
    border-left: 1px solid var(--line);
    backdrop-filter: blur(18px);
}

.user-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.78rem 1rem;
    border-radius: 0.95rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--muted);
    transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.user-sidebar .nav-link:hover {
    background: rgba(30, 41, 59, 0.55);
    color: var(--text);
}

.user-sidebar .nav-link.is-active {
    background: linear-gradient(90deg, rgba(16, 185, 129, 0.18), rgba(16, 185, 129, 0.06));
    color: var(--emerald-bright);
    box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.28);
}

.user-sidebar .nav-link svg {
    flex-shrink: 0;
    opacity: 0.9;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem;
    border-radius: 1rem;
    background: rgba(30, 41, 59, 0.45);
    border: 1px solid var(--line-soft);
}

.user-avatar {
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 9999px;
    display: grid;
    place-items: center;
    font-weight: 700;
    background: rgba(16, 185, 129, 0.16);
    color: var(--emerald-bright);
    box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.25);
}

/* ---------- Header ---------- */
.user-header {
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
}

.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem 0.7rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    color: var(--emerald-bright);
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.22);
}

.live-pill span {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 9999px;
    background: var(--emerald-bright);
    box-shadow: 0 0 10px var(--emerald);
    animation: liveBlink 1.8s ease-in-out infinite;
}

@keyframes liveBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* ---------- Surfaces ---------- */
.u-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-panel);
    backdrop-filter: blur(12px);
}

.u-card-solid {
    background: var(--panel-solid);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-panel);
}

.u-hero {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    border: 1px solid rgba(16, 185, 129, 0.22);
    background:
        linear-gradient(115deg, rgba(16, 185, 129, 0.16) 0%, rgba(15, 23, 42, 0.4) 45%, rgba(15, 23, 42, 0.85) 100%);
    padding: 1.6rem 1.5rem;
    box-shadow: var(--shadow-panel);
}

.u-hero::before {
    content: '';
    position: absolute;
    inset: auto -20% -60% auto;
    width: 280px;
    height: 280px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(52, 211, 153, 0.22), transparent 65%);
    pointer-events: none;
}

.u-hero > * { position: relative; z-index: 1; }

.u-stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.15rem 1.1rem;
    box-shadow: var(--shadow-panel);
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.u-stat:hover {
    border-color: rgba(16, 185, 129, 0.28);
    transform: translateY(-2px);
}

.u-icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.9rem;
    display: grid;
    place-items: center;
}

.u-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: rgba(30, 41, 59, 0.35);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.u-row:hover {
    background: rgba(30, 41, 59, 0.55);
    border-color: rgba(16, 185, 129, 0.18);
}

.u-empty {
    text-align: center;
    padding: 3.25rem 1.5rem;
}

.u-empty .u-icon {
    width: 4rem;
    height: 4rem;
    margin: 0 auto 1rem;
    border-radius: 1.15rem;
    background: rgba(30, 41, 59, 0.7);
    color: var(--faint);
}

/* ---------- Buttons & forms ---------- */
.u-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    font-weight: 700;
    border-radius: 0.9rem;
    padding: 0.7rem 1.15rem;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.u-btn:active { transform: scale(0.98); }

.u-btn-primary {
    background: linear-gradient(180deg, #34d399 0%, #10b981 100%);
    color: #020617;
    box-shadow: 0 10px 28px -12px rgba(16, 185, 129, 0.7);
}

.u-btn-primary:hover {
    background: linear-gradient(180deg, #6ee7b7 0%, #34d399 100%);
}

.u-btn-ghost {
    border: 1px solid var(--line);
    color: var(--text-soft);
    background: transparent;
}

.u-btn-ghost:hover {
    background: rgba(30, 41, 59, 0.6);
    border-color: rgba(16, 185, 129, 0.35);
    color: var(--emerald-bright);
}

.u-btn-soft {
    background: rgba(30, 41, 59, 0.7);
    color: var(--text-soft);
    border: 1px solid transparent;
}

.u-btn-soft:hover {
    background: rgba(51, 65, 85, 0.8);
}

.u-label {
    display: block;
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.u-field,
.field,
.password-field input {
    width: 100%;
    background: rgba(30, 41, 59, 0.55) !important;
    border: 1px solid #334155 !important;
    border-radius: 0.9rem !important;
    padding: 0.7rem 1rem !important;
    color: var(--text) !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
}

.password-field input {
    padding-left: 3rem !important;
    padding-right: 1rem !important;
}

.u-field:focus,
.field:focus,
.password-field input:focus {
    outline: none !important;
    border-color: var(--emerald) !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15) !important;
}

.u-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    border-radius: 0.65rem;
    font-size: 0.7rem;
    border: 1px solid;
}

.u-badge-emerald { background: rgba(16,185,129,.12); color: #6ee7b7; border-color: rgba(16,185,129,.28); }
.u-badge-sky { background: rgba(14,165,233,.12); color: #7dd3fc; border-color: rgba(14,165,233,.28); }
.u-badge-amber { background: rgba(245,158,11,.12); color: #fcd34d; border-color: rgba(245,158,11,.28); }
.u-badge-slate { background: rgba(100,116,139,.15); color: #cbd5e1; border-color: rgba(100,116,139,.3); }
.u-badge-rose { background: rgba(244,63,94,.12); color: #fda4af; border-color: rgba(244,63,94,.28); }
.u-badge-violet { background: rgba(139,92,246,.12); color: #c4b5fd; border-color: rgba(139,92,246,.28); }

/* ---------- Auth ---------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    color: var(--text-soft);
}

.auth-card {
    width: 100%;
    max-width: 26.5rem;
}

.auth-panel {
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(51, 65, 85, 0.9);
    border-radius: 1.4rem;
    padding: 1.75rem 1.5rem;
    box-shadow:
        0 30px 80px -40px rgba(0, 0, 0, 0.9),
        0 0 0 1px rgba(16, 185, 129, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(18px);
}

@media (min-width: 640px) {
    .auth-panel { padding: 2rem; }
}

.auth-steps {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    margin-bottom: 1.35rem;
}

.auth-steps i {
    display: block;
    width: 2.1rem;
    height: 0.28rem;
    border-radius: 9999px;
    background: #334155;
    transition: background 0.25s ease, box-shadow 0.25s ease;
}

.auth-steps i.on {
    background: var(--emerald);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.55);
}

.auth-alert {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    border-radius: 0.95rem;
    padding: 0.85rem 1rem;
    margin-bottom: 1.15rem;
    font-size: 0.875rem;
}

.auth-alert-error {
    background: rgba(248, 113, 113, 0.08);
    border: 1px solid rgba(248, 113, 113, 0.28);
    color: #fca5a5;
}

.auth-alert-ok {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.28);
    color: #6ee7b7;
}

/* ---------- Motion ---------- */
.fade-in {
    animation: fadeIn 0.4s ease both;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.stagger > * {
    animation: fadeIn 0.45s ease both;
}
.stagger > *:nth-child(1) { animation-delay: 0.04s; }
.stagger > *:nth-child(2) { animation-delay: 0.09s; }
.stagger > *:nth-child(3) { animation-delay: 0.14s; }
.stagger > *:nth-child(4) { animation-delay: 0.19s; }
.stagger > *:nth-child(5) { animation-delay: 0.24s; }
.stagger > *:nth-child(6) { animation-delay: 0.29s; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .brand-mark::after { animation: none; }
    .live-pill span { animation: none; }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: #1e293b; border-radius: 9999px; }
::-webkit-scrollbar-thumb:hover { background: #334155; }

/* ---------- Table polish ---------- */
.u-table th {
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--faint);
    background: rgba(30, 41, 59, 0.35);
}

.u-table tr {
    transition: background 0.15s ease;
}

.u-table tbody tr:hover {
    background: rgba(30, 41, 59, 0.35);
}

/* ---------- Key card hover glow ---------- */
.key-card {
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.key-card:hover {
    border-color: rgba(16, 185, 129, 0.35);
    transform: translateY(-3px);
    box-shadow: 0 18px 40px -24px rgba(16, 185, 129, 0.45);
}

/* Focus visible for a11y */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid rgba(52, 211, 153, 0.7);
    outline-offset: 2px;
}
