/* =========================================================
   Meraton CRM – Custom Styles
   Primary: #d9151f  |  Stack: Bootstrap 5.3 + Bootstrap Icons
   ========================================================= */

/* ---------------------------------------------------------
   CSS Variables & Bootstrap Overrides
   --------------------------------------------------------- */
:root {
    --crm-primary:        #d9151f;
    --crm-primary-dark:   #b01018;
    --crm-primary-light:  #f8d0d2;
    --crm-sidebar-width:  260px;
    --crm-sidebar-bg:     #1e2330;
    --crm-sidebar-text:   #b8bfd0;
    --crm-sidebar-active: #ffffff;
    --crm-topbar-height:  56px;
    --bs-primary:         #d9151f;
    --bs-primary-rgb:     217, 21, 31;
    --bs-link-color:      #d9151f;
    --bs-link-hover-color:#b01018;
}

[data-bs-theme="dark"] {
    --crm-sidebar-bg:    #13161e;
    --crm-sidebar-text:  #9aa0b4;
    --bs-body-bg:        #1a1d27;
    --bs-body-color:     #d0d3df;
    --bs-border-color:   #2e3347;
    --bs-card-bg:        #222636;
}

/* Override Bootstrap primary buttons */
.btn-primary {
    --bs-btn-bg:             var(--crm-primary);
    --bs-btn-border-color:   var(--crm-primary);
    --bs-btn-hover-bg:       var(--crm-primary-dark);
    --bs-btn-hover-border-color: var(--crm-primary-dark);
    --bs-btn-active-bg:      var(--crm-primary-dark);
    --bs-btn-active-border-color: var(--crm-primary-dark);
    --bs-btn-focus-shadow-rgb: 217, 21, 31;
}

.btn-outline-primary {
    --bs-btn-color:          var(--crm-primary);
    --bs-btn-border-color:   var(--crm-primary);
    --bs-btn-hover-bg:       var(--crm-primary);
    --bs-btn-hover-border-color: var(--crm-primary);
    --bs-btn-active-bg:      var(--crm-primary);
    --bs-btn-active-border-color: var(--crm-primary);
}

.text-primary   { color: var(--crm-primary) !important; }
.bg-primary     { background-color: var(--crm-primary) !important; }
.border-primary { border-color: var(--crm-primary) !important; }
.badge.bg-primary { background-color: var(--crm-primary) !important; }

a { color: var(--crm-primary); }
a:hover { color: var(--crm-primary-dark); }

/* ---------------------------------------------------------
   Layout – Sidebar + Main
   --------------------------------------------------------- */
body {
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar */
#sidebar {
    width: var(--crm-sidebar-width);
    min-width: var(--crm-sidebar-width);
    height: 100vh;
    position: sticky;
    top: 0;
    background-color: var(--crm-sidebar-bg);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1040;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

#sidebar .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.07);
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.01em;
    flex-shrink: 0;
}

#sidebar .sidebar-brand .brand-icon {
    width: 32px;
    height: 32px;
    background-color: var(--crm-primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #fff;
    flex-shrink: 0;
}

#sidebar .sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
}

#sidebar .nav-section-title {
    padding: 0.6rem 1.25rem 0.25rem;
    font-size: 0.675rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.3);
}

#sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 1.25rem;
    color: var(--crm-sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: 0;
    transition: color 0.15s, background 0.15s;
    white-space: nowrap;
}

#sidebar .nav-link i {
    font-size: 1rem;
    width: 1.1rem;
    text-align: center;
    flex-shrink: 0;
}

#sidebar .nav-link:hover {
    color: #fff;
    background-color: rgba(255,255,255,0.06);
}

#sidebar .nav-link.active {
    color: var(--crm-sidebar-active);
    background-color: var(--crm-primary);
}

#sidebar .nav-link.active:hover {
    background-color: var(--crm-primary-dark);
}

/* Main content area */
#crm-content {
    min-height: 100vh;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Topbar */
