:root {
    --bg: #f5f5f5;
    --card: #ffffff;
    --border: #ddd;
    --text: #333;
    --text-muted: #666;
    --primary: #1F4E79;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --purple: #6f42c1;
}

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

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

header {
    background: var(--primary);
    color: white;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-wrap: wrap;
    gap: 0.5rem;
}
header h1 { font-size: 1.25rem; font-weight: 600; cursor: pointer; }
.header-right { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.user-info { font-size: 0.875rem; margin-right: 0.5rem; }
.user-info .role { 
    background: rgba(255,255,255,0.2); 
    padding: 0.1rem 0.3rem; 
    border-radius: 3px; 
    font-size: 0.7rem; 
    margin-left: 0.3rem;
}

.container { padding: 1rem; }

.login-container {
    max-width: 400px;
    margin: 100px auto;
    padding: 2rem;
    background: var(--card);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.login-container h2 { margin-bottom: 1.5rem; text-align: center; }
.login-container .form-row { margin-bottom: 1rem; }
.login-container label { display: block; margin-bottom: 0.25rem; font-weight: 500; }
.login-container input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 1rem;
}
.login-container .btn { width: 100%; padding: 0.75rem; font-size: 1rem; }
.login-error { color: var(--danger); margin-bottom: 1rem; text-align: center; }

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
}
.tab {
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-radius: 4px 4px 0 0;
}
.tab:hover { background: rgba(0,0,0,0.05); }
.tab.active { 
    color: var(--primary); 
    font-weight: 600;
    border-bottom: 2px solid var(--primary);
    margin-bottom: -2px;
}
.tab-content { display: none; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }
.tab-content.active { display: block; }

.stats-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    min-width: 80px;
}
.stat-card .label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; }
.stat-card .value { font-size: 1.25rem; font-weight: 600; }

.filters {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 1rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; gap: 0.2rem; }
.filter-group label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; }
.filter-group select, .filter-group input {
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.8rem;
    min-width: 100px;
}

