*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --border: #e0e0e0;
    --text: #1a1a1a;
    --text-secondary: #666;
    --accent: #2563eb;
    --accent-light: #dbeafe;
    --highlight-req: #fef08a;
    --highlight-active: #fbbf24;
    --highlight-keyword: #bfdbfe;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --success: #16a34a;
    --radius: 6px;
    --sidebar-width: 280px;
    --header-height: 48px;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', 'Liberation Mono', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html,
body {
    height: 100%;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.2s ease;
}

.sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
}

#rfc-search {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
    background: var(--bg);
    flex: 1;
}

#rfc-search:focus {
    border-color: var(--accent);
}

.sidebar-filter-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.btn-fav-filter {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 8px;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-secondary);
    flex-shrink: 0;
    line-height: 1;
}

.btn-fav-filter.active {
    color: #eab308;
    border-color: #eab308;
    background: #fefce8;
}

.rfc-fav-star {
    cursor: pointer;
    font-size: 14px;
    color: var(--border);
    flex-shrink: 0;
    line-height: 1;
}

.rfc-fav-star.favourited {
    color: #eab308;
}

.rfc-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
}

.rfc-list li {
    padding: 8px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.1s;
}

.rfc-list li:hover {
    background: var(--bg);
}

.rfc-list li.active {
    background: var(--accent-light);
    color: var(--accent);
    font-weight: 500;
}

.rfc-list .rfc-stat {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.rfc-list li.active .rfc-stat {
    color: var(--accent);
}

.sidebar-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text);
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: var(--bg);
}

/* Main */
.main {
    margin-left: var(--sidebar-width);
    height: 100%;
    display: flex;
    transition: margin-left 0.2s ease;
}

.sidebar.collapsed~.main {
    margin-left: 0;
}

.pane {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.rfc-pane {
    flex: 3;
    border-right: 1px solid var(--border);
    min-width: 680px;
}

.req-pane {
    flex: 2;
}

.pane-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    min-height: var(--header-height);
}

.req-pane .pane-header {
    min-height: var(--header-height);
}

.req-nav-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

.req-nav-controls button {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    font-size: 12px;
    transition: background 0.1s;
}

.req-nav-controls button:hover {
    background: var(--bg);
}

#req-nav-indicator {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

.pane-header h3 {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    flex: 1;
    justify-content: flex-end;
}

.keyword-stats {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 11px;
}

.keyword-stats .stat-badge {
    padding: 2px 6px;
    border-radius: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.keyword-stats .stat-badge.filter-active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.nav-controls,
.page-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-controls button,
.nav-controls button {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    font-size: 12px;
    transition: background 0.1s;
}

.page-controls button:hover,
.nav-controls button:hover {
    background: var(--bg);
}

#page-indicator {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

/* RFC content */
.rfc-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    background: var(--surface);
    outline: none;
    cursor: text;
}

.rfc-content .placeholder {
    font-family: var(--font-sans);
    color: var(--text-secondary);
    white-space: normal;
}

/* Highlighted keywords in the RFC text */
.rfc-content .kw {
    background: var(--highlight-keyword);
    border-radius: 2px;
    padding: 0 1px;
}

/* Text that has an associated requirement */
.rfc-content .req-highlight {
    background: var(--highlight-req);
    border-radius: 2px;
    cursor: pointer;
}

/* Active requirement highlight */
.rfc-content .req-active {
    background: var(--highlight-active);
    outline: 2px solid #f59e0b;
    outline-offset: -1px;
}

/* Keyword search active result */
.rfc-content .kw-active {
    background: #f97316;
    color: white;
    border-radius: 2px;
}

/* Requirements list */
.req-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.req-list .placeholder {
    color: var(--text-secondary);
    text-align: center;
    padding: 24px;
}

.req-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    background: var(--surface);
    transition: border-color 0.1s;
    cursor: pointer;
}

.req-card:hover {
    border-color: var(--accent);
}

