@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');

/* ===== CSS Variables (Premium Dark Mode Glassmorphism) ===== */
:root {
    --color-primary: #e11c24;
    --color-primary-dark: #b8171d;
    --color-primary-light: #f43f47;
    --color-bg: #000000;
    --color-surface: #111111;
    --color-surface-hover: #222222;
    --color-text: #ffffff;
    --color-text-secondary: #aaaaaa;
    --color-border: #333333;
    --color-success: #10b981;
    --color-error: #e11c24;
    --color-warning: #f59e0b;
    --sidebar-width: 260px;
    --header-height: 70px;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --transition: 0.2s ease-in-out;
    --glass-blur: none;
}

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

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

body {
    font-family: 'Poppins', sans-serif;
    color: var(--color-text);
    background: var(--color-bg);
    background-attachment: fixed;
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    color: var(--color-text);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
    box-shadow: 2px 0 30px rgba(0, 0, 0, 0.5);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-logo {
    height: 48px;
    width: auto;
    object-fit: contain;
}

.sidebar-title {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--color-text);
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--color-text);
    font-size: 20px;
    cursor: pointer;
    margin-left: auto;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    transition: all var(--transition);
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    width: 100%;
    text-align: left;
    margin-bottom: 4px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--color-text);
    border-color: rgba(255, 255, 255, 0.05);
    transform: translateX(4px);
}

.nav-item.active,
.nav-item:where(.active) {
    background: rgba(225, 28, 36, 0.1);
    border: 1px solid var(--color-primary);
    color: var(--color-primary-light);
    font-weight: 600;
}

.nav-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.nav-section {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.3);
    padding: 20px 16px 8px;
    letter-spacing: 1.5px;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn:hover {
    background: rgba(225, 28, 36, 0.15) !important;
    color: var(--color-error) !important;
    border-color: rgba(225, 28, 36, 0.3) !important;
}

/* ===== Main Content ===== */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--header-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.hamburger {
    display: none;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--color-border);
    font-size: 20px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    color: var(--color-text);
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text);
    flex: 1;
    letter-spacing: -0.3px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.connection-indicator {
    font-size: 14px;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.2));
}

.app-content {
    flex: 1;
    padding: 32px;
}

/* ===== Page ===== */
.page-header {
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.5px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* ===== Glassmorphism Cards ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.dash-card {
    display: flex;
    align-items: center;
    gap: 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    transition: all var(--transition);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.dash-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
}

.dash-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    background: var(--color-surface-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

.dash-card-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    color: var(--color-text);
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 2px 10px rgba(255, 255, 255, 0.05);
}

.dash-card-info h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text);
    letter-spacing: -0.3px;
}

.dash-card-info p {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-top: 4px;
}

/* ===== Maps Component ===== */
.map-placeholder {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0;
    box-shadow: var(--shadow);
    color: var(--color-text-secondary);
    min-height: 450px;
    display: block;
    position: relative;
    overflow: hidden;
}

/* ===== Form Cards ===== */
.form-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.form-card h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 12px;
    margin-bottom: 24px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-secondary);
    letter-spacing: 0.2px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    background: rgba(0, 0, 0, 0.2);
    color: var(--color-text);
    transition: all var(--transition);
    outline: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.form-input:focus {
    border-color: var(--color-primary);
    background: rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15), inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.form-input:disabled {
    background: rgba(255, 255, 255, 0.02);
    color: var(--color-text-secondary);
    border-color: rgba(255, 255, 255, 0.05);
    cursor: not-allowed;
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23cbd5e1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

select.form-input option {
    background: #1e293b;
    color: #f8fafc;
}

select.form-input option:checked,
select.form-input option:focus {
    background-color: var(--color-primary) !important;
    box-shadow: 0 0 10px 100px var(--color-primary) inset !important;
    color: #ffffff !important;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 16px;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(225, 28, 36, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(225, 28, 36, 0.4);
    background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--color-text);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.2);
}

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

.btn-sm {
    padding: 6px 14px;
    font-size: 14px;
}

/* ===== Data Tables ===== */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.data-table th {
    background: rgba(0, 0, 0, 0.2);
    color: var(--color-text-secondary);
    padding: 16px 20px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.data-table td {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 15px;
    color: var(--color-text);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text);
    border: 1px solid rgba(255, 255, 255, 0.05);
    letter-spacing: 0.3px;
}

.badge-active {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.2);
}

