/* Modern mobile-first visual refresh */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --background-color: #f4f6fb;
    --surface-color: #ffffff;
    --surface-alt: #f7f9fc;
    --text-color: #1f2937;
    --muted-color: #6b7280;
    --border-color: #e2e8f0;
    --shadow-soft: 0 18px 45px rgba(15, 23, 42, 0.12);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    background: var(--background-color);
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
}

body.dashboard-body {
    padding: 0;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.12) 0%, rgba(99, 102, 241, 0.03) 45%, var(--background-color) 100%);
    min-height: 100vh;
}

body.dashboard-body > .d-flex {
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

body.dashboard-body .flex-grow-1 {
    min-width: 0;
    width: 100%;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-color);
    font-weight: 600;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color .2s ease;
}

a:hover,
a:focus {
    color: var(--primary-hover);
}

img {
    max-width: 100%;
    height: auto;
}

/* Buttons */
.btn {
    border-radius: 999px;
    font-weight: 600;
    letter-spacing: .01em;
    transition: transform .2s ease, box-shadow .2s ease, background-color .2s ease, color .2s ease;
    white-space: nowrap;
}

.btn:not(.btn-link) {
    padding: 0.65rem 1.2rem;
}

.btn-sm {
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
}

.btn-primary {
    background: var(--primary-gradient);
    border: none;
    color: #fff;
    box-shadow: 0 12px 30px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--primary-gradient);
    box-shadow: 0 18px 38px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.btn-outline-primary {
    color: var(--primary-color);
    border-color: rgba(99, 102, 241, 0.35);
    background: rgba(99, 102, 241, 0.08);
}

.btn-outline-primary:hover {
    color: #fff;
    background: var(--primary-gradient);
    border-color: transparent;
}

.btn-outline-secondary,
.btn-outline-info,
.btn-outline-danger,
.btn-outline-success,
.btn-outline-warning {
    background: rgba(15, 23, 42, 0.03);
    border-color: rgba(15, 23, 42, 0.12);
    color: var(--muted-color);
}

.btn-outline-danger {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.35);
    background: rgba(248, 113, 113, 0.08);
}

.btn-outline-success {
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.35);
    background: rgba(16, 185, 129, 0.08);
}

.btn-outline-warning {
    color: #f59e0b;
    border-color: rgba(245, 158, 11, 0.35);
    background: rgba(245, 158, 11, 0.12);
}

.btn-link {
    color: var(--primary-color);
    padding-left: 0;
    padding-right: 0;
    box-shadow: none;
}

.btn-link:hover {
    color: var(--primary-hover);
    transform: none;
}

/* Forms */
.form-control,
.form-select,
textarea {
    border-radius: 0.95rem;
    padding: 0.75rem 1rem;
    border: 1px solid rgba(99, 102, 241, 0.18);
    background: var(--surface-alt);
    transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

.form-control:focus,
.form-select:focus,
textarea:focus {
    border-color: var(--primary-color);
    background: #fff;
    box-shadow: 0 0 0 .2rem rgba(99, 102, 241, 0.15);
}

.input-group {
    width: 100%;
}

.filter-actions {
    min-width: 150px;
}

.filter-actions .btn {
    width: 100%;
}

.form-label {
    font-weight: 600;
    color: var(--muted-color);
}

/* Cards */
.card {
    background-color: var(--surface-color);
    border: none;
    border-radius: 1.25rem;
    box-shadow: var(--shadow-soft);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.card:last-child {
    margin-bottom: 0;
}

.card .card-header {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.08) 0%, rgba(99, 102, 241, 0) 100%);
    border-bottom: 1px solid rgba(226, 232, 240, 0.7);
    font-weight: 600;
    color: var(--text-color);
}

.card .card-body {
    padding: 1.5rem;
}

.card.text-center .card-body {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
}

.card-title {
    color: var(--text-color);
    font-weight: 600;
}

.card-text {
    color: var(--muted-color);
}

/* Lists & badges */
.list-group {
    border-radius: 1.25rem;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

.list-group-item {
    border: none;
    padding: 0.85rem 1rem;
    color: var(--muted-color);
}

.list-group-item + .list-group-item {
    border-top: 1px solid rgba(226, 232, 240, 0.7);
}

.badge {
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    font-weight: 600;
}

.alert {
    border-radius: 1.1rem;
}

/* Tables */
.table {
    border-collapse: collapse;
    width: 100%;
    margin-top: 1.5rem;
    background: var(--surface-color);
    border-radius: 1.25rem;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}

.table th,
.table td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid rgba(226, 232, 240, 0.7);
}

.table th {
    background: rgba(99, 102, 241, 0.08);
    color: var(--text-color);
    font-weight: 600;
}

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

.table.table-bordered {
    border: none;
}

.table.table-bordered th,
.table.table-bordered td {
    border-right: 1px solid rgba(226, 232, 240, 0.7);
}

.table.table-bordered th:last-child,
.table.table-bordered td:last-child {
    border-right: none;
}

/* Calendar tables */
.calendar-table {
    margin-top: 0;
}

.calendar-table th,
.calendar-table td {
    text-align: center;
}

