/* Intapp Definitions Page Styles */

.definitions-page {
    /* Matches letters / clauses / templates / users — these list pages share the wide
       viewing space (capped at 2000px in MainLayout's content-wrapper :has rule). */
    max-width: 2500px;
    margin: 0 auto;
    padding: 24px;
}

/* Page Header */
.definitions-page .page-header {
    /* Other pages (clauses, dashboard, etc.) define a global `.page-header { display: flex }`
       in their own stylesheets, and those rules leak in app-wide. That layout puts the title
       row and the filter row side-by-side, which makes the search/filters feel cramped against
       the title. Stack them vertically instead — title on top, search bar underneath.
       `align-items: stretch` is needed because the global `.page-header` sets
       `align-items: flex-start`, which would otherwise size each child to its content width
       and left-align it — defeating `justify-content: space-between` on .page-header-top
       (the Import button would sit right next to the title instead of at the right edge). */
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 24px;
}

.definitions-page .page-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.page-title h1 {
    font-size: 24px;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0 0 6px 0;
}

.page-title p {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0;
}

.definitions-page .page-actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

.upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.upload-btn:hover {
    background-color: #4338ca;
}

.definitions-page .filter-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.definitions-page .filter-row .filter-bar {
    flex: 1;
}

.definitions-page .filter-row .upload-btn {
    flex-shrink: 0;
}

/* Filter Bar */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--border-primary);
    border-radius: 12px;
}


.search-box {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i {
    position: absolute;
    left: 12px;
    color: var(--text-placeholder);
}

.search-box input {
    width: 100%;
    padding: 10px 36px 10px 40px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.clear-search {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-placeholder);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-search:hover {
    color: var(--text-muted);
}

.category-filter select {
    padding: 10px 36px 10px 12px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    min-width: 180px;
}

.category-filter select:focus {
    outline: none;
    border-color: #6366f1;
}

.result-count {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Import Status */
.import-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 14px;
}

.import-status.uploading {
    background: var(--color-primary-bg-subtle);
    color: var(--color-primary-hover);
    border: 1px solid #bfdbfe;
}

.import-status.success {
    background: var(--color-success-bg-subtle);
    color: #15803d;
    border: 1px solid var(--color-success-border);
}

.import-status.error {
    background: var(--color-danger-bg-subtle);
    color: var(--color-danger);
    border: 1px solid var(--color-danger-border);
}

.dismiss-btn {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    opacity: 0.7;
    color: inherit;
}

.dismiss-btn:hover {
    opacity: 1;
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 40px;
    color: var(--text-muted);
    gap: 16px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 40px;
    background: #fff;
    border: 2px dashed var(--border-primary);
    border-radius: 16px;
    text-align: center;
}

.empty-state i {
    font-size: 48px;
    color: var(--text-faint);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 8px 0;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0 0 24px 0;
    max-width: 400px;
}

/* Definitions Table */
.definitions-table-container {
    background: #fff;
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    overflow: hidden;
}

.definitions-table {
    width: 100%;
    border-collapse: collapse;
}

.definitions-table thead {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
}

.definitions-table th {
    padding: 14px 16px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.definitions-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}

.definitions-table th.sortable:hover {
    color: var(--text-primary);
}

.definitions-table th.sortable.sorted {
    color: var(--color-primary);
}

.definitions-table th.sortable i {
    font-size: 10px;
    margin-left: 4px;
    opacity: 0.4;
}

.definitions-table th.sortable:hover i,
.definitions-table th.sortable.sorted i {
    opacity: 1;
}

.definitions-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--bg-tertiary);
    font-size: 14px;
    color: var(--text-secondary);
    vertical-align: middle;
}

.definitions-table tbody tr:hover {
    background: var(--bg-secondary);
}

.definitions-table tbody tr:last-child td {
    border-bottom: none;
}

/* Column widths */
.definitions-page .col-name { width: 18%; }
.definitions-page .col-form { width: 14%; }
.definitions-page .col-title { width: 20%; }
.definitions-page .col-category { width: 10%; }
.definitions-page .col-type { width: 10%; }
.definitions-page .col-tags { width: 19%; }
.definitions-page .col-actions { width: 9%; text-align: right; }

/* Form name cell */
.form-name {
    font-size: 12px;
    color: var(--text-secondary);
}

.no-form {
    color: var(--text-placeholder);
    font-size: 12px;
}

/* Name cell */
.name-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.question-name {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 13px;
    font-weight: 500;
    color: #1a1a2e;
}

.question-id {
    font-size: 11px;
    color: var(--text-placeholder);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

/* Title cell */
.title-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.title-cell .title {
    flex: 1;
}

.title-cell .help-text {
    color: var(--text-placeholder);
    cursor: help;
}

.title-cell .help-text:hover {
    color: #6366f1;
}

/* Category badge */
.category-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
}

