/* ==========================================================================
   G-Loca CRM — design system
   Simple, lisible : texte assez grand, contrastes nets, peu de fioritures.
   ========================================================================== */

:root {
    /* ink family — text, chrome, sidebar */
    --ink: #1b2438;
    --ink-soft: #4d5875;
    --ink-faint: #6b7490;

    /* surfaces */
    --paper: #ffffff;
    --ground: #eef0eb;
    --line: #d5d9cd;
    --sidebar: #1b2438;
    --sidebar-line: #303a54;

    /* accent */
    --accent: #96652c;
    --accent-deep: #744e20;
    --accent-tint: #f7efe2;

    /* semantic */
    --success: #3f6b4a;
    --success-tint: #eaf1ea;
    --danger: #a13d2e;
    --danger-tint: #fbebe7;
    --warning: #9c7a1f;
    --warning-tint: #faf3df;
    --info: #3c5872;
    --info-tint: #edf2f5;

    --radius: 8px;
    --radius-sm: 6px;

    --font-display: Arial, Helvetica, sans-serif;
    --font-body: Arial, Helvetica, sans-serif;
    --font-data: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

/* ==========================================================================
   Base
   ========================================================================== */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.55;
    font-variant-numeric: tabular-nums;
}

a {
    color: var(--accent-deep);
    text-decoration: none;
}

a:hover {
    color: var(--accent);
    text-decoration: underline;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==========================================================================
   Shell & navigation
   ========================================================================== */

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

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    background: var(--sidebar);
    color: #fff;
    padding: 22px 16px 18px;
    display: flex;
    flex-direction: column;
    z-index: 1030;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: inherit;
    padding: 0 8px;
}

.brand:hover {
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--accent-tint);
    color: var(--accent-deep);
    display: grid;
    place-items: center;
    font: 700 18px var(--font-display);
    flex-shrink: 0;
}

.brand strong {
    display: block;
    font: 700 16px var(--font-display);
    line-height: 1.2;
}

.brand small {
    display: block;
    margin-top: 2px;
    color: #a9b1cf;
    font-size: 13px;
}

.side-nav {
    margin-top: 30px;
}

.nav-label {
    margin: 22px 10px 8px;
    color: #9aa3c0;
    font-size: 13px;
    font-weight: 700;
}

.side-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #c4c9dd;
    padding: 10px 10px;
    margin: 2px 0;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 15px;
    border-left: 3px solid transparent;
}

.side-nav a:hover {
    background: #232d47;
    color: #fff;
    text-decoration: none;
}

.side-nav a.active {
    background: #232d47;
    color: #fff;
    font-weight: 600;
    border-left-color: var(--accent);
}

.nav-icon {
    width: 25px;
    height: 25px;
    border: 1px solid #454f6c;
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    font: 700 12px var(--font-data);
    flex-shrink: 0;
}

.active .nav-icon {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid var(--sidebar-line);
    padding: 16px 8px 0;
}

.user-chip {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 0;
    color: inherit;
    text-decoration: none;
    border-radius: var(--radius-sm);
    padding: 6px;
    margin: -6px;
}

.user-chip:hover {
    background: #232d47;
}

.user-chip > span {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #2a3453;
    color: #d3d8ea;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.user-chip div {
    min-width: 0;
}

.user-chip strong,
.user-chip small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-chip strong {
    font-size: 14px;
}

.user-chip small {
    font-size: 13px;
    color: #a2aac6;
}

.logout-link {
    display: block;
    color: #a2aac6;
    margin-top: 14px;
    font-size: 13px;
}

.mobile-header {
    display: none;
}

.main-content {
    margin-left: 260px;
    padding: 36px 44px 64px;
    max-width: 1600px;
}

/* ==========================================================================
   Page header
   ========================================================================== */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 28px;
}

.page-eyebrow {
    font-size: 13px;
    color: var(--accent-deep);
    font-weight: 700;
    margin: 0 0 6px;
}

.page-title {
    font: 700 28px/1.2 var(--font-display);
    margin: 0;
    text-wrap: balance;
}

.page-subtitle {
    color: var(--ink-soft);
    margin: 8px 0 0;
    max-width: 640px;
    font-size: 16px;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 15px;
    padding: .6rem 1rem;
}

