/* Cortex Dashboard — Abbacus Brand Identity
   Warm backgrounds, stone text, blue accent */

:root {
    --bg-primary: #faf8f5;
    --bg-secondary: #f0ece6;
    --bg-card: #ffffff;
    --text-primary: #3d3833;
    --text-secondary: #6b6560;
    --text-muted: #9b9590;
    --accent: #2563eb;
    --accent-light: #dbeafe;
    --accent-dark: #1d4ed8;
    --border: #e5e0da;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 220px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    flex-shrink: 0;
}

.sidebar-brand {
    padding: 0 1.25rem 1.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.sidebar-brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-brand small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.sidebar nav a {
    display: block;
    padding: 0.5rem 1.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    border-left: 3px solid transparent;
}

.sidebar nav a:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
    text-decoration: none;
}

.sidebar nav a.active {
    color: var(--accent);
    border-left-color: var(--accent);
    background: var(--bg-primary);
    font-weight: 600;
}

.main {
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
}

.page-title {
    margin-bottom: 1rem;
    font-size: 1.5rem;
    line-height: 1.2;
}

.page-title-lg {
    margin-bottom: 1.5rem;
}

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

.card-spaced { margin-bottom: 1.5rem; }

.stack-sm > * + * { margin-top: 0.5rem; }

.card-header {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

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

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

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

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.table-empty {
    text-align: center;
    color: var(--text-muted);
}

.text-strong { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-xs { font-size: 0.75rem; }

.truncate {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
}

td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

tr:hover { background: var(--bg-secondary); }

/* Type badges */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-decision { background: #dbeafe; color: #1e40af; }
.badge-lesson { background: #d1fae5; color: #065f46; }
.badge-fix { background: #fee2e2; color: #991b1b; }
.badge-session { background: #fef3c7; color: #92400e; }
.badge-research { background: #ede9fe; color: #5b21b6; }
.badge-source { background: #e0e7ff; color: #3730a3; }
.badge-synthesis { background: #fce7f3; color: #9d174d; }
.badge-idea { background: #f0fdf4; color: #166534; }

/* Forms */
input, select, textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--bg-card);
    color: var(--text-primary);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-light);
}

textarea { min-height: 120px; resize: vertical; }

label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.form-group { margin-bottom: 1rem; }

.form-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-row > * {
    flex: 1 1 180px;
    min-width: 0;
}

.btn {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover { background: var(--accent-dark); }

.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.75rem; }

.hidden { display: none; }

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
}

.alert-danger { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }

/* Project grid */
.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.project-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s, border-color 0.15s;
    text-decoration: none;
    color: inherit;
}

.project-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--accent);
    text-decoration: none;
}

.project-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.project-last-activity {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.project-stat {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
}

.project-count {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
}

.project-count-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Breadcrumbs */
.breadcrumb-link {
    color: var(--text-muted);
    font-weight: 400;
}

.breadcrumb-link:hover {
    color: var(--accent);
}

.breadcrumb-sep {
    color: var(--text-muted);
    margin: 0 0.25rem;
    font-weight: 300;
}

/* Explore page */
.explore-stat-row {
    display: flex;
    gap: 2rem;
    margin-top: 0.75rem;
}

.explore-stat {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
}

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

.explore-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.connection-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.connection-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

.connection-item:hover {
    background: var(--bg-secondary);
}

.connection-direction {
    font-size: 1rem;
    font-weight: 700;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.connection-outgoing { color: var(--accent); }
.connection-incoming { color: var(--success); }

.connection-rel {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    min-width: 80px;
}

.connection-target {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.truncate-wide {
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Entity browser */
.entity-filter-row {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.entity-tab {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 99px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.entity-tab:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.entity-tab-active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.entity-tab-active:hover {
    color: white;
}

.entity-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.entity-chip {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    font-size: 0.8rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.15s;
}

.entity-chip:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow);
    text-decoration: none;
}

.entity-chip-type {
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
}

.entity-chip-name {
    font-weight: 500;
}

.entity-chip-count {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-light);
    padding: 0.1rem 0.35rem;
    border-radius: 99px;
    min-width: 1.2rem;
    text-align: center;
}

/* Size variants */
.entity-chip-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.7rem;
}

.entity-chip-md {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
}

.entity-chip-lg {
    padding: 0.5rem 0.9rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.entity-chip-xl {
    padding: 0.6rem 1rem;
    font-size: 1rem;
    font-weight: 700;
    border-width: 2px;
    border-color: var(--accent);
}

/* Settings import/export */
.settings-io-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
}

/* Graph container */
#cy {
    width: 100%;
    height: 600px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
}

/* Login page */
.login-container {
    max-width: 360px;
    margin: 8rem auto;
    padding: 2rem;
}

/* Detail page */
.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.meta-item label { margin-bottom: 0; }
.meta-item span { font-size: 0.875rem; }

.content-body {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: var(--radius);
    white-space: pre-wrap;
    font-size: 0.875rem;
    line-height: 1.7;
}

/* Relationships */
.rel-list { list-style: none; }
.rel-list li {
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 768px) {
    .layout { flex-direction: column; }
    .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
    .sidebar nav { display: flex; overflow-x: auto; }
    .sidebar nav a { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
    .sidebar nav a.active { border-left: none; border-bottom-color: var(--accent); }
    .main { padding: 1rem; }
    .truncate { max-width: 220px; }
}
