/* ─── Reset ─────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* ─── Global page loader ─────────────────────────── */
.page-loader {
    position: fixed;
    inset: 0;
    background: var(--bg-main);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.page-loader.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loader-spinner {
    width: 32px;
    height: 32px;
    border: 2.5px solid #e5e7eb;
    border-top-color: #9ca3af;
    border-radius: 50%;
    animation: loaderSpin 0.7s linear infinite;
}

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

.loader-brand {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: "Inter", sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.01em;
    white-space: nowrap;
}

/* ─── Design tokens ──────────────────────────────── */
:root {
    --primary-color: #151718;
    --primary-hover: #2d3135;
    --text-main: #111827;
    --text-muted: #6b7280;
    --text-on-primary: #ffffff;
    --bg-main: #f3f4f6;
    --bg-card: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.92);
    --status-success-bg: #ecfdf5;
    --status-success-text: #059669;
    --status-warning-bg: #fff7ed;
    --status-warning-text: #c2410c;
    --border-color: #e5e7eb;
    --border-focus: #151718;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md:
        0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg:
        0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
    --shadow-xl: 0 20px 40px -8px rgba(0, 0, 0, 0.18);
    --radius-sm: 2px;
    --radius-md: 4px;
    --radius-lg: 6px;
    --radius-full: 9999px;
    --transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    --input-height: 46px;
}

/* ─── Base ───────────────────────────────────────── */
html,
body {
    margin: 0;
    padding: 0;
    font-family: "Inter", sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
h5 {
    color: var(--text-main);
    font-weight: 700;
    margin: 0;
}

/* ─── Layout ─────────────────────────────────────── */
.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 40px 28px 60px;
}

.container-sm {
    max-width: 580px;
    margin: 0 auto;
    padding: 40px 28px 60px;
}

.container-fluid {
    padding: 32px 28px 60px;
}

/* ─── Page header (shared across all pages) ──────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 32px;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 3px;
    line-height: 1.2;
}

.page-header-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0;
}

/* ─── Card ───────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    padding: 28px;
}

/* ─── Buttons ────────────────────────────────────── */
.btn {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 18px;
    height: 40px;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
    white-space: nowrap;
    line-height: 1;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-primary {
    background: var(--primary-color);
    color: var(--text-on-primary);
    border-color: var(--primary-color);
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(21, 23, 24, 0.28);
}

.btn-outline {
    background: var(--bg-card);
    color: var(--text-main);
    border-color: var(--border-color);
}
.btn-outline:hover {
    background: var(--bg-main);
    border-color: #9ca3af;
}

.btn-sm {
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
}

.btn-full {
    width: 100%;
    height: 46px;
    font-size: 15px;
    border-radius: var(--radius-md);
}

.btn-danger {
    background: #dc2626;
    color: #fff;
    border-color: #dc2626;
}
.btn-danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}

/* ─── Unified form field ─────────────────────────── */
/* Every control inside .input-group gets identical treatment */
.input-group {
    margin-bottom: 18px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 6px;
}

.input-group input,
.input-group select,
.input-group textarea,
.form-control {
    width: 100%;
    height: var(--input-height);
    padding: 0 14px;
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-color);
    background: var(--bg-card);
    font-family: inherit;
    font-size: 14px;
    color: var(--text-main);
    transition: var(--transition);
    appearance: none;
    -webkit-appearance: none;
    display: block;
}

.input-group textarea {
    height: auto;
    padding: 12px 14px;
    resize: vertical;
    min-height: 100px;
}

/* Custom chevron for <select> */
.input-group select,
select.form-control {
    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='%236b7280' 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 12px center;
    padding-right: 38px;
    cursor: pointer;
}

.input-group input:focus,
.input-group select:focus,
.input-group textarea:focus,
.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(21, 23, 24, 0.1);
    background: #fff;
}

.input-group input::placeholder,
.input-group textarea::placeholder {
    color: #b0b7c3;
}

.input-note {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 5px;
    line-height: 1.5;
}

/* Label optional tag */
.label-optional {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
}

/* ─── Badges ─────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    line-height: 1.4;
}

.badge-success {
    background: var(--status-success-bg);
    color: var(--status-success-text);
}
.badge-warning {
    background: var(--status-warning-bg);
    color: var(--status-warning-text);
}
.badge-inactive {
    background: #f3f4f6;
    color: #6b7280;
}

/* ─── Alert / flash messages ─────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    border: 1px solid;
    line-height: 1.5;
}
.alert-error {
    background: #fef2f2;
    color: #b91c1c;
    border-color: #fecaca;
}
.alert-success {
    background: var(--status-success-bg);
    color: var(--status-success-text);
    border-color: #a7f3d0;
}

/* ─── Modal ──────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--bg-card);
    padding: 36px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 420px;
    border: 1px solid var(--border-color);
    animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-content h2 {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 6px;
}

.modal-content p {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0 0 20px;
    line-height: 1.5;
}

.modal-btn-full {
    width: 100%;
    margin-top: 4px;
}

/* ─── Confirm modal (dynamic, replaces native confirm()) ── */
.confirm-modal {
    text-align: center;
}

.confirm-modal h2,
.confirm-modal p {
    text-align: center;
}

.confirm-modal-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 18px;
}

.confirm-modal-icon svg {
    width: 24px;
    height: 24px;
}

.confirm-modal-icon[data-variant="danger"] {
    background: #fef2f2;
    color: #dc2626;
}

.confirm-modal-icon[data-variant="warning"] {
    background: var(--status-warning-bg);
    color: var(--status-warning-text);
}

.confirm-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
}

.confirm-modal-actions .btn {
    flex: 1;
}

/* ─── Toast notification ─────────────────────────── */
.notification-toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 5000;
    background: var(--bg-card);
    color: var(--text-main);
    padding: 14px 20px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateX(calc(100% + 24px));
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}
.notification-toast.active {
    transform: translateX(0);
}

.notification-icon-container {
    width: 30px;
    height: 30px;
    background: var(--bg-main);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.notification-icon {
    width: 18px;
    height: 18px;
    color: var(--text-main);
}

/* ─── Back link ──────────────────────────────────── */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    margin-bottom: 8px;
    transition: var(--transition);
}

.back-link svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}
.back-link:hover {
    color: var(--text-main);
}

/* ─── Utility ────────────────────────────────────── */
.hidden {
    display: none !important;
}

.text-muted {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0;
}

/* ─── Profile page ──────────────────────────────── */
.profile-header {
    display: flex;
    align-items: center;
    gap: 18px;
    margin: 8px 0 28px;
    flex-wrap: wrap;
}

.profile-avatar-lg {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: -0.02em;
}

.profile-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    margin: 0 0 10px;
}

/* Device link inside table cell */
.device-link {
    color: inherit;
    text-decoration: none;
    transition: var(--transition);
}
.device-link:hover {
    text-decoration: underline;
}

/* Alert spacing */
.alert-mb {
    margin-bottom: 24px;
}

/* ─── Responsive ─────────────────────────────────── */
@media (max-width: 640px) {
    .container,
    .container-sm {
        padding: 20px 16px 48px;
    }

    .container-fluid {
        padding: 20px 16px 48px;
    }

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

    .card {
        padding: 20px;
    }

    .modal-content {
        padding: 28px 22px;
    }

    .notification-toast {
        left: 12px;
        right: 12px;
        min-width: 0;
        top: auto;
        bottom: 16px;
        transform: translateY(calc(100% + 20px));
    }
    .notification-toast.active {
        transform: translateY(0);
    }
}