.calendar-table td {
    padding: 0;
}

.calendar-table td .btn {
    margin: 0.3rem;
}

/* Dashboard layout */
body.dashboard-body {
    margin: 0;
}

main.dashboard-main {
    flex-grow: 1;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

#sidebar {
    width: 240px;
    min-height: 100vh;
    --bs-offcanvas-width: 240px;
    background: var(--surface-color) !important;
    border-right: 1px solid rgba(226, 232, 240, 0.7);
    box-shadow: inset -1px 0 0 rgba(226, 232, 240, 0.7);
}

#sidebar .offcanvas-body {
    padding: 1.5rem 1.25rem;
}

#sidebar .sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.1) 0%, rgba(99, 102, 241, 0) 100%);
    border-bottom: 1px solid rgba(226, 232, 240, 0.7);
}

#sidebar .sidebar-greeting {
    font-weight: 600;
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#sidebar .nav-link {
    color: var(--text-color);
    padding: 0.6rem 0.9rem;
    margin: 0.15rem 0.4rem;
    border-radius: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 500;
    transition: background .2s ease, color .2s ease, transform .2s ease;
}

#sidebar .nav-link i {
    font-size: 1.1rem;
    color: var(--primary-color);
}

#sidebar .nav-link:hover {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary-hover);
    transform: translateX(4px);
}

#sidebar .nav-link.active {
    background: var(--primary-gradient);
    color: #fff;
    box-shadow: 0 12px 30px rgba(99, 102, 241, 0.3);
}

#sidebar .nav-link.active i {
    color: #fff;
}

.dashboard-body .navbar {
    position: sticky;
    top: 0;
    z-index: 1025;
    padding: 0.75rem 1rem;
    background: var(--surface-color);
    border-bottom: 1px solid rgba(226, 232, 240, 0.7);
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

.dashboard-body .navbar .navbar-brand {
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--text-color);
}

.dashboard-body .navbar .btn {
    border-radius: 999px;
    border-color: rgba(99, 102, 241, 0.25);
    color: var(--primary-color);
}

.dashboard-body .navbar .btn:hover {
    background: rgba(99, 102, 241, 0.08);
    color: var(--primary-hover);
}

.card-body.d-flex {
    gap: 1.25rem;
}

.card-body.d-flex > .d-flex {
    gap: 0.75rem;
}

/* Authentication pages */
body.auth-body {
    margin: 0;
    padding: clamp(1.5rem, 4vw, 3rem);
    background: var(--background-color);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    background: var(--surface-color);
    border-radius: 1.5rem;
    box-shadow: var(--shadow-soft);
    padding: clamp(2rem, 5vw, 2.75rem);
    width: min(420px, 100%);
}

.auth-card .form-control,
.auth-card .form-select,
.auth-card textarea {
    background: var(--surface-alt);
}

.auth-card .btn {
    width: 100%;
}

.auth-footer {
    margin-top: 1.5rem;
    color: var(--muted-color);
    text-align: center;
}

.auth-footer a {
    color: var(--primary-color);
    font-weight: 600;
}

/* Responsive tweaks */
@media (max-width: 992px) {
    #sidebar {
        width: min(320px, 90vw);
        --bs-offcanvas-width: min(320px, 90vw);
    }
}

