/* ============================================
   WattWatch — Custom Styles
   Glassmorphism · Animations · Dark Mode
   ============================================ */

/* ---- CSS Custom Properties ---- */
:root {
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
    --glass-shadow: 0 8px 32px rgba(31, 38, 135, 0.08);
    --sidebar-width: 260px;
    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;
    --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark {
    --glass-bg: rgba(30, 30, 40, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* ---- Base ---- */
* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    transition: background-color var(--transition-base), color var(--transition-base);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}
.dark ::-webkit-scrollbar-thumb {
    background: #334155;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    z-index: 40;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    transition: transform var(--transition-slow);
    display: flex;
    flex-direction: column;
}

.sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 2rem 1rem 0.5rem;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 0.75rem;
    margin-bottom: 2.5rem;
}

.sidebar-logo-icon {
    font-size: 1.6rem;
    line-height: 1;
}

.sidebar-logo-text {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.9rem;
    border-radius: 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #64748b;
    text-decoration: none;
    transition: all var(--transition-fast);
}

.nav-link:hover {
    background: rgba(59, 130, 246, 0.08);
    color: #3b82f6;
}

.nav-link.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(99, 102, 241, 0.08));
    color: #3b82f6;
    font-weight: 600;
}

.dark .nav-link {
    color: #94a3b8;
}

.dark .nav-link:hover {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.dark .nav-link.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(99, 102, 241, 0.12));
    color: #60a5fa;
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 0.75rem;
    text-align: center;
}



/* ============================================
   Mobile Header
   ============================================ */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    z-index: 30;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    align-items: center;
    padding: 0 1rem;
    gap: 0.75rem;
}

.hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #64748b;
    padding: 0.25rem;
    border-radius: 0.5rem;
    transition: background var(--transition-fast);
}

.hamburger-btn:hover {
    background: rgba(0,0,0,0.05);
}

.dark .hamburger-btn {
    color: #94a3b8;
}

.mobile-header-title {
    font-weight: 700;
    font-size: 1.1rem;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    transition: opacity var(--transition-base);
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: 2.5rem 3rem;
    transition: margin-left var(--transition-slow);
}

/* ============================================
   Glass Card
   ============================================ */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    box-shadow: var(--glass-shadow);
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.glass-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(31, 38, 135, 0.12);
}

.dark .glass-card:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

/* ============================================
   Progress Bar
   ============================================ */
