/* Engrams Dashboard Styles */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --bg-hover: #1a4080;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --accent: #4A90D9;
    --accent-hover: #5BA0E9;
    --success: #5CB85C;
    --warning: #F0AD4E;
    --danger: #D9534F;
    --border: #2a2a4a;
    --shadow: rgba(0, 0, 0, 0.3);
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

[x-cloak] { display: none !important; }

/* Navigation */
.top-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
}

.brand-icon { font-size: 1.3rem; }

.nav-links {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.nav-links a:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-links a.active { background: var(--accent); color: #fff; }

.nav-search {
    margin-left: auto;
}

.nav-search input {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    width: 200px;
}

/* Main Content */
.content {
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
}

h1 { margin-bottom: 1.5rem; font-size: 1.5rem; }
h2 { margin-bottom: 1rem; font-size: 1.2rem; color: var(--accent); }
h3 { margin-bottom: 0.5rem; font-size: 1rem; }

/* Loading */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.25rem;
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--border);
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Cards */
.card {
    background: var(--bg-card);
    padding: 1.25rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}

.card.warning {
    border-color: var(--warning);
    background: rgba(240, 173, 78, 0.1);
}

.card.clickable { cursor: pointer; transition: border-color 0.2s; }
.card.clickable:hover { border-color: var(--accent); }

.card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1rem;
}

/* JSON Display */
.json-display {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 400px;
    overflow-y: auto;
    color: var(--text-secondary);
}

.json-display.small { max-height: 200px; font-size: 0.75rem; }

.updated-at {
    display: block;
    margin-top: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Tables */
.table-container { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th, td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.03em;
}

tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg-hover); }

/* Badges & Tags */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.badge-decision { background: rgba(74, 144, 217, 0.2); color: #4A90D9; }
.badge-system_pattern { background: rgba(92, 184, 92, 0.2); color: #5CB85C; }
.badge-progress { background: rgba(240, 173, 78, 0.2); color: #F0AD4E; }
.badge-custom_data { background: rgba(153, 153, 153, 0.2); color: #999; }
.badge-team { background: rgba(92, 184, 92, 0.2); color: #5CB85C; }
.badge-individual { background: rgba(74, 144, 217, 0.2); color: #4A90D9; }
.badge-category { background: rgba(153, 107, 217, 0.2); color: #9B6BD9; }
.badge-binding { background: rgba(240, 173, 78, 0.2); color: #F0AD4E; }

.tag {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    background: rgba(74, 144, 217, 0.15);
    color: var(--accent);
    margin: 0.1rem;
}

.status-in_progress { background: rgba(74, 144, 217, 0.2); color: #4A90D9; }
.status-todo { background: rgba(153, 153, 153, 0.2); color: #999; }
.status-blocked { background: rgba(217, 83, 79, 0.2); color: #D9534F; }
.status-done { background: rgba(92, 184, 92, 0.2); color: #5CB85C; }
.status-proposed { background: rgba(240, 173, 78, 0.2); color: #F0AD4E; }
.status-accepted { background: rgba(92, 184, 92, 0.2); color: #5CB85C; }
.status-rejected { background: rgba(217, 83, 79, 0.2); color: #D9534F; }

.rule-hard_block { background: rgba(217, 83, 79, 0.2); color: #D9534F; }
.rule-soft_warn { background: rgba(240, 173, 78, 0.2); color: #F0AD4E; }
.rule-allow_with_flag { background: rgba(92, 184, 92, 0.2); color: #5CB85C; }

/* Toolbar */
.toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar input, .toolbar select {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

.toolbar button, button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.4rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s;
}

button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.toolbar label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.85rem;
    cursor: pointer;
}

/* Activity List */
.activity-list { max-height: 400px; overflow-y: auto; }

.activity-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.activity-label { flex: 1; font-size: 0.85rem; }
.activity-time { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; }

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.modal {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 2rem;
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid var(--border);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.detail-section { margin: 1rem 0; }
.detail-section h3 { color: var(--accent); font-size: 0.9rem; margin-bottom: 0.3rem; }
.detail-section p { font-size: 0.85rem; color: var(--text-secondary); }

.link-item, .binding-item, .rule-card, .amendment-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.binding-item code {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: var(--bg-primary);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
}

/* Knowledge Graph */
#graph-container {
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border);
    height: 600px;
    overflow: hidden;
}

.graph-legend {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
    font-size: 0.8rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

/* Chat */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 200px);
    min-height: 400px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px 8px 0 0;
    border: 1px solid var(--border);
}

.chat-message {
    margin-bottom: 1rem;
    max-width: 80%;
}

.chat-message.user {
    margin-left: auto;
}

.chat-message.user .message-content {
    background: var(--accent);
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 12px 12px 4px 12px;
}

.chat-message.assistant .message-content {
    background: var(--bg-card);
    padding: 0.75rem 1rem;
    border-radius: 12px 12px 12px 4px;
}

.message-context {
    margin-top: 0.5rem;
    padding: 0.25rem 0;
}

.chat-input {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-card);
    border-radius: 0 0 8px 8px;
    border: 1px solid var(--border);
    border-top: none;
}

.chat-input input {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.6rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
}

/* Search Results */
.search-result {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
}

.search-result strong { flex: 1; min-width: 200px; }
.search-result p { width: 100%; font-size: 0.8rem; color: var(--text-secondary); }

/* Responsive */
@media (max-width: 768px) {
    .top-nav { flex-wrap: wrap; }
    .nav-links { order: 3; width: 100%; }
    .nav-search { order: 2; }
    .card-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    #graph-container { height: 400px; }
}