@media (max-width: 768px) {
    body {
        padding: 0;
    }

    .dashboard-main {
        padding: calc(1.75rem + env(safe-area-inset-top)) 1.5rem calc(3.25rem + env(safe-area-inset-bottom)) !important;
        background: var(--surface-color);
        border-radius: 32px 32px 0 0;
        margin-top: -1.5rem;
        box-shadow: 0 -18px 40px rgba(15, 23, 42, 0.12);
        min-height: calc(100vh - 4rem);
    }

    .card {
        margin-bottom: 1.25rem;
        border-radius: 1.5rem;
    }

    .card .card-body {
        padding: 1.35rem;
    }

    .card-body.d-flex {
        flex-direction: column;
        align-items: stretch !important;
    }

    .card-body.d-flex > .d-flex {
        width: 100%;
        flex-wrap: wrap;
        justify-content: stretch;
    }

    .card-body.d-flex > .d-flex .btn {
        flex: 1 1 calc(50% - 0.75rem);
        min-width: calc(50% - 0.75rem);
        text-align: center;
    }

    .list-group {
        box-shadow: none;
        background: transparent;
    }

    .list-group-item {
        border-radius: 1rem;
        margin-bottom: 0.5rem;
        background: rgba(99, 102, 241, 0.08);
    }

    .table {
        margin-top: 1.25rem;
        box-shadow: 0 15px 35px rgba(15, 23, 42, 0.12);
    }

    .table th,
    .table td {
        padding: 0.85rem;
    }

    .table.table-bordered th,
    .table.table-bordered td {
        border-right: none;
    }

    .modal-dialog {
        margin: 1.75rem;
    }

    .modal-content {
        border-radius: 1.5rem;
        border: none;
        box-shadow: 0 25px 55px rgba(15, 23, 42, 0.35);
    }

    .modal-header,
    .modal-footer {
        border: none;
        padding: 1.25rem 1.5rem;
    }

    .modal-body {
        padding: 1.5rem;
    }

    #sidebar {
        background: linear-gradient(180deg, #4f46e5 0%, #6366f1 100%) !important;
        color: #fff;
        border-right: none;
        box-shadow: 0 20px 45px rgba(79, 70, 229, 0.3);
    }

    #sidebar .sidebar-header {
        background: transparent;
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    }

    #sidebar .sidebar-greeting {
        color: #fff;
    }

    #sidebar .btn-close {
        filter: invert(1);
        opacity: 0.8;
    }

    #sidebar .nav-link {
        color: rgba(255, 255, 255, 0.85);
    }

    #sidebar .nav-link i {
        color: rgba(255, 255, 255, 0.9);
    }

    #sidebar .nav-link:hover {
        background: rgba(255, 255, 255, 0.18);
        color: #fff;
        transform: translateX(6px);
    }

    #sidebar .nav-link.active {
        background: rgba(255, 255, 255, 0.25);
        color: #fff;
        box-shadow: none;
    }

    #sidebar .nav-link.active i {
        color: #fff;
    }

    .dashboard-body .navbar {
        background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%) !important;
        border-bottom: none !important;
        box-shadow: 0 20px 45px rgba(79, 70, 229, 0.4);
    }

    .dashboard-body .navbar .navbar-brand,
    .dashboard-body .navbar .navbar-brand:hover {
        color: #fff;
    }

    .dashboard-body .navbar .btn {
        color: #fff;
        border-color: rgba(255, 255, 255, 0.35);
    }

    .dashboard-body .navbar .btn:hover {
        background: rgba(255, 255, 255, 0.18);
    }

    .form-control,
    .form-select,
    textarea {
        background: rgba(99, 102, 241, 0.08);
        border: 1px solid rgba(99, 102, 241, 0.2);
    }

    .form-control:focus,
    .form-select:focus,
    textarea:focus {
        background: #fff;
    }

    .form-label {
        color: var(--muted-color);
    }

    .calendar-table {
        box-shadow: none;
        border-radius: 1.5rem;
        overflow: hidden;
        background: transparent;
    }

    .calendar-table thead tr th {
        background: transparent;
        color: rgba(255, 255, 255, 0.85);
        text-transform: uppercase;
        font-size: 0.75rem;
        letter-spacing: 0.08em;
    }

    .calendar-table td {
        padding: 0.45rem;
        border-bottom: none;
    }

    .calendar-table td .btn {
        border-radius: 1.15rem;
        padding: 1rem 0.75rem;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        font-size: 0.95rem;
        background: rgba(255, 255, 255, 0.12);
        color: #fff;
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
    }

    .calendar-table td .btn.btn-light {
        background: rgba(99, 102, 241, 0.16);
        color: var(--text-color);
        box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.18);
    }

    .calendar-table td .btn.btn-outline-light {
        background: rgba(255, 255, 255, 0.1);
        color: rgba(255, 255, 255, 0.75);
        border: none;
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
    }

    .calendar-table td .btn.btn-primary {
        background: rgba(99, 102, 241, 1);
        color: #fff;
        box-shadow: 0 15px 30px rgba(79, 70, 229, 0.45);
    }

    .calendar-table td .btn .badge {
        align-self: center;
        background: rgba(255, 255, 255, 0.35) !important;
    }

    .list-unstyled li {
        background: rgba(99, 102, 241, 0.08);
        border-radius: 1rem;
        padding: 0.85rem 1rem;
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 576px) {
    table {
        display: block;
        overflow-x: auto;
    }

    .modal-dialog {
        margin: 1.25rem;
    }

    .dashboard-main .row.g-3 > [class*='col-'] {
        width: 100%;
    }

    .dashboard-main .nav-tabs {
        flex-wrap: wrap;
        gap: 0.5rem;
        border-bottom: none;
    }

    .dashboard-main .nav-tabs .nav-item {
        flex: 1 1 100%;
        text-align: center;
    }

    .dashboard-main .nav-tabs .nav-link {
        width: 100%;
        border-radius: 999px !important;
    }

    .dashboard-body .input-group {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .dashboard-body .input-group > * {
        border-radius: 1rem !important;
    }

    .dashboard-body .input-group > :not(:first-child) {
        margin-left: 0;
    }

    .dashboard-body .input-group > .form-control,
    .dashboard-body .input-group > .form-select,
    .dashboard-body .input-group > .form-floating,
    .dashboard-body .input-group > .form-control:focus,
    .dashboard-body .input-group > .form-select:focus {
        flex: 1 1 100%;
        min-width: 0;
    }

    .dashboard-body .input-group > .btn {
        flex: 1 1 calc(50% - 0.25rem);
        width: auto;
    }

    .dashboard-body .input-group > .btn:only-of-type {
        flex-basis: 100%;
    }

    .btn:not(.btn-link) {
        width: 100%;
    }

    .card-body.d-flex > .d-flex .btn {
        width: auto;
    }
}

@media (min-width: 1200px) {
    .dashboard-main {
        max-width: 1140px;
        margin-left: auto;
        margin-right: auto;
    }
}