.req-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.req-card-header {
    padding: 10px 12px 6px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.req-card-header .req-priority {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
    text-transform: uppercase;
}

.req-priority.must,
.req-priority.required,
.req-priority.shall {
    background: var(--danger-light);
    color: var(--danger);
}

.req-priority.must-not,
.req-priority.shall-not {
    background: #fce7f3;
    color: #be185d;
}

.req-priority.should,
.req-priority.recommended {
    background: #fef3c7;
    color: #92400e;
}

.req-priority.should-not,
.req-priority.not-recommended {
    background: #fff7ed;
    color: #9a3412;
}

.req-priority.may,
.req-priority.optional {
    background: #ecfdf5;
    color: #065f46;
}

.req-card-body {
    padding: 0 12px 10px;
}

.req-card-body .req-text {
    font-size: 12px;
    color: var(--text);
    line-height: 1.5;
    margin-bottom: 8px;
    max-height: 60px;
    overflow: hidden;
}

.req-card.expanded .req-card-body .req-text {
    max-height: none;
}

.req-card-actions {
    display: none;
    padding: 0 12px 12px;
}

.req-card.expanded .req-card-actions {
    display: block;
}

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group textarea,
.form-group input,
.form-group select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: var(--font-sans);
    background: var(--bg);
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.form-group textarea:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Searchable dropdown */
.search-dropdown {
    position: relative;
}

.search-dropdown input {
    width: 100%;
}

.search-dropdown .dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 150px;
    overflow-y: auto;
    z-index: 50;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.search-dropdown .dropdown-list.show {
    display: block;
}

.search-dropdown .dropdown-item {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 13px;
}

.search-dropdown .dropdown-item:hover {
    background: var(--accent-light);
}

.search-dropdown .dropdown-create {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--accent);
    font-style: italic;
    border-top: 1px solid var(--border);
}

.search-dropdown .dropdown-create:hover {
    background: var(--accent-light);
}

/* Multi-select tags */
.tag-container {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--accent-light);
    border-radius: 12px;
    font-size: 12px;
    color: var(--accent);
}

.tag .tag-remove {
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    line-height: 1;
}

.tag .tag-remove:hover {
    color: var(--danger);
}

.btn-row {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 8px;
}

button.btn-primary {
    padding: 6px 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}

button.btn-primary:hover {
    opacity: 0.9;
}

button.btn-primary:disabled {
    opacity: 0.5;
    cursor: default;
}

button.btn-danger {
    padding: 6px 14px;
    background: none;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
}

button.btn-danger:hover {
    background: var(--danger-light);
}

button.btn-secondary {
    padding: 6px 14px;
    background: none;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
}

button.btn-secondary:hover {
    background: var(--bg);
}

/* Context menu for text selection */
.context-menu {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 200;
    padding: 4px;
    display: none;
}

.context-menu button {
    display: block;
    width: 100%;
    padding: 8px 16px;
    border: none;
    background: none;
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    border-radius: 4px;
    white-space: nowrap;
}

.context-menu button:hover {
    background: var(--accent-light);
    color: var(--accent);
}

/* Selection popup */
.selection-popup {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 200;
    display: none;
    padding: 4px;
}

.selection-popup button {
    padding: 6px 14px;
    border: none;
    background: var(--accent);
    color: white;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 500;
}

.selection-popup button:hover {
    opacity: 0.9;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Readonly mode */
body.readonly .req-card-actions {
    display: none !important;
}

body.readonly .rfc-fav-star {
    display: none;
}

body.readonly .btn-fav-filter {
    display: none;
}

body.readonly .btn-refresh-rfcs {
    display: none;
}

.btn-req-filter {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    flex-shrink: 0;
    line-height: 1;
}

.btn-req-filter.active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-light);
}

.btn-refresh-rfcs {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    flex-shrink: 0;
    line-height: 1;
}

.btn-refresh-rfcs:hover {
    background: var(--bg);
}

.btn-refresh-rfcs.loading {
    animation: spin 1s linear infinite;
    pointer-events: none;
    opacity: 0.5;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.rfc-list .rfc-entry-name {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    flex: 1;
}

.rfc-list .rfc-title {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}