.btn-sm {
    padding: .38rem .7rem;
    font-size: 13px;
    border-radius: var(--radius-sm);
}

.btn-primary {
    --bs-btn-bg: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-bg: var(--accent-deep);
    --bs-btn-hover-border-color: var(--accent-deep);
}

.btn-dark {
    --bs-btn-bg: var(--ink);
    --bs-btn-border-color: var(--ink);
}

.btn-outline-primary {
    --bs-btn-color: var(--accent-deep);
    --bs-btn-border-color: #cbb290;
    --bs-btn-hover-bg: var(--accent-tint);
    --bs-btn-hover-color: var(--accent-deep);
    --bs-btn-hover-border-color: var(--accent);
}

.btn-outline-secondary {
    --bs-btn-color: var(--ink-soft);
    --bs-btn-border-color: #c7cabd;
}

.btn-outline-danger {
    --bs-btn-color: var(--danger);
    --bs-btn-border-color: #d9b3ab;
    --bs-btn-hover-bg: var(--danger-tint);
    --bs-btn-hover-color: var(--danger);
    --bs-btn-hover-border-color: var(--danger);
}

.btn-link {
    font-weight: 600;
    text-decoration: none;
}

.link-btn {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: pointer;
}

/* ==========================================================================
   Panels, forms, tables
   ========================================================================== */

.panel,
.card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.card {
    --bs-card-border-color: var(--line);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--line);
}

.panel-title {
    font: 700 17px var(--font-display);
    margin: 0;
}

.panel-link {
    font-size: 14px;
    font-weight: 600;
}

.filter-panel {
    padding: 16px;
    margin-bottom: 16px;
}

.form-control,
.form-select {
    min-height: 44px;
    border-color: #c7cbbd;
    border-radius: var(--radius-sm);
    font-size: 15px;
    background-color: #fff;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-tint);
}