.progress-track {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.dark .progress-track {
    background: #1e293b;
}

.progress-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    background: linear-gradient(90deg, #3b82f6, #6366f1);
}

.progress-fill.warning {
    background: linear-gradient(90deg, #f59e0b, #ef4444);
}

.progress-fill.danger {
    background: linear-gradient(90deg, #ef4444, #dc2626);
}

/* ============================================
   Status Badge
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-safe {
    background: rgba(34, 197, 94, 0.12);
    color: #16a34a;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.12);
    color: #dc2626;
}

.dark .badge-safe {
    background: rgba(34, 197, 94, 0.18);
    color: #4ade80;
}

.dark .badge-warning {
    background: rgba(245, 158, 11, 0.18);
    color: #fbbf24;
}

.dark .badge-danger {
    background: rgba(239, 68, 68, 0.18);
    color: #f87171;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: 0.65rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all var(--transition-fast);
    outline: none;
    text-decoration: none;
}

.btn:focus-visible {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.4);
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(59, 130, 246, 0.08);
    color: #3b82f6;
}

.btn-secondary:hover {
    background: rgba(59, 130, 246, 0.15);
}

.dark .btn-secondary {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.btn-ghost {
    background: transparent;
    color: #64748b;
}

.btn-ghost:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #334155;
}

.dark .btn-ghost {
    color: #94a3b8;
}

.dark .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: translateY(-1px);
}

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

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

/* ============================================
   Modal
   ============================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

.modal-backdrop.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    width: 100%;
    max-width: 460px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.dark .modal-content {
    background: #1e293b;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem 0.75rem;
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #0f172a;
}

.dark .modal-title {
    color: #f1f5f9;
}

.modal-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    padding: 0.25rem;
    border-radius: 0.5rem;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.modal-close-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #475569;
}

.dark .modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #cbd5e1;
}

.modal-body {
    padding: 0.5rem 1.5rem 1.5rem;
}

/* ============================================
   Form Elements
   ============================================ */
.form-group {
    margin-bottom: 1.15rem;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 0.4rem;
}

.dark .form-label {
    color: #94a3b8;
}

.form-input {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 0.6rem;
    font-size: 0.9rem;
    font-family: inherit;
    background: white;
    color: #0f172a;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}

.form-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.dark .form-input {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}

.dark .form-input:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
}

.form-hint {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 0.3rem;
}

.form-error {
    font-size: 0.75rem;
    color: #ef4444;
    margin-top: 0.3rem;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 0.85rem 1rem;
    border-radius: 0.75rem;
    background: white;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    border: 1px solid #e2e8f0;
    animation: toastSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.875rem;
    line-height: 1.4;
    color: #334155;
}

.dark .toast {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    color: #e2e8f0;
}

.toast-exit {
    animation: toastSlideOut 0.25s ease forwards;
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-top: 1px;
}

.toast-success .toast-icon {
    color: #22c55e;
}

.toast-error .toast-icon {
    color: #ef4444;
}

.toast-info .toast-icon {
    color: #3b82f6;
}

/* ============================================
   Dropdown
   ============================================ */
.dropdown-wrapper {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.35rem);
    min-width: 180px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    z-index: 20;
    padding: 0.35rem;
    animation: dropdownSlideIn 0.15s ease;
    opacity: 1;
}

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

.dark .dropdown-menu {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: none;
    background: none;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-family: inherit;
    color: #475569;
    cursor: pointer;
    transition: background var(--transition-fast);
    text-align: left;
}

.dropdown-item:hover {
    background: rgba(59, 130, 246, 0.08);
    color: #3b82f6;
}

.dark .dropdown-item {
    color: #cbd5e1;
}

.dark .dropdown-item:hover {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

/* ============================================
   Table
   ============================================ */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table thead th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    border-bottom: 1px solid #e2e8f0;
}

.dark .data-table thead th {
    border-bottom-color: #1e293b;
}

.data-table tbody td {
    padding: 0.85rem 1rem;
    font-size: 0.875rem;
    color: #475569;
    border-bottom: 1px solid #f1f5f9;
}

.dark .data-table tbody td {
    color: #cbd5e1;
    border-bottom-color: rgba(255,255,255,0.04);
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: rgba(59, 130, 246, 0.03);
}

.dark .data-table tbody tr:hover {
    background: rgba(59, 130, 246, 0.06);
}

/* ============================================
   Pagination
   ============================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin-top: 1.5rem;
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    border: 1px solid #e2e8f0;
    background: white;
    color: #64748b;
    border-radius: 0.5rem;
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.page-btn:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.08);
    border-color: #3b82f6;
    color: #3b82f6;
}

.page-btn.active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

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

.dark .page-btn {
    background: #0f172a;
    border-color: #334155;
    color: #94a3b8;
}

.dark .page-btn.active {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

/* ============================================
   Skeleton Loading
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 0.5rem;
}

.dark .skeleton {
    background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
    background-size: 200% 100%;
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1.25rem;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 0.5rem;
}

.dark .empty-state-title {
    color: #94a3b8;
}

.empty-state-text {
    font-size: 0.9rem;
    color: #94a3b8;
    margin-bottom: 1.5rem;
    max-width: 320px;
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes cardFadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card-animate {
    animation: cardFadeIn 0.35s ease both;
}

/* ============================================
   Page Header
   ============================================ */
.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: #0f172a;
}

.dark .page-title {
    color: #f1f5f9;
}

.page-subtitle {
    font-size: 0.95rem;
    color: #94a3b8;
    margin-top: 0.3rem;
}

/* ============================================
   Toggle Switch
   ============================================ */
.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toggle {
    position: relative;
    width: 48px;
    height: 26px;
    background: #cbd5e1;
    border-radius: 999px;
    cursor: pointer;
    border: none;
    padding: 0;
    transition: background var(--transition-fast);
}

.toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition-fast);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle.active {
    background: #3b82f6;
}

.toggle.active::after {
    transform: translateX(22px);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 1024px) {
    .main-content {
        padding: 2rem;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-header {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding: 1.25rem;
        padding-top: calc(56px + 1.25rem);
    }

    .toast-container {
        left: 1rem;
        right: 1rem;
        max-width: none;
    }

    /* Responsive table: horizontal scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .data-table {
        min-width: 600px;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 1rem;
        padding-top: calc(56px + 1rem);
    }

    .page-title {
        font-size: 1.4rem;
    }

    .modal-content {
        border-radius: 0.75rem;
    }
}
