/**
 * CusmaDocs UI Enhancements
 * Comprehensive visual improvements for consistency and modern design
 */

/* ========================================================================
   BUTTON ENHANCEMENTS - Consistent sizing, spacing, and styling
   ======================================================================== */

/* Base button improvements */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.5;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
    min-height: 38px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: translateY(0);
}

.btn:disabled,
.btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Button sizes */
.btn-sm {
    padding: 0.4rem 0.875rem;
    font-size: 0.875rem;
    min-height: 32px;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    min-height: 44px;
}

/* Button variants */
.btn-primary {
    background: var(--brand, #3b82f6);
    color: white;
    border-color: var(--brand, #3b82f6);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
    background: var(--brand-2, #2563eb);
    border-color: var(--brand-2, #2563eb);
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
}

.btn-secondary {
    background: var(--muted, #475569);
    color: white;
    border-color: var(--muted, #475569);
}

.btn-secondary:hover {
    background: color-mix(in oklab, var(--muted, #475569) 85%, black);
}

.btn-success {
    background: var(--good, #16a34a);
    color: white;
    border-color: var(--good, #16a34a);
}

.btn-success:hover {
    background: color-mix(in oklab, var(--good, #16a34a) 85%, black);
}

.btn-danger {
    background: var(--bad, #dc2626);
    color: white;
    border-color: var(--bad, #dc2626);
}

.btn-danger:hover {
    background: color-mix(in oklab, var(--bad, #dc2626) 85%, black);
}

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border, #e5e7eb);
    color: var(--text, #0f172a);
}

.btn-outline:hover {
    background: var(--panel-2, #f8fafc);
    border-color: var(--brand, #3b82f6);
    color: var(--brand, #3b82f6);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--muted, #475569);
}

.btn-ghost:hover {
    background: var(--panel-2, #f8fafc);
    color: var(--text, #0f172a);
}

/* Icon buttons */
.btn i.bi {
    font-size: 1.1em;
    line-height: 1;
}

.btn-icon-only {
    padding: 0.5rem;
    min-width: 38px;
    aspect-ratio: 1;
}

/* Button groups */
.btn-group {
    display: inline-flex;
    gap: 0.5rem;
}

.btn-group-tight {
    display: inline-flex;
    gap: 0;
}

.btn-group-tight .btn {
    border-radius: 0;
    margin-left: -1px;
}

.btn-group-tight .btn:first-child {
    border-top-left-radius: 0.5rem;
    border-bottom-left-radius: 0.5rem;
    margin-left: 0;
}

.btn-group-tight .btn:last-child {
    border-top-right-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

/* ========================================================================
   CARD & PANEL ENHANCEMENTS
   ======================================================================== */

.card {
    background: var(--panel, #ffffff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.card-elevated {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.card-elevated:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border, #e5e7eb);
    background: var(--panel-2, #f8fafc);
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border, #e5e7eb);
    background: var(--panel-2, #f8fafc);
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text, #0f172a);
    margin: 0 0 0.5rem 0;
}

.card-subtitle {
    font-size: 0.875rem;
    color: var(--muted, #475569);
    margin: 0;
}

/* ========================================================================
   FORM ENHANCEMENTS
   ======================================================================== */



/* Form layouts */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.form-inline {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border, #e5e7eb);
}

/* ========================================================================
   TABLE ENHANCEMENTS
   ======================================================================== */

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 0.75rem;
    border: 1px solid var(--border, #e5e7eb);
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9375rem;
}

.table thead th {
    padding: 0.875rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted, #475569);
    background: var(--panel-2, #f8fafc);
    border-bottom: 2px solid var(--border, #e5e7eb);
    text-align: left;
    white-space: nowrap;
}

.table tbody td {
    padding: 1rem;
    border-bottom: 1px solid var(--border, #e5e7eb);
    color: var(--text, #0f172a);
}

.table tbody tr {
    transition: background-color 0.15s ease;
}

.table tbody tr:hover {
    background: var(--panel-2, #f8fafc);
}

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

/* Table alignment helpers */
.t-left { text-align: left !important; }
.t-center { text-align: center !important; }
.t-right { text-align: right !important; }

/* Table utilities */
.table-compact thead th,
.table-compact tbody td {
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
}

.table-striped tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

/* ========================================================================
   BADGE & PILL ENHANCEMENTS
   ======================================================================== */

.badge,
.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    border-radius: 0.375rem;
    white-space: nowrap;
}

.badge-primary {
    background: rgba(59, 130, 246, 0.1);
    color: var(--brand, #3b82f6);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.badge-success {
    background: rgba(22, 163, 74, 0.1);
    color: var(--good, #16a34a);
    border: 1px solid rgba(22, 163, 74, 0.2);
}

.badge-danger {
    background: rgba(220, 38, 38, 0.1);
    color: var(--bad, #dc2626);
    border: 1px solid rgba(220, 38, 38, 0.2);
}

.badge-warning {
    background: rgba(217, 119, 6, 0.1);
    color: var(--warn, #d97706);
    border: 1px solid rgba(217, 119, 6, 0.2);
}

.badge-secondary {
    background: var(--panel-2, #f8fafc);
    color: var(--muted, #475569);
    border: 1px solid var(--border, #e5e7eb);
}

/* Status-specific badges */
.status-draft {
    background: rgba(148, 163, 184, 0.15);
    color: #475569;
    border: 1px solid rgba(148, 163, 184, 0.25);
}

.status-signed {
    background: rgba(22, 163, 74, 0.15);
    color: #15803d;
    border: 1px solid rgba(22, 163, 74, 0.25);
}

.status-void {
    background: rgba(220, 38, 38, 0.15);
    color: #991b1b;
    border: 1px solid rgba(220, 38, 38, 0.25);
}

/* ========================================================================
   PAGE HEADER ENHANCEMENTS
   ======================================================================== */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    gap: 1.5rem;
}

.page-header .title {
    margin: 0 0 0.5rem 0;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text, #0f172a);
    line-height: 1.2;
}

.page-header .subtitle {
    margin: 0;
    font-size: 1rem;
    color: var(--muted, #475569);
    line-height: 1.5;
}

.page-header .actions {
    display: flex;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* Responsive page header */
@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .page-header .actions {
        width: 100%;
        justify-content: stretch;
    }
    
    .page-header .actions .btn {
        flex: 1;
    }
}

/* ========================================================================
   TOOLBAR ENHANCEMENTS
   ======================================================================== */

.toolbar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--panel, #ffffff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 0.75rem;
    flex-wrap: wrap;
}

.toolbar .spacer {
    flex: 1;
}

.toolbar .input {
    min-width: 200px;
    flex: 1;
    max-width: 400px;
    margin: 0;
}

.toolbar .btn {
    margin: 0;
}

@media (max-width: 640px) {
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .toolbar .input {
        max-width: none;
        width: 100%;
    }
    
    .toolbar .spacer {
        display: none;
    }
}

/* ========================================================================
   ALERT & MESSAGE ENHANCEMENTS
   ======================================================================== */

.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-radius: 0.75rem;
    margin-bottom: 1.5rem;
    border: 1px solid;
    font-size: 0.9375rem;
}

.alert i.bi {
    font-size: 1.25rem;
    flex-shrink: 0;
    margin-top: 0.125rem;
}

.alert-success {
    background: rgba(22, 163, 74, 0.1);
    color: #15803d;
    border-color: rgba(22, 163, 74, 0.25);
}

.alert-danger,
.alert-error {
    background: rgba(220, 38, 38, 0.1);
    color: #991b1b;
    border-color: rgba(220, 38, 38, 0.25);
}

.alert-warning {
    background: rgba(217, 119, 6, 0.1);
    color: #92400e;
    border-color: rgba(217, 119, 6, 0.25);
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    color: #1e40af;
    border-color: rgba(59, 130, 246, 0.25);
}

/* ========================================================================
   LOADING STATES
   ======================================================================== */

.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid var(--border, #e5e7eb);
    border-top-color: var(--brand, #3b82f6);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border, #e5e7eb);
    border-top-color: var(--brand, #3b82f6);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ========================================================================
   UTILITY CLASSES
   ======================================================================== */

/* Spacing */
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.5rem !important; }
.mb-2 { margin-bottom: 1rem !important; }
.mb-3 { margin-bottom: 1.5rem !important; }
.mb-4 { margin-bottom: 2rem !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 0.5rem !important; }
.mt-2 { margin-top: 1rem !important; }
.mt-3 { margin-top: 1.5rem !important; }
.mt-4 { margin-top: 2rem !important; }

.p-0 { padding: 0 !important; }
.p-1 { padding: 0.5rem !important; }
.p-2 { padding: 1rem !important; }
.p-3 { padding: 1.5rem !important; }
.p-4 { padding: 2rem !important; }

/* Text alignment */
.text-left { text-align: left !important; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }

/* Text colors */
.text-muted { color: var(--muted, #475569) !important; }
.text-primary { color: var(--brand, #3b82f6) !important; }
.text-success { color: var(--good, #16a34a) !important; }
.text-danger { color: var(--bad, #dc2626) !important; }
.text-warning { color: var(--warn, #d97706) !important; }

/* Display */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }
.d-flex { display: flex !important; }
.d-grid { display: grid !important; }

/* Flex utilities */
.flex-row { flex-direction: row !important; }
.flex-column { flex-direction: column !important; }
.align-items-center { align-items: center !important; }
.align-items-start { align-items: flex-start !important; }
.align-items-end { align-items: flex-end !important; }
.justify-content-start { justify-content: flex-start !important; }
.justify-content-center { justify-content: center !important; }
.justify-content-end { justify-content: flex-end !important; }
.justify-content-between { justify-content: space-between !important; }
.gap-1 { gap: 0.5rem !important; }
.gap-2 { gap: 1rem !important; }
.gap-3 { gap: 1.5rem !important; }

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


/* ========================================================================
   RESPONSIVE IMPROVEMENTS
   ======================================================================== */

@media (max-width: 768px) {
    .btn {
        font-size: 0.875rem;
        padding: 0.5rem 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions .btn {
        width: 100%;
    }
    
    .table {
        font-size: 0.875rem;
    }
    
    .table thead th,
    .table tbody td {
        padding: 0.75rem 0.625rem;
    }
}

/* ========================================================================
   ANIMATION UTILITIES
   ======================================================================== */

.fade-in {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.slide-in {
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Smooth transitions for interactive elements */
a, button, .btn, .card {
    transition: all 0.2s ease;
}

/* ========================================================================
   ACCESSIBILITY IMPROVEMENTS
   ======================================================================== */

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--brand, #3b82f6);
    outline-offset: 2px;
}

/* Skip to main content */
.skip-to-main {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--brand, #3b82f6);
    color: white;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    z-index: 9999;
}

.skip-to-main:focus {
    top: 0;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
