/* components.css — Shared UI Components
 * Universelle Komponenten fuer alle CRM/Admin-Projekte
 * Setzt design-tokens.css voraus
 * ================================================ */


/* -------------------------------------------------------------------
   Header
   ------------------------------------------------------------------- */

.crm-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    height: var(--crm-header-h);
    padding: 0 1.25rem;
    background: var(--crm-surface);
    border-bottom: 1px solid var(--crm-border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .04);
}

.crm-header-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.crm-header-logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--crm-primary-text, var(--crm-primary));
}

.crm-header-logo-img {
    max-height: 32px;
    width: auto;
}

.crm-header-icon {
    vertical-align: middle;
}

.crm-header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-left: auto;
}

.crm-header-user-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    padding: 0.35rem 0.5rem;
    border-radius: var(--crm-radius);
    cursor: pointer;
    color: var(--crm-text);
    transition: background-color 0.15s;
}

.crm-header-user-btn:hover {
    background: var(--crm-surface-2);
}

.crm-header-user-name {
    font-size: 13px;
    color: var(--crm-text-muted);
}


/* -------------------------------------------------------------------
   Navigation
   ------------------------------------------------------------------- */

.crm-nav {
    display: flex;
    gap: 0.25rem;
    margin-left: 1.5rem;
}

.crm-nav-item {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    padding: 0.4rem 0.75rem;
    font-size: 13px;
    color: var(--crm-text-muted);
    border-radius: var(--crm-radius);
    transition: background-color 0.15s, color 0.15s;
    text-decoration: none;
}

.crm-nav-item:hover {
    background: var(--crm-surface-2);
    text-decoration: none;
    color: var(--crm-text);
}

.crm-nav-item.active {
    color: var(--crm-primary-text, var(--crm-primary));
    font-weight: 600;
    background: var(--crm-primary-light);
}


/* -------------------------------------------------------------------
   Main Content
   ------------------------------------------------------------------- */

.crm-main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem;
}


/* -------------------------------------------------------------------
   Toolbar
   ------------------------------------------------------------------- */

.crm-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.crm-page-title {
    font-size: 1.35rem;
    font-weight: 700;
}


/* -------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------- */

.crm-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    background: var(--crm-primary);
    color: var(--crm-on-primary, #fff);
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--crm-radius);
    border: none;
    cursor: pointer;
    transition: background-color 0.15s, box-shadow 0.15s;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.crm-btn:hover {
    background: var(--crm-primary-dark);
    text-decoration: none;
    color: var(--crm-on-primary, #fff);
}

.crm-btn:active {
    transform: translateY(1px);
}

.crm-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.crm-btn-ghost {
    background: transparent;
    border: 1px solid var(--crm-border);
    color: var(--crm-text);
}

.crm-btn-ghost:hover {
    background: var(--crm-surface-2);
    color: var(--crm-text);
}

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

.crm-btn-danger:hover {
    background: #dc2626;
}

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

.crm-btn-success:hover {
    background: #16a34a;
}

.crm-btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 12px;
}

.crm-btn-xs {
    padding: 0.2rem 0.4rem;
    font-size: 11px;
    border-radius: 4px;
}

.crm-btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0.3rem;
    border-radius: var(--crm-radius);
    color: var(--crm-text-muted);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.crm-btn-icon:hover {
    background: var(--crm-surface-2);
    color: var(--crm-text);
}


/* -------------------------------------------------------------------
   Forms
   ------------------------------------------------------------------- */

.crm-form-group {
    margin-bottom: 0.85rem;
}

.crm-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--crm-text-muted);
    margin-bottom: 0.3rem;
}