.category-badge.client-information { background: var(--color-primary-bg); color: var(--color-primary-hover); }
.category-badge.request-information { background: var(--color-warning-bg); color: #b45309; }
.category-badge.matter { background: var(--color-success-bg); color: #047857; }
.category-badge.financial { background: #fce7f3; color: #be185d; }
/* billing was purple (#ede9fe / #6d28d9) — swapped to slate.
   contact-details was indigo (#e0e7ff / #4338ca) which reads as purple too —
   swapped to cyan. Both stay distinguishable from the other category
   palettes (blue/amber/green/pink/teal/orange/rose). */
.category-badge.billing { background: #e2e8f0; color: #334155; }
.category-badge.contact-details { background: #cffafe; color: #155e75; }
.category-badge.names { background: #ccfbf1; color: #0d9488; }
.category-badge.address { background: #fed7aa; color: #c2410c; }
.category-badge.dates { background: #fecdd3; color: #be123c; }
.category-badge.legal { background: #bfdbfe; color: var(--color-info-text); }

/* Type badge */
.type-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-secondary);
    color: var(--text-muted);
    border: 1px solid var(--border-primary);
}

/* Tags cell */
.tags-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    background: var(--color-primary-bg-subtle);
    color: var(--color-primary);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.tag.more {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.tag.editable {
    padding-right: 4px;
}

.remove-tag {
    background: none;
    border: none;
    padding: 2px 4px;
    margin-left: 2px;
    cursor: pointer;
    color: var(--color-primary);
    opacity: 0.7;
    display: flex;
    align-items: center;
}

.remove-tag:hover {
    opacity: 1;
    color: var(--color-danger);
}

.no-tags {
    font-size: 12px;
    color: var(--text-placeholder);
    font-style: italic;
}

/* Action buttons */
.btn-icon {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 6px;
    transition: all 0.15s;
}

.btn-icon:hover {
    background: var(--bg-tertiary);
    color: #6366f1;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.modal.show {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    z-index: 1001;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-primary);
}

.modal-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-title i {
    font-size: 20px;
    color: #6366f1;
}

.modal-title h2 {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a2e;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 8px;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-primary);
    background: var(--bg-secondary);
    border-radius: 0 0 16px 16px;
}

/* Definition Summary in Modal */
.definition-summary {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.summary-row {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

.summary-row:last-child {
    margin-bottom: 0;
}

.summary-row .label {
    font-size: 13px;
    color: var(--text-muted);
    min-width: 120px;
}

.summary-row .value {
    font-size: 13px;
    color: #1a1a2e;
    font-weight: 500;
}

/* Form Sections */
.form-section {
    margin-bottom: 24px;
}

.form-section:last-child {
    margin-bottom: 0;
}

.form-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.form-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Tags Editor */
.tags-editor {
    margin-bottom: 16px;
}

.current-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 36px;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    margin-bottom: 12px;
}

.add-tag-row {
    display: flex;
    gap: 8px;
}

.add-tag-row input {
    flex: 1;
}

.form-input {
    padding: 10px 12px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    font-size: 14px;
}

.form-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Suggested Tags */
.suggested-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.suggested-label {
    font-size: 12px;
    color: var(--text-muted);
}

.suggested-tag {
    padding: 4px 10px;
    background: var(--bg-tertiary);
    border: 1px dashed var(--text-faint);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.suggested-tag:hover:not(:disabled) {
    background: var(--color-primary-bg-subtle);
    border-color: #93c5fd;
    color: var(--color-primary);
}

.suggested-tag:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Detail View */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.detail-item.full-width {
    grid-column: 1 / -1;
}

.detail-item label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.detail-item span {
    font-size: 14px;
    color: #1a1a2e;
}

.detail-item .mono {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 13px;
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: 6px;
    word-break: break-all;
}

.tags-display {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Buttons — see design-tokens.css for canonical button rules. */

/* Toast Notifications */
.toast-notification {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    animation: slideIn 0.3s ease-out;
}

.toast-notification.success {
    background: var(--color-success);
    color: #fff;
}

.toast-notification.error {
    background: var(--color-danger);
    color: #fff;
}

@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Spinner */
.spinner-border {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

.spinner-border-sm {
    width: 0.875em;
    height: 0.875em;
    border-width: 1.5px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .page-header-top {
        flex-direction: column;
        gap: 16px;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .category-filter select {
        width: 100%;
    }

    .definitions-table-container {
        overflow-x: auto;
    }

    .definitions-table {
        min-width: 800px;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .modal.show {
        width: 95%;
        max-height: 95vh;
    }
}
