:root {
    --app-bg: #f4f6f8;
    --app-surface: #ffffff;
    --app-border: #d9e0e7;
    --app-text: #1f2937;
    --app-muted: #637083;
    --app-primary: #0d6efd;
    --app-danger: #dc3545;
    --app-warning: #ffc107;
    --app-success: #198754;
    --app-secondary: #6c757d;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    background: var(--app-bg);
    color: var(--app-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    margin: 0;
    min-height: 100%;
}

a {
    color: var(--app-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Fallbacks for the Bootstrap classes used by the app. Bootstrap CDN remains the primary UI layer. */
.container {
    margin-inline: auto;
    max-width: 1140px;
    padding-inline: 1rem;
    width: 100%;
}

.row {
    display: flex;
    flex-wrap: wrap;
    margin-inline: -.5rem;
}

.row > * {
    padding-inline: .5rem;
    width: 100%;
}

.g-2 {
    gap: .5rem;
}

.g-3 {
    row-gap: 1rem;
}

.g-4 {
    row-gap: 1.5rem;
}

.d-none {
    display: none !important;
}

.d-flex {
    display: flex !important;
}

.d-grid {
    display: grid !important;
}

.flex-wrap {
    flex-wrap: wrap !important;
}

.align-items-center {
    align-items: center !important;
}

.align-items-start {
    align-items: flex-start !important;
}

.justify-content-between {
    justify-content: space-between !important;
}

.justify-content-center {
    justify-content: center !important;
}

.gap-2 {
    gap: .5rem !important;
}

.gap-3 {
    gap: 1rem !important;
}

.mb-0 {
    margin-bottom: 0 !important;
}

.mb-2 {
    margin-bottom: .5rem !important;
}

.mb-1 {
    margin-bottom: .25rem !important;
}

.mb-3 {
    margin-bottom: 1rem !important;
}

.mb-4 {
    margin-bottom: 1.5rem !important;
}

.mt-3 {
    margin-top: 1rem !important;
}

.mt-4 {
    margin-top: 1.5rem !important;
}

.py-5 {
    padding-block: 3rem !important;
}

.me-auto {
    margin-right: auto !important;
}

.p-3 {
    padding: 1rem !important;
}

.text-secondary {
    color: var(--app-muted) !important;
}

.text-end {
    text-align: end !important;
}

.fw-semibold {
    font-weight: 600 !important;
}

.small {
    font-size: .875rem !important;
}

.h3 {
    font-size: calc(1.3rem + .6vw);
}

.h4 {
    font-size: calc(1.275rem + .3vw);
}

.h5 {
    font-size: 1.25rem;
}

.h6 {
    font-size: 1rem;
}

.navbar {
    align-items: center;
    display: flex;
    min-height: 64px;
    padding-block: .75rem;
}

.navbar .container {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
}

.navbar-brand {
    color: var(--app-text);
    font-size: 1.05rem;
    font-weight: 700;
    margin-right: 1rem;
}

.navbar-toggler {
    background: transparent;
    border: 1px solid var(--app-border);
    border-radius: .5rem;
    margin-left: auto;
    min-height: 44px;
    padding: .5rem .75rem;
}

.navbar-toggler-icon {
    display: inline-block;
    height: 1.25rem;
    position: relative;
    width: 1.5rem;
}

.navbar-toggler-icon::before {
    box-shadow: 0 .45rem 0 #333, 0 .9rem 0 #333;
    content: "";
    display: block;
    height: 2px;
    width: 1.5rem;
    background: #333;
}

.navbar-collapse {
    flex-basis: 100%;
    flex-grow: 1;
}

.collapse:not(.show) {
    display: none;
}

.navbar-nav {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    list-style: none;
    margin: .75rem 0;
    padding-left: 0;
}

.nav-link {
    border-radius: .5rem;
    color: #334155;
    display: block;
    padding: .65rem .75rem;
}

.nav-link.active,
.nav-link:hover {
    background: #eaf2ff;
    color: var(--app-primary);
    text-decoration: none;
}

.app-photo-grid,
.app-photo-preview-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

.app-audio-note-list {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

.app-audio-note-card audio {
    min-height: 44px;
}

.app-audio-recorder-panel {
    display: grid;
    gap: 1rem;
}

.app-audio-recorder-status-row {
    align-items: end;
    display: grid;
    gap: .75rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.app-audio-recorder-timer {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.app-audio-recorder-indicator {
    align-items: center;
    color: var(--app-danger);
    display: inline-flex;
    font-weight: 700;
    gap: .5rem;
}

.app-audio-recorder-dot {
    animation: appPulse 1.2s ease-in-out infinite;
    background: currentColor;
    border-radius: 999px;
    display: inline-block;
    height: .75rem;
    width: .75rem;
}

.app-audio-recorder-actions {
    display: grid;
    gap: .75rem;
    grid-template-columns: 1fr;
}

.app-audio-recorder-primary {
    min-height: 56px;
}

.app-photo-grid {
    align-items: start;
}

.app-photo-preview-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.app-photo-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app-photo-frame {
    align-items: center;
    background: #f8fafc;
    border-bottom: 1px solid var(--app-border);
    display: flex;
    justify-content: center;
    max-height: 320px;
    min-height: 220px;
    overflow: hidden;
    padding: 1rem;
}

.app-photo-thumb,
.app-photo-preview-image {
    background: #e9eef3;
    display: block;
    height: auto;
    margin: 0 auto;
    max-height: 320px;
    max-width: 100%;
    object-fit: contain;
    width: 100%;
}

.app-photo-preview-image {
    height: auto;
    max-height: 180px;
}

.app-photo-preview-card {
    margin: 0;
}

@media (min-width: 768px) {
    .app-photo-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1200px) {
    .app-photo-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.navbar-text {
    display: block;
    padding-block: .5rem;
}

.card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: .5rem;
}

.card-body {
    padding: 1rem;
}

.alert {
    border: 1px solid transparent;
    border-radius: .5rem;
    margin-bottom: 1rem;
    padding: 1rem;
}

.alert-danger {
    background: #f8d7da;
    border-color: #f1aeb5;
    color: #842029;
}

.alert-info {
    background: #cff4fc;
    border-color: #9eeaf9;
    color: #055160;
}

.alert-warning {
    background: #fff3cd;
    border-color: #ffecb5;
    color: #664d03;
}

.btn {
    align-items: center;
    border: 1px solid transparent;
    border-radius: .5rem;
    cursor: pointer;
    display: inline-flex;
    font-weight: 600;
    justify-content: center;
    line-height: 1.25;
    min-height: 44px;
    padding: .625rem 1rem;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

.btn-sm {
    min-height: 44px;
    padding: .55rem .85rem;
}

.btn-lg {
    min-height: 48px;
    padding: .75rem 1.1rem;
}

.btn-primary {
    background: var(--app-primary);
    border-color: var(--app-primary);
    color: #fff;
}

.btn-success {
    background: var(--app-success);
    border-color: var(--app-success);
    color: #fff;
}

.btn-danger {
    background: var(--app-danger);
    border-color: var(--app-danger);
    color: #fff;
}

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

.btn-outline-secondary {
    background: #fff;
    border-color: var(--app-border);
    color: #334155;
}

.btn-outline-danger {
    background: #fff;
    border-color: var(--app-danger);
    color: var(--app-danger);
}

.badge {
    border-radius: 999px;
    display: inline-block;
    font-size: .75rem;
    font-weight: 700;
    padding: .35em .65em;
}

.text-bg-primary {
    background: var(--app-primary) !important;
    color: #fff !important;
}

.text-bg-secondary {
    background: var(--app-secondary) !important;
    color: #fff !important;
}

.text-bg-warning {
    background: var(--app-warning) !important;
    color: #2b2100 !important;
}

.text-bg-success {
    background: var(--app-success) !important;
    color: #fff !important;
}

.text-bg-danger {
    background: var(--app-danger) !important;
    color: #fff !important;
}

.text-danger {
    color: var(--app-danger) !important;
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: .35rem;
}

.form-control,
.form-select {
    appearance: none;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: .5rem;
    color: var(--app-text);
    display: block;
    font: inherit;
    min-height: 44px;
    padding: .625rem .75rem;
    width: 100%;
}

.form-control:focus,
.form-select:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 .25rem rgba(13, 110, 253, .15);
    outline: 0;
}

textarea.form-control {
    min-height: 132px;
}

.form-check {
    align-items: flex-start;
    display: flex;
    gap: .5rem;
}

.form-check-input {
    height: 1.2rem;
    margin-top: .15rem;
    width: 1.2rem;
}

.table-responsive {
    overflow-x: auto;
    width: 100%;
}

.table {
    border-collapse: collapse;
    width: 100%;
}

.table th,
.table td {
    border-bottom: 1px solid var(--app-border);
    padding: .85rem;
    vertical-align: middle;
}

.table thead th {
    background: #f8fafc;
    color: #475569;
    font-size: .875rem;
    font-weight: 700;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.breadcrumb-item + .breadcrumb-item::before {
    color: var(--app-muted);
    content: "/";
    padding-right: .35rem;
}

.breadcrumb-item.active {
    color: var(--app-muted);
}

.bg-white {
    background: #fff !important;
}

.bg-light {
    background: #f8fafc !important;
}

.border {
    border: 1px solid var(--app-border) !important;
}

.border-bottom {
    border-bottom: 1px solid var(--app-border) !important;
}

.rounded-2 {
    border-radius: .5rem !important;
}

.w-100 {
    width: 100% !important;
}

.min-vh-100 {
    min-height: 100vh !important;
}

.app-navbar {
    box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}

.app-main {
    padding-block: 1rem 2rem;
}

.app-page-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.app-page-actions {
    display: grid;
    gap: .5rem;
}

.app-card {
    border-color: var(--app-border);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}

.app-card-body {
    padding: 1rem;
}

.app-muted-label {
    color: var(--app-muted);
    font-size: .875rem;
}

.app-mobile-list {
    display: grid;
    gap: .75rem;
}

.app-mobile-detail-list {
    display: grid;
    gap: .75rem;
}

.app-mobile-detail-item {
    border: 1px solid var(--app-border);
    border-radius: .5rem;
    padding: 1rem;
}

.app-mobile-detail-grid {
    display: grid;
    gap: .75rem;
}

.app-mobile-detail-meta {
    display: grid;
    gap: .5rem;
}

.app-customer-summary-grid {
    row-gap: .5rem;
}

.app-mobile-detail-actions {
    display: grid;
    gap: .5rem;
}

.app-agenda-mobile {
    display: grid;
    gap: .75rem;
}

.app-agenda-board {
    padding: 0;
}

.app-agenda-desktop-layout {
    display: grid;
    gap: 0;
    grid-template-columns: minmax(0, 1fr);
}

.app-agenda-desktop-layout.app-agenda-desktop-layout-weekend-open {
    grid-template-columns: minmax(0, 1fr) 240px;
}

.app-agenda-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.app-agenda-column {
    border-right: 1px solid var(--app-border);
    min-height: 320px;
}

.app-agenda-column:last-child {
    border-right: 0;
}

.app-agenda-column-current,
.app-agenda-day-card-current {
    background: #f8fbff;
}

.app-agenda-weekend {
    background: #f8fafc;
    border-left: 1px solid var(--app-border);
    display: block;
}

.app-agenda-weekend-header {
    align-items: center;
    background: #f1f5f9;
    border-bottom: 1px solid var(--app-border);
    display: flex;
    justify-content: space-between;
    padding: 1rem;
}

.app-agenda-weekend-body {
    display: grid;
    gap: .75rem;
    padding: 1rem;
}

.app-agenda-weekend-day {
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: .5rem;
    padding: .85rem;
}

.app-agenda-column-header {
    background: #f8fafc;
    border-bottom: 1px solid var(--app-border);
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 1;
}

.app-agenda-column-day {
    color: #475569;
    font-size: .875rem;
    font-weight: 700;
    text-transform: uppercase;
}

.app-agenda-column-date {
    font-size: 1rem;
    font-weight: 700;
}

.app-agenda-column-body,
.app-agenda-item-list {
    display: grid;
    gap: .75rem;
}

.app-agenda-column-body {
    align-content: start;
    padding: .85rem;
}

.app-agenda-item {
    background: #fff;
    border: 1px solid var(--app-border);
    border-left-width: 4px;
    border-radius: .5rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
    color: inherit;
    display: block;
    min-width: 0;
    padding: .85rem;
    text-decoration: none;
    width: 100%;
}

.app-agenda-item:hover {
    border-color: #bfd4ff;
    box-shadow: 0 4px 12px rgba(13, 110, 253, .08);
    text-decoration: none;
}

.app-agenda-item-plan {
    border-left-color: #64748b;
}

.app-agenda-item-visit {
    border-left-color: var(--app-primary);
}

.app-agenda-item-time {
    color: #475569;
    font-size: .875rem;
    font-weight: 700;
    margin-bottom: .35rem;
}

.app-agenda-empty {
    color: var(--app-muted);
    font-size: .875rem;
    padding-top: .25rem;
}

.app-agenda-item .badge {
    white-space: nowrap;
}

.app-agenda-weekend-trigger {
    max-width: 100%;
    white-space: nowrap;
}

.app-agenda-inline-link {
    color: var(--app-primary);
}

.app-agenda-legend {
    border: 1px solid transparent;
}

.app-agenda-legend-plan {
    background: #eef2f7;
    border-color: #cbd5e1;
    color: #334155;
}

.app-agenda-legend-visit {
    background: #eaf2ff;
    border-color: #bfd4ff;
    color: #0b5ed7;
}

.app-login-shell {
    min-height: 100vh;
}

.app-footer {
    color: var(--app-muted);
    font-size: .875rem;
    padding-block: 1rem;
}

@keyframes appPulse {
    0%, 100% {
        opacity: .35;
        transform: scale(.9);
    }

    50% {
        opacity: 1;
        transform: scale(1);
    }
}

@media (min-width: 576px) {
    .col-sm-10 {
        flex: 0 0 auto;
        width: 83.333333%;
    }

    .d-sm-flex {
        display: flex !important;
    }

    .justify-content-sm-end {
        justify-content: flex-end !important;
    }
}

@media (min-width: 768px) {
    .btn-sm {
        min-height: 38px;
        padding: .45rem .75rem;
    }

    .col-md-4 {
        flex: 0 0 auto;
        width: 33.333333%;
    }

    .col-md-6 {
        flex: 0 0 auto;
        width: 50%;
    }

    .col-md-7 {
        flex: 0 0 auto;
        width: 58.333333%;
    }

    .col-md-8 {
        flex: 0 0 auto;
        width: 66.666667%;
    }

    .d-md-none {
        display: none !important;
    }

    .d-md-block {
        display: block !important;
    }

    .app-main {
        padding-block: 1.5rem 2.5rem;
    }

    .app-page-header {
        align-items: center;
        flex-direction: row;
        justify-content: space-between;
        margin-bottom: 1.5rem;
    }

    .app-page-actions {
        align-items: center;
        display: flex;
        flex-direction: row;
    }

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

    .app-audio-recorder-actions {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 992px) {
    .mb-lg-0 {
        margin-bottom: 0 !important;
    }

    .col-lg-4 {
        flex: 0 0 auto;
        width: 33.333333%;
    }

    .col-lg-5 {
        flex: 0 0 auto;
        width: 41.666667%;
    }

    .col-lg-8 {
        flex: 0 0 auto;
        width: 66.666667%;
    }

    .navbar-expand-lg .navbar-toggler {
        display: none;
    }

    .navbar-expand-lg .navbar-collapse {
        align-items: center;
        display: flex !important;
        flex-basis: auto;
    }

    .navbar-expand-lg .navbar-nav {
        flex-direction: row;
        margin: 0;
    }

    .d-lg-flex {
        display: flex !important;
    }
}