.crm-input,
.crm-select {
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    padding: 0.45rem 0.75rem;
    font-size: 14px;
    font-family: inherit;
    color: var(--crm-text);
    background: var(--crm-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.crm-input:focus,
.crm-select:focus {
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.crm-input::placeholder {
    color: var(--crm-text-muted);
    opacity: 0.7;
}

.crm-input:disabled,
.crm-select:disabled {
    background: var(--crm-surface-2);
    opacity: 0.7;
    cursor: not-allowed;
}

.crm-textarea {
    width: 100%;
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    padding: 0.45rem 0.75rem;
    font-size: 14px;
    font-family: inherit;
    color: var(--crm-text);
    background: var(--crm-surface);
    resize: vertical;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.crm-textarea:focus {
    border-color: var(--crm-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.crm-form-hint {
    display: block;
    font-size: 12px;
    color: var(--crm-text-muted);
    margin-top: 0.2rem;
}

.crm-form-row {
    display: flex;
    gap: 1rem;
}

.crm-form-row > * {
    flex: 1;
}

.crm-form-value {
    padding: 0.45rem 0;
    font-size: 14px;
}

.crm-checkbox-label {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    cursor: pointer;
    font-size: 14px;
}

.crm-checkbox-label input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
}

.crm-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.crm-form-error {
    color: var(--crm-danger);
    font-size: 12px;
    margin-top: 0.2rem;
}

.crm-input.error,
.crm-select.error,
.crm-textarea.error {
    border-color: var(--crm-danger);
}


/* -------------------------------------------------------------------
   Panels
   ------------------------------------------------------------------- */

.crm-panel {
    background: var(--crm-surface);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.crm-panel-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--crm-surface-2);
    padding: 0.75rem 1.25rem;
    margin: -1.25rem -1.25rem 1rem;
    border-radius: var(--crm-radius) var(--crm-radius) 0 0;
    cursor: pointer;
    user-select: none;
}

.crm-panel-title {
    font-size: 1rem;
    font-weight: 700;
    flex: 1;
}

.crm-panel-toggle {
    display: inline-block;
    color: var(--crm-text-muted);
    transition: transform 0.2s ease;
    font-size: 14px;
    line-height: 1;
}

.crm-panel-toggle::before {
    content: "\25BE"; /* Dreieck nach unten */
}

.crm-panel.collapsed .crm-panel-body {
    display: none;
}

.crm-panel.collapsed .crm-panel-toggle {
    transform: rotate(-90deg);
}

.crm-panel-body {
    /* Content container */
}


/* -------------------------------------------------------------------
   Status Tabs
   ------------------------------------------------------------------- */

.crm-status-tabs {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.crm-tab {
    padding: 0.4rem 0.85rem;
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    font-size: 13px;
    color: var(--crm-text-muted);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.crm-tab:hover {
    background: var(--crm-surface-2);
}

.crm-tab.active {
    background: var(--crm-primary);
    color: var(--crm-on-primary, #fff);
    border-color: var(--crm-primary);
}

.crm-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--crm-danger);
    color: #fff;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 700;
    margin-left: 4px;
    line-height: 1;
}

.crm-tab.active .crm-badge {
    background: rgba(255, 255, 255, .25);
}


/* -------------------------------------------------------------------
   Modals
   ------------------------------------------------------------------- */

.crm-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.crm-modal[hidden] {
    display: none;
}

.crm-modal-box {
    background: var(--crm-surface);
    border-radius: var(--crm-radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
    max-height: 90vh;
    overflow-y: auto;
}

.crm-modal-box--wide {
    max-width: 640px;
}

.crm-modal-box--narrow {
    max-width: 360px;
}

.crm-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.crm-modal-title {
    font-size: 1.1rem;
    font-weight: 700;
}

.crm-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0.3rem;
    border-radius: var(--crm-radius);
    color: var(--crm-text-muted);
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.crm-modal-close:hover {
    background: var(--crm-surface-2);
    color: var(--crm-text);
}

.crm-modal-body {
    /* Content container */
}

.crm-modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.25rem;
}


/* -------------------------------------------------------------------
   Tables
   ------------------------------------------------------------------- */

.crm-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.crm-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--crm-surface);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow);
    overflow: hidden;
}

.crm-table th {
    padding: 0.65rem 1rem;
    background: var(--crm-surface-2);
    border-bottom: 1px solid var(--crm-border);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--crm-text-muted);
    letter-spacing: 0.06em;
    text-align: left;
    white-space: nowrap;
}

.crm-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--crm-border);
    vertical-align: middle;
    font-size: 14px;
}

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

.crm-table tr:hover td {
    background: var(--crm-surface-2);
}

.crm-table td a {
    color: var(--crm-primary-text, var(--crm-primary));
}

.crm-table td a:hover {
    text-decoration: underline;
}


/* -------------------------------------------------------------------
   Toast Notifications
   ------------------------------------------------------------------- */

.crm-toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.crm-toast {
    background: var(--crm-surface);
    border-radius: var(--crm-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    min-width: 280px;
    max-width: 400px;
    border-left: 4px solid var(--crm-border);
    animation: slideIn 0.3s ease;
    pointer-events: auto;
    font-size: 14px;
}

.crm-toast--success {
    border-left-color: var(--crm-success);
}

.crm-toast--error {
    border-left-color: var(--crm-danger);
}

.crm-toast--warning {
    border-left-color: var(--crm-warning);
}

.crm-toast--info {
    border-left-color: var(--crm-primary);
}

.crm-toast-message {
    flex: 1;
}

.crm-toast-close {
    background: none;
    border: none;
    color: var(--crm-text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 16px;
    line-height: 1;
}

.crm-toast-close:hover {
    color: var(--crm-text);
}


/* -------------------------------------------------------------------
   Toggle Switch
   ------------------------------------------------------------------- */

.crm-toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.crm-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.crm-toggle-slider {
    position: absolute;
    inset: 0;
    background: #cbd5e1;
    border-radius: 99px;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.crm-toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .1);
}

.crm-toggle input:checked + .crm-toggle-slider {
    background: var(--crm-primary);
}

.crm-toggle input:checked + .crm-toggle-slider::before {
    transform: translateX(20px);
}

.crm-toggle input:focus + .crm-toggle-slider {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}


/* -------------------------------------------------------------------
   Dropdown
   ------------------------------------------------------------------- */

.crm-dropdown {
    position: relative;
    display: inline-block;
}

.crm-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 200;
    min-width: 180px;
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .1);
    padding: 0.35rem 0;
    display: none;
}