.crm-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background-color: var(--bs-body-bg, #fff);
}

/* ---------------------------------------------------------
   Responsive – mobile sidebar
   --------------------------------------------------------- */
@media (max-width: 991.98px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        transform: translateX(calc(-1 * var(--crm-sidebar-width)));
    }

    #sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.25);
    }

    #sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 1039;
    }

    #sidebar-overlay.show {
        display: block;
    }
}

/* ---------------------------------------------------------
   Avatars
   --------------------------------------------------------- */
.avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.avatar-lg {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.6rem;
    flex-shrink: 0;
}

.avatar-initials {
    background-color: var(--crm-primary);
    color: #fff;
    user-select: none;
}

/* ---------------------------------------------------------
   Stat Cards (Dashboard)
   --------------------------------------------------------- */
.stat-card {
    border: none;
    border-radius: 0.75rem;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    cursor: default;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.1) !important;
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-card .stat-label {
    font-size: 0.825rem;
    color: var(--bs-secondary-color, #6c757d);
}

/* ---------------------------------------------------------
   Note Cards (Timeline)
   --------------------------------------------------------- */
.note-card {
    border-left: 3px solid var(--crm-primary);
    border-radius: 0 0.5rem 0.5rem 0;
    transition: box-shadow 0.15s;
}

.note-card:hover {
    box-shadow: 0 2px 12px rgba(0,0,0,0.08) !important;
}

.note-card .note-meta {
    font-size: 0.8rem;
    color: var(--bs-secondary-color, #6c757d);
}

.note-card .note-body {
    white-space: pre-wrap;
    word-break: break-word;
}

.note-card .note-actions {
    opacity: 0;
    transition: opacity 0.15s;
}

.note-card:hover .note-actions {
    opacity: 1;
}

/* Edit textarea inside note card */
.note-edit-area {
    display: none;
}

.note-edit-area.active {
    display: block;
}

/* ---------------------------------------------------------
   File Drop Zone
   --------------------------------------------------------- */
.file-drop-zone {
    border: 2px dashed var(--bs-border-color, #dee2e6);
    border-radius: 0.75rem;
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
    color: var(--bs-secondary-color, #6c757d);
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
    border-color: var(--crm-primary);
    background-color: var(--crm-primary-light);
    color: var(--crm-primary);
}

[data-bs-theme="dark"] .file-drop-zone:hover,
[data-bs-theme="dark"] .file-drop-zone.drag-over {
    background-color: rgba(217, 21, 31, 0.12);
}

.file-drop-zone .drop-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
}

.file-drop-zone input[type="file"] {
    display: none;
}

/* File list items */
.file-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--bs-border-color, #dee2e6);
    margin-bottom: 0.4rem;
    background: var(--bs-body-bg, #fff);
    transition: background 0.15s;
}

.file-item:hover {
    background: var(--bs-tertiary-bg, #f8f9fa);
}

.file-item .file-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    color: var(--crm-primary);
}

.file-item .file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.875rem;
}

.file-item .file-size {
    font-size: 0.75rem;
    color: var(--bs-secondary-color, #6c757d);
    flex-shrink: 0;
}

/* ---------------------------------------------------------
   Auth Layout
   --------------------------------------------------------- */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bs-body-bg, #f5f6fa);
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    border: none;
    border-radius: 1rem;
    box-shadow: 0 4px 32px rgba(0,0,0,0.1);
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
    font-weight: 700;
    font-size: 1.3rem;
    color: var(--bs-body-color);
}

.auth-logo .brand-icon {
    width: 40px;
    height: 40px;
    background-color: var(--crm-primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    color: #fff;
}

/* ---------------------------------------------------------
   Table Enhancements
   --------------------------------------------------------- */
.table-hover tbody tr {
    cursor: default;
}

.table th {
    font-weight: 600;
    font-size: 0.825rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

/* ---------------------------------------------------------
   Page Header
   --------------------------------------------------------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
}

/* ---------------------------------------------------------
   Badges & Tags
   --------------------------------------------------------- */
.tag-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.55rem;
    border-radius: 20px;
    font-size: 0.775rem;
    font-weight: 500;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
}

.tag-badge:hover {
    opacity: 0.85;
    color: #fff;
}

/* ---------------------------------------------------------
   Expiry / Status Badges
   --------------------------------------------------------- */
.badge-expiry-ok      { background-color: #198754; }
.badge-expiry-warning { background-color: #fd7e14; }
.badge-expiry-danger  { background-color: #dc3545; }

/* ---------------------------------------------------------
   Activity Log
   --------------------------------------------------------- */
.log-action-badge {
    font-family: monospace;
    font-size: 0.75rem;
}

/* ---------------------------------------------------------
   Color Swatch (Tag editor)
   --------------------------------------------------------- */
.color-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.15);
    display: inline-block;
    flex-shrink: 0;
    vertical-align: middle;
}

/* ---------------------------------------------------------
   Permissions Grid (Groups editor)
   --------------------------------------------------------- */
.permission-module-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--bs-secondary-color, #6c757d);
    margin-bottom: 0.4rem;
}

/* ---------------------------------------------------------
   Upload progress bar (inline)
   --------------------------------------------------------- */
.upload-progress {
    display: none;
}

.upload-progress.active {
    display: block;
}

/* ---------------------------------------------------------
   Scrollbar (Webkit)
   --------------------------------------------------------- */
#sidebar::-webkit-scrollbar {
    width: 4px;
}

#sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

/* ---------------------------------------------------------
   Misc Utilities
   --------------------------------------------------------- */
.cursor-pointer { cursor: pointer; }
.min-w-0        { min-width: 0; }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-hover {
    transition: box-shadow 0.15s;
}

.card-hover:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.1) !important;
}