.form-label,
label.required {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.form-text {
    font-size: 13px;
    color: var(--ink-soft);
}

.table-panel {
    overflow: hidden;
}

.table-responsive {
    border-radius: var(--radius);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: var(--accent-tint);
    margin: 0;
    font-size: 15px;
}

.table > :not(caption) > * > * {
    padding: 14px 20px;
    border-bottom-color: var(--line);
}

.table thead th {
    background: var(--ground);
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    border-bottom: 1px solid var(--line);
}

.table tbody {
    vertical-align: middle;
}

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

.table-title {
    color: var(--ink);
    font-weight: 600;
}

.table-meta {
    display: block;
    color: var(--ink-faint);
    font: 13px var(--font-data);
    margin-top: 3px;
}

.empty-row {
    text-align: center !important;
    color: var(--ink-faint);
    padding: 40px !important;
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
    font: 600 13px var(--font-body);
    padding: .38em .65em;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}

.text-bg-secondary {
    background: var(--ground) !important;
    color: var(--ink-soft) !important;
    border-color: var(--line) !important;
}

.text-bg-primary {
    background: var(--accent-tint) !important;
    color: var(--accent-deep) !important;
    border-color: #d9c19a !important;
}

.text-bg-success {
    background: var(--success-tint) !important;
    color: var(--success) !important;
    border-color: #b9d1bd !important;
}

.text-bg-info {
    background: var(--info-tint) !important;
    color: var(--info) !important;
    border-color: #bccbd6 !important;
}

.badge-priority-HIGH,
.badge-priority-CRITICAL {
    background: var(--danger-tint);
    color: var(--danger);
    border-color: #e3b9b1;
}

.badge-priority-MEDIUM {
    background: var(--warning-tint);
    color: var(--warning);
    border-color: #e3d19d;
}

.badge-priority-LOW {
    background: var(--ground);
    color: var(--ink-soft);
    border-color: var(--line);
}

/* ==========================================================================
   Dashboard
   ========================================================================== */

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.metric {
    padding: 18px 20px;
}

.metric-label {
    color: var(--ink-soft);
    font-size: 14px;
    font-weight: 600;
}

.metric-value {
    display: block;
    font: 700 30px/1 var(--font-display);
    margin-top: 14px;
}

.metric-foot {
    display: block;
    color: var(--ink-faint);
    font-size: 13px;
    margin-top: 8px;
}

.metric.alerting {
    border-color: var(--danger);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.activity-row {
    display: flex;
    gap: 12px;
    padding: 15px 20px;
    border-bottom: 1px solid var(--line);
}

.activity-row:last-child {
    border: 0;
}

.activity-date {
    color: var(--ink-faint);
    font: 13px var(--font-data);
    white-space: nowrap;
    margin-left: auto;
}

.activity-body {
    min-width: 0;
}

.activity-body strong {
    display: block;
    font-size: 15px;
}

.activity-body small {
    display: block;
    color: var(--ink-soft);
    margin-top: 3px;
    font-size: 14px;
}

.activity-marker {
    width: 9px;
    height: 9px;
    margin-top: 6px;
    border-radius: 50%;
    background: var(--accent);
    flex: 0 0 auto;
}

/* ==========================================================================
   Agency detail
   ========================================================================== */

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
}

.detail-stack {
    display: grid;
    gap: 16px;
}

.identity-panel {
    padding: 22px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.info-grid > div {
    overflow-wrap: break-word;
}

.info-label {
    display: block;
    color: var(--ink-faint);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
}

.notes {
    border-top: 1px solid var(--line);
    margin-top: 20px;
    padding-top: 18px;
    color: var(--ink);
    line-height: 1.6;
    overflow-wrap: break-word;
}

.notes .info-label {
    margin-bottom: 8px;
}

.social-links {
    border-top: 1px solid var(--line);
    margin-top: 20px;
    padding-top: 18px;
}

.social-links-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.social-links-list a {
    display: inline-block;
    padding: 5px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
}

.social-links-list a:hover {
    background: var(--surface-soft, #f4f4f5);
}

.item-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
}

.item-row:last-child {
    border: 0;
}

.item-main {
    flex: 1;
    min-width: 0;
}

.item-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.timeline {
    padding: 8px 20px 4px;
}

.timeline-item {
    position: relative;
    border-left: 2px solid var(--line);
    padding: 9px 0 18px 18px;
    margin-left: 4px;
}

.timeline-item:before {
    content: "";
    position: absolute;
    left: -5px;
    top: 14px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

/* ==========================================================================
   Forms
   ========================================================================== */

.form-shell {
    max-width: 1120px;
}

.form-card {
    padding: 26px;
}

.form-card > div {
    margin-bottom: 18px;
}

.form-card textarea {
    min-height: 120px;
}

.form-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 16px;
    align-items: start;
}

.form-main {
    display: grid;
    gap: 16px;
}

.form-section {
    padding: 24px;
}

.form-section-heading {
    border-bottom: 1px solid var(--line);
    padding-bottom: 14px;
    margin-bottom: 20px;
}

.form-section-heading h2 {
    font: 700 17px var(--font-display);
    margin: 0;
}

.form-section-heading p {
    font-size: 14px;
    color: var(--ink-soft);
    margin: 5px 0 0;
}

.form-section-heading.compact {
    padding-bottom: 14px;
    margin-bottom: 17px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 16px;
}

.form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.field-span-2 {
    grid-column: span 2;
}

.field-span-3 {
    grid-column: span 3;
}

.form-section .mb-3 {
    margin-bottom: 18px !important;
}

.form-section textarea {
    resize: vertical;
}

.form-side hr {
    border-color: var(--line);
    margin: 8px 0 20px;
}

.form-mini-title {
    font-size: 14px;
    color: var(--ink);
    font-weight: 700;
    margin-bottom: 16px;
}

.sticky-section {
    position: sticky;
    top: 24px;
}

.form-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 20px;
    flex-wrap: wrap;
}

.pagination {
    justify-content: flex-end;
    gap: 4px;
}

.page-link {
    border-radius: var(--radius-sm) !important;
    border-color: var(--line);
    color: var(--ink-soft);
    font-size: 14px;
}

.page-item.disabled .page-link {
    background: var(--ground);
    color: var(--ink-faint);
}

.app-alert {
    margin-bottom: 20px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    border-left: 4px solid var(--ink);
}

.alert-success.app-alert {
    border-left-color: var(--success);
}

.alert-danger.app-alert {
    border-left-color: var(--danger);
}

/* ==========================================================================
   Bulk selection & row actions
   ========================================================================== */

.checkbox-col {
    width: 36px;
}

.bulk-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    color: var(--ink-soft);
}

.bulk-select-all {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 600;
    color: var(--ink);
}