.crm-dropdown-menu.open {
    display: block;
}

.crm-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.85rem;
    font-size: 13px;
    color: var(--crm-text);
    cursor: pointer;
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    transition: background-color 0.15s;
}

.crm-dropdown-item:hover {
    background: var(--crm-surface-2);
}

.crm-dropdown-divider {
    height: 1px;
    background: var(--crm-border);
    margin: 0.35rem 0;
}


/* -------------------------------------------------------------------
   Search
   ------------------------------------------------------------------- */

.crm-search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.crm-search-wrapper .crm-input {
    padding-left: 2rem;
}

.crm-search-icon {
    position: absolute;
    left: 0.6rem;
    color: var(--crm-text-muted);
    font-size: 14px;
    pointer-events: none;
}


/* -------------------------------------------------------------------
   Pagination
   ------------------------------------------------------------------- */

.crm-pagination {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.crm-page-btn {
    padding: 0.35rem 0.7rem;
    background: var(--crm-surface);
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius);
    font-size: 13px;
    cursor: pointer;
    color: var(--crm-text);
    transition: background-color 0.15s, border-color 0.15s;
    text-decoration: none;
}

.crm-page-btn:hover {
    background: var(--crm-surface-2);
    text-decoration: none;
}

.crm-page-btn.active {
    background: var(--crm-primary);
    color: var(--crm-on-primary, #fff);
    border-color: var(--crm-primary);
}

.crm-page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}


/* -------------------------------------------------------------------
   Empty State
   ------------------------------------------------------------------- */

.crm-empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--crm-text-muted);
}

.crm-empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

.crm-empty-state-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--crm-text);
    margin-bottom: 0.35rem;
}

.crm-empty-state-text {
    font-size: 13px;
    margin-bottom: 1rem;
}


/* -------------------------------------------------------------------
   Loading / Spinner
   ------------------------------------------------------------------- */

.crm-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--crm-border);
    border-top-color: var(--crm-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.crm-spinner--lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

.crm-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, .7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: var(--crm-radius);
}


/* -------------------------------------------------------------------
   Settings Layout
   ------------------------------------------------------------------- */

.crm-settings-grid {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 1.5rem;
}

.crm-settings-sidebar {
    position: sticky;
    top: calc(var(--crm-header-h) + 1rem);
    background: var(--crm-surface);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow);
    padding: 0.75rem 0;
    align-self: start;
}

.crm-settings-cat-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--crm-text-muted);
    padding: 0.75rem 1rem;
    letter-spacing: 0.04em;
}

.crm-settings-cat-item {
    display: block;
    padding: 0.4rem 1rem 0.4rem 1.5rem;
    font-size: 13px;
    border-left: 2px solid transparent;
    cursor: pointer;
    width: 100%;
    background: none;
    border-right: none;
    border-top: none;
    border-bottom: none;
    text-align: left;
    color: var(--crm-text);
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.crm-settings-cat-item:hover {
    color: var(--crm-primary-text, var(--crm-primary));
    background: var(--crm-primary-light);
}

.crm-settings-cat-item.active {
    border-left-color: var(--crm-primary);
    color: var(--crm-primary-text, var(--crm-primary));
    font-weight: 600;
}

.crm-settings-content {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.crm-settings-section {
    display: none;
}

.crm-settings-section.active {
    display: block;
}

.crm-settings-plugins {
    display: flex;
    flex-direction: column;
}

.crm-setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--crm-border);
}

.crm-setting-item:last-child {
    border-bottom: none;
}

.crm-setting-item.crm-setting-sub {
    padding-left: 2.25rem;
    background: var(--crm-surface-2);
}

.crm-setting-info {
    flex: 1;
    min-width: 0;
}

.crm-setting-name {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--crm-text);
    line-height: 1.3;
}

.crm-setting-desc {
    display: block;
    font-size: 12px;
    color: var(--crm-text-muted);
    margin-top: 2px;
    line-height: 1.4;
}

.crm-setting-input {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.crm-setting-divider {
    padding: 0.65rem 1rem;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--crm-text-muted);
    background: var(--crm-surface-2);
    border-bottom: 1px solid var(--crm-border);
    border-top: 1px solid var(--crm-border);
}

.crm-management-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.25rem;
}


/* -------------------------------------------------------------------
   Stats Grid
   ------------------------------------------------------------------- */

.crm-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.crm-stat-card {
    background: var(--crm-surface);
    border-radius: var(--crm-radius);
    box-shadow: var(--crm-shadow);
    padding: 1rem 1.25rem;
}

.crm-stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--crm-text-muted);
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.crm-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--crm-text);
}

.crm-stat-change {
    font-size: 12px;
    margin-top: 0.15rem;
}

.crm-stat-change--up {
    color: var(--crm-success);
}

.crm-stat-change--down {
    color: var(--crm-danger);
}