.badge-inactive {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.2);
}

/* ===== Login Specific ===== */
.login-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
}

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 48px 40px;
    box-shadow: var(--shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 40px;
}

.login-logo h1 {
    font-size: 32px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -1px;
}


.login-error {
    background: rgba(225, 28, 36, 0.15);
    border: 1px solid rgba(225, 28, 36, 0.3);
    color: #fca5a5;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(4px);
}

/* ===== Validation ===== */
.valid.modified:not([type=checkbox]) {
    outline: none;
    border-color: rgba(16, 185, 129, 0.5);
}

.invalid {
    outline: none;
    border-color: var(--color-error) !important;
    background: rgba(239, 68, 68, 0.05) !important;
}

.validation-message {
    color: #f87171;
    font-size: 13px;
    margin-top: 4px;
    display: block;
}

/* ===== Animations ===== */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

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

    .sidebar-close {
        display: block;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 90;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
    }

    .app-main {
        margin-left: 0;
    }

    .hamburger {
        display: block;
    }

    .app-content {
        padding: 20px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .page-header h1 {
        font-size: 24px;
    }
}

/* ===== Blazor Error UI (Global) ===== */
#blazor-error-ui {
    background: rgba(225, 28, 36, 0.95);
    backdrop-filter: blur(10px);
    bottom: auto !important;
    top: 0 !important;
    box-shadow: 0 4px 20px rgba(225, 28, 36, 0.4);
    color: #ffffff !important;
    display: none;
    left: 0;
    padding: 16px 24px;
    position: fixed;
    right: 0;
    width: 100%;
    z-index: 99999;
    text-align: center;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 2px solid #fff;
    animation: slideDown 0.4s ease-out;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 20px;
    transition: color 0.2s;
}

#blazor-error-ui .dismiss:hover {
    color: white;
}

#blazor-error-ui .reload {
    color: white;
    text-decoration: underline;
    margin-left: 12px;
    font-weight: 700;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ===== Toast/Alerts Global System ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
    /* Let clicks pass through container */
}

.toast-item {
    pointer-events: auto;
    /* Re-enable clicks on the toast itself */
    background: #1e1e24;
    color: #fff;
    border-radius: 8px;
    padding: 16px;
    width: 380px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    animation: slideInToast 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    position: relative;
    overflow: hidden;
    font-family: 'Inter', system-ui, sans-serif;
}

.toast-error {
    border-left: 6px solid #ff4b4b;
    background: rgba(45, 10, 10, 0.95);
    backdrop-filter: blur(10px);
}

.toast-error:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255, 75, 75, 0.05) 10px, rgba(255, 75, 75, 0.05) 20px);
    pointer-events: none;
}

.toast-success {
    border-left: 6px solid #4cd137;
}

.toast-info {
    border-left: 6px solid #0097e6;
}

.toast-warning {
    border-left: 6px solid #fbc531;
    color: #1a1a1a;
    background: #fff;
}

.toast-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.toast-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toast-content strong {
    font-size: 0.95rem;
    color: #ff4b4b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.toast-message {
    font-size: 0.85rem;
    line-height: 1.4;
    color: #e0e0e0;
    word-break: break-word;
}

.toast-warning .toast-message {
    color: #333;
}

.toast-close {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    padding: 0;
    font-size: 1.2rem;
    transition: color 0.1s ease;
}

.toast-close:hover {
    color: #fff;
}

.toast-error .toast-close:hover {
    color: #ff4b4b;
}

@keyframes slideInToast {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-shake {
    animation: slideInToast 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards, shakeAlert 0.5s cubic-bezier(.36, .07, .19, .97) both 0.3s;
}

@keyframes shakeAlert {

    10%,
    90% {
        transform: translate3d(-2px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(4px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-8px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(8px, 0, 0);
    }
}

/* ===== Sync Logs Modal ===== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1e1e24;
    width: 90%;
    max-width: 700px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #fff;
    font-weight: 600;
}

.close-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: #aaa;
    cursor: pointer;
    transition: color 0.15s;
}

.close-btn:hover {
    color: #fff;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

/* ===== Language Selector ===== */
.language-selector {
    margin-right: 12px;
}

.language-selector select {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: 12px;
    font-family: 'Poppins', sans-serif;
    cursor: pointer;
    appearance: auto;
}

.language-selector select:focus {
    outline: none;
    border-color: var(--color-primary);
}