.bulk-bar .btn {
    margin-left: auto;
}

.new-contact-picker {
    display: flex;
    gap: 8px;
}

.new-contact-picker .form-select {
    min-width: 220px;
}

.row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
}

.log-meta {
    margin: 8px 0 0;
    padding: 10px 12px;
    background: var(--ground);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font: 13px var(--font-data);
    color: var(--ink-soft);
    max-width: 340px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ==========================================================================
   Login
   ========================================================================== */

.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--ground);
}

.login-aside {
    background: var(--sidebar);
    color: #fff;
    padding: 48px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.login-aside h1 {
    max-width: 500px;
    font: 700 40px/1.2 var(--font-display);
    text-wrap: balance;
}

.login-aside p {
    color: #b9bfd6;
    max-width: 450px;
    font-size: 16px;
    line-height: 1.6;
}

.login-main {
    display: grid;
    place-items: center;
    padding: 30px;
}

.login-card {
    width: min(420px, 100%);
}

.login-card h2 {
    font: 700 26px var(--font-display);
}

.login-kicker {
    color: var(--accent-deep);
    font-size: 13px;
    font-weight: 700;
}

.login-card .form-control {
    min-height: 46px;
}

.login-card .btn {
    min-height: 46px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1100px) {
    .metrics { grid-template-columns: repeat(2, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
    .main-content { padding: 30px; }
    .form-layout { grid-template-columns: 1fr; }
    .sticky-section { position: static; }
    .form-side { grid-row: 1; }
}

@media (max-width: 767px) {
    .sidebar { display: none; }
    .mobile-header {
        height: 60px;
        padding: 0 16px;
        background: var(--sidebar);
        color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    .mobile-header .brand { padding: 0; }
    .mobile-header .brand-mark { width: 32px; height: 32px; }
    .menu-button {
        background: transparent;
        border: 1px solid var(--sidebar-line);
        border-radius: var(--radius-sm);
        color: #fff;
        padding: 8px 12px;
        font-size: 14px;
    }
    .main-content { margin: 0; padding: 24px 16px 44px; }
    .side-nav.mobile { margin: 0; }
    .side-nav.mobile a { color: var(--ink); }
    .page-header { display: block; }
    .header-actions { margin-top: 16px; }
    .page-title { font-size: 24px; }
    .metrics { grid-template-columns: 1fr 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .table > :not(caption) > * > * { padding: 12px; }
    .form-section { padding: 18px; }
    .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
    .field-span-2, .field-span-3 { grid-column: span 1; }
    .login-page { grid-template-columns: 1fr; }
    .login-aside { display: none; }
    .login-main { min-height: 100vh; }
    .hide-mobile { display: none; }
}

@media (max-width: 420px) {
    .metrics { grid-template-columns: 1fr; }
}

.user-avatar {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--ink);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
}

.maintenance-screen {
    max-width: 480px;
    margin: 15vh auto;
    text-align: center;
    padding: 32px;
}

.danger-zone {
    margin-top: 20px;
    border-color: var(--danger);
}

.danger-zone h2 {
    color: var(--danger);
}

.totp-setup {
    display: flex;
    gap: 24px;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.totp-qr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px;
    background: #fff;
}

.totp-secret {
    display: inline-block;
    margin: 6px 0;
    padding: 5px 10px;
    background: var(--ground);
    border-radius: var(--radius-sm);
    font-size: 15px;
}

/* ==========================================================================
   Visite guidée (driver.js)
   ========================================================================== */

.tour-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    z-index: 1000;
}

.tour-fab:hover {
    background: var(--accent-deep);
}

.driver-popover {
    font-family: var(--font-body);
    border-radius: var(--radius);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.driver-popover-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
}

.driver-popover-description {
    font-size: 14px;
    color: var(--ink-soft);
    line-height: 1.5;
}

.driver-popover-footer .driver-popover-footer-btn {
    border-radius: var(--radius-sm);
    text-shadow: none;
    font-size: 13px;
}

.driver-popover-next-btn,
.driver-popover-done-btn {
    background: var(--accent) !important;
    color: #fff !important;
    border: 1px solid var(--accent) !important;
}

.driver-popover-prev-btn {
    color: var(--ink) !important;
}

.driver-popover-progress-text {
    font-size: 12px;
    color: var(--ink-faint);
}