/* Focus ring using primary color */
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 0.25rem rgba(217, 21, 31, 0.2);
}

/* Dark mode card */
[data-bs-theme="dark"] .card {
    border-color: var(--bs-border-color);
}

[data-bs-theme="dark"] .file-item {
    border-color: var(--bs-border-color);
}

/* Fade-in animation for new list items */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.animate-in {
    animation: fadeInDown 0.2s ease forwards;
}

/* ---------------------------------------------------------
   Dark Mode – Table & Badge Overrides
   --------------------------------------------------------- */

/* Überfällige Zeilen */
[data-bs-theme="dark"] .table-danger {
    --bs-table-bg:           rgba(220, 53, 69, 0.18);
    --bs-table-border-color: rgba(220, 53, 69, 0.28);
    --bs-table-color:        #f8d7da;
    --bs-table-striped-bg:   rgba(220, 53, 69, 0.22);
    --bs-table-hover-bg:     rgba(220, 53, 69, 0.25);
}

/* Summen-/Footer-Zeile */
[data-bs-theme="dark"] .table-light {
    --bs-table-bg:           rgba(255, 255, 255, 0.05);
    --bs-table-border-color: var(--bs-border-color);
    --bs-table-color:        var(--bs-body-color);
}

/* Sekundäre "Ghost"-Badges (Intervall, Typ) */
[data-bs-theme="dark"] .badge.bg-secondary.bg-opacity-25 {
    background-color: rgba(150, 160, 180, 0.2) !important;
    color: #c8cfe0 !important;
}

/* Warning-Badge (Status "Offen") im Dark Mode */
[data-bs-theme="dark"] .badge.bg-warning {
    background-color: #e8a000 !important;
    color: #1a1a1a !important;
}

/* Overdue-Text */
[data-bs-theme="dark"] .text-danger {
    color: #f07070 !important;
}

/* Firmen-/Kontakt-Links in der Tabelle */
[data-bs-theme="dark"] .table td a.text-decoration-none {
    color: #8ab4f8;
}
[data-bs-theme="dark"] .table td a.text-decoration-none:hover {
    color: #aecbfa;
}

/* Geplante (is_future) Tabellenzeilen */
.opacity-60 { opacity: 0.6; }