.btn {
    padding: 0.4rem 0.75rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: opacity 0.2s;
    text-decoration: none;
    display: inline-block;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-secondary { background: #6c757d; color: white; }
.btn-warning { background: var(--warning); color: #333; }
.btn-purple { background: var(--purple); color: white; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }

.table-wrapper {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th, td { padding: 0.5rem 0.4rem; text-align: left; border-bottom: 1px solid var(--border); }
th { 
    background: #f8f9fa; 
    font-weight: 600; 
    position: sticky; 
    top: 0; 
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
th:hover { background: #e9ecef; }
th .sort-icon { margin-left: 0.25rem; opacity: 0.3; font-size: 0.7rem; }
th.sorted .sort-icon { opacity: 1; }
tr:hover { background: #f8f9fa; }
tr.clickable { cursor: pointer; }

.task-cell { max-width: 400px; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 500;
    white-space: nowrap;
}
.badge-backlog { background: #e9ecef; color: #495057; }
.badge-active { background: #cce5ff; color: #004085; }
.badge-blocked { background: #f8d7da; color: #721c24; }
.badge-review { background: #fff3cd; color: #856404; }
.badge-delayed { background: #e2d5f1; color: #5a3d8a; }
.badge-done { background: #d4edda; color: #155724; }
.badge-canceled { background: #e9ecef; color: #6c757d; text-decoration: line-through; }

.badge-critical { background: #dc3545; color: white; }
.badge-high { background: #fd7e14; color: white; }
.badge-medium { background: #ffc107; color: #333; }
.badge-low { background: #6c757d; color: white; }

.badge-now { background: #dc3545; color: white; }
.badge-thisweek { background: #fd7e14; color: white; }
.badge-thismonth { background: #17a2b8; color: white; }
.badge-someday { background: #6c757d; color: white; }

.deadline-badge { display:inline-block; padding:0.15rem 0.45rem; border-radius:10px; font-size:0.7rem; font-weight:600; margin-left:2px; }
.deadline-overdue { background:#7b0000; color:white; }
.deadline-today   { background:#dc3545; color:white; }
.deadline-now     { background:#dc3545; color:white; }
.deadline-week    { background:#fd7e14; color:white; }
.deadline-month   { background:#17a2b8; color:white; }
.deadline-someday { background:#adb5bd; color:#333; }

.badge-bot { background: var(--purple); color: white; }
.badge-admin { background: var(--primary); color: white; }
.badge-unverified { background: var(--warning); color: #333; }

.company-codes { display: flex; gap: 0.2rem; flex-wrap: wrap; }
.company-code {
    display: inline-block;
    padding: 0.1rem 0.3rem;
    background: var(--primary);
    color: white;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
}
.company-code.priv { background: var(--purple); }

/* Project/Subtask hierarchy styles */
tr.is-project { background: #f0f7ff; }
tr.is-project:hover { background: #e3f0ff; }
tr.is-subtask { background: #fafafa; }
tr.depth-1 td:first-child { padding-left: 1.5rem; }
tr.depth-2 td:first-child { padding-left: 2.5rem; }
tr.depth-3 td:first-child { padding-left: 3.5rem; }

.tree-toggle {
    cursor: pointer;
    display: inline-block;
    width: 16px;
    text-align: center;
    margin-right: 4px;
    font-size: 0.7rem;
    color: var(--primary);
}
.tree-toggle:hover { color: var(--text); }

.subtask-count {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-left: 0.3rem;
}
.subtask-count.has-open { color: var(--primary); font-weight: 500; }

.badge-project { background: var(--primary); color: white; }

/* Subtasks section in detail view */
.subtasks-section { margin-bottom: 1.5rem; }
.subtasks-section h3 { font-size: 1rem; margin-bottom: 0.75rem; padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }
.subtask-item { 
    display: flex; align-items: center; gap: 0.75rem; 
    padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; margin-bottom: 0.5rem;
}
.subtask-item:hover { background: #f8f9fa; cursor: pointer; }
.subtask-item .subtask-status { min-width: 60px; }
.subtask-item .subtask-title { flex: 1; }

.actions { white-space: nowrap; }
.actions .btn { margin-right: 0.2rem; }

.blocked-link { color: var(--danger); text-decoration: none; font-weight: 500; }
.blocked-link:hover { text-decoration: underline; }

.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--card);
    border-radius: 8px;
    padding: 1.5rem;
    width: 95%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h2 { margin-bottom: 1rem; font-size: 1.25rem; }
.modal .form-row { margin-bottom: 0.75rem; }
.modal label { display: block; margin-bottom: 0.2rem; font-weight: 500; font-size: 0.85rem; }
.modal input, .modal select, .modal textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.85rem;
}
.modal input[type="checkbox"] { width: auto; }
.modal textarea { min-height: 70px; resize: vertical; }
.modal .form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.form-row-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-row-3col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.75rem; }
.form-row-inline { display: flex; align-items: center; gap: 0.5rem; }
.form-row-inline label { margin-bottom: 0; }

.multi-select { 
    display: flex; flex-wrap: wrap; gap: 0.3rem; padding: 0.3rem;
    border: 1px solid var(--border); border-radius: 4px;
    min-height: 38px; background: white;
}
.multi-select-item {
    display: inline-flex; align-items: center;
    padding: 0.2rem 0.4rem; background: var(--primary); color: white;
    border-radius: 3px; font-size: 0.75rem;
}
.multi-select-item .remove { margin-left: 0.3rem; cursor: pointer; font-weight: bold; }
.multi-select-add {
    padding: 0.2rem 0.4rem; border: 1px dashed var(--border);
    border-radius: 3px; font-size: 0.75rem; cursor: pointer; background: transparent;
}

.detail-view { display: none; background: var(--card); border-radius: 8px; padding: 1.5rem; margin-bottom: 1rem; }
.detail-view.active { display: block; }
.detail-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border);
    flex-wrap: wrap; gap: 1rem;
}
.detail-header h2 { font-size: 1.25rem; margin-bottom: 0.5rem; }
.detail-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.detail-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem; margin-bottom: 1.5rem;
}
.detail-field label { 
    display: block; font-size: 0.7rem; color: var(--text-muted); 
    text-transform: uppercase; margin-bottom: 0.2rem;
}
.detail-field .value { font-size: 0.9rem; }
.detail-context, .detail-prompt, .detail-result {
    background: #f8f9fa; padding: 1rem; border-radius: 4px; margin-bottom: 1rem;
}
.detail-context h3, .detail-prompt h3, .detail-result h3 { 
    font-size: 0.85rem; margin-bottom: 0.5rem; color: var(--text-muted);
}
.detail-result.has-result { background: #e8f5e9; }

.notes-section { margin-top: 1.5rem; }
.notes-section h3 { 
    font-size: 1rem; margin-bottom: 0.75rem;
    padding-bottom: 0.5rem; border-bottom: 1px solid var(--border);
}
.note-item { padding: 0.75rem; border: 1px solid var(--border); border-radius: 4px; margin-bottom: 0.5rem; }
.note-header { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.note-content { font-size: 0.9rem; white-space: pre-wrap; }
.add-note-form { margin-top: 1rem; }
.add-note-form textarea { margin-bottom: 0.5rem; }

.note-type {
    display: inline-block; padding: 0.1rem 0.3rem; border-radius: 3px;
    font-size: 0.65rem; font-weight: 600; text-transform: uppercase; margin-right: 0.5rem;
}
.note-type-comment { background: #e9ecef; color: #495057; }
.note-type-update { background: #fff3cd; color: #856404; }
.note-type-meeting { background: #d1ecf1; color: #0c5460; }

.admin-section { background: var(--card); border-radius: 8px; padding: 1.5rem; margin-bottom: 1rem; }
.admin-section h3 { margin-bottom: 1rem; font-size: 1.1rem; }
.staging-card { border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem 1rem; margin-bottom: 0.75rem; }
.staging-card.pending { border-left: 4px solid var(--warning); }
.staging-card.approved { border-left: 4px solid var(--success); }
.staging-card.rejected { border-left: 4px solid var(--danger); }
.staging-payload { font-family: monospace; font-size: 0.75rem; background: #f8f9fa; padding: 0.5rem; border-radius: 4px; max-height: 160px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; margin: 0.5rem 0; display: none; }
.scorecard-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.scorecard-stat { background: #f8f9fa; border-radius: 4px; padding: 0.3rem 0.6rem; font-size: 0.82rem; }
.scorecard-stat .label { font-size: 0.7rem; color: var(--text-muted); display: block; }
.autonomy-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.autonomy-row:last-child { border-bottom: none; }
.autonomy-cap { font-weight: 600; min-width: 120px; font-family: monospace; font-size: 0.9rem; }

/* Bash structured prompt editor */
.bash-editor { background: #f8f9fa; border: 1px solid var(--border); border-radius: 4px; padding: 0.75rem; margin-top: 0.25rem; }
.bash-editor .form-row { margin-bottom: 0.5rem; }

/* KP/JSON editor warning banner */
.kp-warning { background: #fff3cd; border: 1px solid #ffc107; border-radius: 4px; padding: 0.4rem 0.75rem; margin-bottom: 0.5rem; font-size: 0.8rem; color: #856404; }

/* Bash confirm modal */
.bash-confirm-box { background: #fff3cd; border: 2px solid var(--warning); border-radius: 6px; padding: 1rem; margin-bottom: 1rem; }
.bash-confirm-hash { font-family: monospace; font-size: 1.6rem; font-weight: bold; letter-spacing: 0.12em; color: var(--primary); margin-top: 0.25rem; }
#bash-confirm-input { font-family: monospace; font-size: 1.25rem; letter-spacing: 0.12em; width: 12ch; text-align: center; padding: 0.4rem; }

@media print {
    header, .filters, .btn, .no-print, .actions, .stats-bar, .tabs { display: none !important; }
    .container { padding: 0; }
    .table-wrapper { border: none; }
    table { font-size: 8pt; }
    th, td { padding: 4px 3px; border: 1px solid #ccc; }
}

.hidden { display: none !important; }
