/* ==========================================================================
   EthoLogger
   Behavioral Coding Application Stylesheet
   Rationalist / Control Center aesthetic
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* --------------------------------------------------------------------------
   CSS Custom Properties
   -------------------------------------------------------------------------- */
:root {
    /* Typography */
    --font-stack: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", Menlo, Consolas, monospace;

    /* Rationalist palette */
    --bg-body: #EBEBEB;
    --bg-card: #FFFFFF;
    --bg-surface: #FFFFFF;
    --bg-dark: #1A1A1A;

    /* Text */
    --text-primary: #1A1A1A;
    --text-secondary: #666666;
    --text-on-dark: #FFFFFF;
    --text-muted: #999999;

    /* Accent */
    --color-primary: #FF4C00;
    --color-primary-hover: #E04400;
    --color-primary-light: rgba(255, 76, 0, 0.1);
    --color-accent: #FF4C00;
    --color-accent-alt: #007AFF;
    --color-accent-alt-hover: #0066DD;

    /* Semantic */
    --color-success: #00C853;
    --color-warning: #FFB300;
    --color-danger: #FF1744;
    --color-danger-hover: #E01540;

    /* Borders — no shadows, hairline only */
    --border-color: #CCCCCC;
    --border-color-light: #DDDDDD;

    /* Radii — restrained */
    --radius-card: 0px;
    --radius-btn: 2px;
    --radius-input: 2px;
    --radius-pill: 999px;

    /* Spacing */
    --header-height: 40px;
    --sidebar-width: 240px;

    /* Label style (plate-engraved) */
    --label-size: 10px;
    --label-weight: 600;
    --label-spacing: 0.1em;
    --label-transform: uppercase;

    /* Density (overridden by mode) */
    --density-padding: 8px;
    --density-gap: 6px;
    --btn-min-height: 44px;

    /* Transitions */
    --transition-fast: 0.1s ease;
    --transition-normal: 0.2s ease;
}

/* --------------------------------------------------------------------------
   Reset & Base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-stack);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

a:hover {
    text-decoration: underline;
}

img,
video {
    max-width: 100%;
    display: block;
}

table {
    border-collapse: collapse;
    width: 100%;
}

/* --------------------------------------------------------------------------
   Utility Classes
   -------------------------------------------------------------------------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.hidden {
    display: none !important;
}

.text-muted {
    color: var(--text-secondary);
}

.label-caps {
    font-size: var(--label-size);
    font-weight: var(--label-weight);
    letter-spacing: var(--label-spacing);
    text-transform: var(--label-transform);
    color: var(--text-secondary);
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 7px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    color: var(--text-on-dark);
    background-color: var(--color-primary);
    border-radius: var(--radius-pill);
}

.badge-success {
    background-color: var(--color-success);
}

.badge-warning {
    background-color: var(--color-warning);
    color: var(--text-primary);
}

.badge-danger {
    background-color: var(--color-danger);
}

/* --------------------------------------------------------------------------
   View System
   -------------------------------------------------------------------------- */
.view {
    display: none;
    padding-top: var(--header-height);
}

.view.active {
    display: block;
}

/* The coder view uses a special grid layout when active */
#view-coder.active {
    display: block;
    padding-top: var(--header-height);
    height: 100vh;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Header (#app-header)
   -------------------------------------------------------------------------- */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--bg-dark);
    color: var(--text-on-dark);
    display: flex;
    align-items: center;
    padding: 0 16px;
    z-index: 1000;
    border-bottom: 1px solid var(--border-color);
}

.header-logo {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text-on-dark);
    white-space: nowrap;
    flex-shrink: 0;
}

.header-breadcrumb {
    flex: 1;
    text-align: center;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.65);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 16px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.header-project-info {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.header-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-stack);
    color: var(--text-on-dark);
    background-color: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-btn);
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
    white-space: nowrap;
}

.header-btn:hover {
    background-color: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.3);
}

.header-btn:active {
    background-color: rgba(255, 255, 255, 0.25);
}

/* Spacer below fixed header */
.header-spacer {
    height: var(--header-height);
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Landing Page (#view-landing)
   -------------------------------------------------------------------------- */
#view-landing.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.landing-hero {
    text-align: center;
    padding: 64px 24px 40px;
    max-width: 600px;
}

.landing-hero h1 {
    font-size: 48px;
    font-weight: 800;
    letter-spacing: 4px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.landing-hero .subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 36px;
    line-height: 1.6;
}

.landing-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Recent projects section */
.landing-recent {
    width: 100%;
    max-width: 900px;
    padding: 0 24px 48px;
}

.landing-recent h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.recent-projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    max-width: 100%;
}

.project-card {
    background: var(--bg-card);
    border-radius: var(--radius-card);
    padding: 20px;
    transition: border-color var(--transition-fast);
    cursor: pointer;
    position: relative;
    border: 1px solid var(--border-color);
}

.project-card:hover {
    border-color: var(--text-secondary);
}

.project-card .project-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    padding-right: 28px; /* room for delete button */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-card .project-meta {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.7;
}

.project-card .project-meta span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-card .project-delete-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-input);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    transition: color var(--transition-fast), background-color var(--transition-fast),
        border-color var(--transition-fast);
}

.project-card .project-delete-btn:hover {
    color: var(--color-danger);
    background-color: rgba(230, 57, 70, 0.08);
    border-color: rgba(230, 57, 70, 0.2);
}

.landing-empty {
    text-align: center;
    padding: 32px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* --------------------------------------------------------------------------
   Setup Page (#view-setup)
   -------------------------------------------------------------------------- */
#view-setup.active {
    display: flex;
    justify-content: center;
    padding: calc(var(--header-height) + 48px) 24px 48px;
}

.setup-card {
    background: var(--bg-card);
    border-radius: var(--radius-card);
    padding: 32px;
    width: 100%;
    max-width: 500px;
    border: 1px solid var(--border-color);
}

.setup-card h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   Form Elements
   -------------------------------------------------------------------------- */
label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="file"],
select,
textarea {
    display: block;
    width: 100%;
    height: 40px;
    padding: 8px 12px;
    font-family: var(--font-stack);
    font-size: 14px;
    color: var(--text-primary);
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-input);
    transition: border-color var(--transition-fast);
    outline: none;
}

textarea {
    height: auto;
    min-height: 80px;
    resize: vertical;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
select:focus,
textarea:focus {
    border-color: var(--color-primary);
}

input[type="color"] {
    width: 40px;
    height: 40px;
    padding: 2px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-input);
    cursor: pointer;
    background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

input.error,
select.error {
    border-color: var(--color-danger);
}

.error-text,
.form-error {
    font-size: 12px;
    color: var(--color-danger);
    margin-top: 4px;
}

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

.form-group:last-child {
    margin-bottom: 0;
}

.form-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.form-actions {
    margin-top: 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Styled file input */
input[type="file"] {
    height: auto;
    padding: 8px;
    font-size: 13px;
    cursor: pointer;
}

input[type="file"]::file-selector-button {
    font-family: var(--font-stack);
    font-size: 12px;
    font-weight: 500;
    padding: 5px 12px;
    margin-right: 10px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-input);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

input[type="file"]::file-selector-button:hover {
    background: var(--color-primary-hover);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-family: var(--font-stack);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    border: 1px solid transparent;
    border-radius: var(--radius-btn);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast),
        border-color var(--transition-fast);
    white-space: nowrap;
    text-decoration: none;
    outline: none;
    user-select: none;
}

.btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.btn:active {
    background-color: #E0E0E0;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Primary */
.btn-primary {
    background-color: var(--color-primary);
    color: var(--text-on-dark);
    border-color: var(--color-primary);
}

.btn-primary:hover {
    background-color: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

/* Secondary (outlined) */
.btn-secondary {
    background-color: transparent;
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn-secondary:hover {
    background-color: var(--color-primary);
    color: var(--text-on-dark);
}

/* Danger */
.btn-danger {
    background-color: var(--color-danger);
    color: var(--text-on-dark);
    border-color: var(--color-danger);
}

.btn-danger:hover {
    background-color: var(--color-danger-hover);
    border-color: var(--color-danger-hover);
}

/* Success */
.btn-success {
    background-color: var(--color-success);
    color: var(--text-on-dark);
    border-color: var(--color-success);
}

.btn-success:hover {
    background-color: #27b0a3;
    border-color: #27b0a3;
}

/* Size variants */
.btn-large {
    padding: 14px 28px;
    font-size: 16px;
    font-weight: 600;
    border-radius: var(--radius-card);
}

.btn-small {
    padding: 5px 10px;
    font-size: 12px;
}

/* Ghost — minimal style, good for icon-only buttons */
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

/* --------------------------------------------------------------------------
   Ethogram Builder (#view-ethogram)
   -------------------------------------------------------------------------- */
#view-ethogram.active {
    display: flex;
    flex-direction: column;
    padding: calc(var(--header-height) + 24px) 24px 24px;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

.ethogram-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.ethogram-toolbar h2 {
    font-size: 18px;
    font-weight: 600;
    margin-right: auto;
}

/* Add-behavior row */
.add-behavior-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-wrap: wrap;
    background: var(--bg-card);
    border: 1px solid var(--border-color-light);
    border-radius: var(--radius-card);
    padding: 16px;
    margin-bottom: 20px;
}

.add-behavior-form .form-group {
    margin-bottom: 0;
}

.add-behavior-form .form-group-name {
    flex: 2;
    min-width: 140px;
}

.add-behavior-form .form-group-category {
    flex: 1;
    min-width: 100px;
}

.add-behavior-form .form-group-type {
    flex: 0 0 120px;
}

.add-behavior-form .form-group-key {
    flex: 0 0 70px;
}

.add-behavior-form .form-group-key input {
    max-width: 50px;
    text-align: center;
    font-family: var(--font-mono);
    font-weight: 600;
    text-transform: uppercase;
}

.add-behavior-form .form-group-color {
    flex: 0 0 auto;
}

.add-behavior-form .form-group-action {
    flex: 0 0 auto;
}

/* Behavior table */
.ethogram-table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border-color-light);
    border-radius: var(--radius-card);
    overflow: hidden;
}

.ethogram-table {
    width: 100%;
    font-size: 13px;
}

.ethogram-table thead {
    background: var(--bg-body);
}

.ethogram-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.ethogram-table td {
    padding: 10px 14px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color-light);
}

.ethogram-table tbody tr:nth-child(even) {
    background-color: #fafbfc;
}

.ethogram-table tbody tr:hover {
    background-color: #f0f4ff;
}

.ethogram-table tbody tr:last-child td {
    border-bottom: none;
}

/* Color swatch in table */
.color-swatch {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    vertical-align: middle;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Key badge in table */
.key-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 24px;
    padding: 0 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-on-dark);
    background-color: var(--bg-dark);
    border-radius: 4px;
    text-transform: uppercase;
}

/* Table action buttons */
.table-actions {
    display: flex;
    gap: 6px;
}

.table-actions button {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-input);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: all var(--transition-fast);
}

.table-actions button:hover {
    background: var(--bg-body);
    color: var(--text-primary);
    border-color: #ccc;
}

.table-actions .btn-delete:hover {
    color: var(--color-danger);
}

/* Ethogram footer with next button */
.ethogram-footer {
    padding: 20px 0;
    text-align: center;
    border-color: rgba(230, 57, 70, 0.3);
    background-color: rgba(230, 57, 70, 0.06);
}

/* --------------------------------------------------------------------------
   Coder Layout (#view-coder) — Control Center 3-zone grid
   -------------------------------------------------------------------------- */
.coder-layout {
    display: grid;
    grid-template-areas: "sidebar main datafeed";
    grid-template-columns: var(--sidebar-width) 1fr 260px;
    grid-template-rows: calc(100vh - var(--header-height));
    height: calc(100vh - var(--header-height));
    background: var(--bg-body);
    overflow: hidden;
}

/* ---- Sidebar ---- */
.panel-sidebar {
    grid-area: sidebar;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color-light);
}

.sidebar-section .label-caps {
    display: block;
    margin-bottom: 8px;
}

.sidebar-field {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-color-light);
}

.sidebar-field:last-child {
    border-bottom: none;
}

.sidebar-field-label {
    font-size: var(--label-size);
    text-transform: uppercase;
    letter-spacing: var(--label-spacing);
    color: var(--text-muted);
}

.sidebar-field-value {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    text-align: right;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-subject-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-transport {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-tools {
    display: flex;
    flex-direction: column;
}

.sidebar-tools .label-caps {
    margin-bottom: 8px;
}

.btn-tool {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-family: var(--font-stack);
    font-size: 12px;
    font-weight: 500;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    cursor: pointer;
    color: var(--text-primary);
    transition: background-color var(--transition-fast);
    margin-bottom: 4px;
}

.btn-tool:hover {
    background: var(--bg-body);
}

/* Scan Mode sidebar panel */
.sidebar-scan {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.scan-config-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
}

.scan-config-row label {
    flex: 0 0 56px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 10px;
}

.scan-config-row input[type="number"] {
    flex: 1 1 auto;
    width: 0;
    padding: 4px 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    color: var(--text-primary);
}

.scan-unit {
    color: var(--text-secondary);
    font-size: 10px;
    width: 12px;
    text-align: left;
}

.scan-behavior-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 11px;
    color: var(--text-primary);
    margin: 4px 0;
}

.scan-behavior-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.scan-status {
    margin: 6px 0 0;
    font-size: 10px;
    line-height: 1.35;
    color: var(--text-secondary);
    min-height: 24px;
}

/* URL input row (Load from URL flow) */
.url-input-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.url-input-row input[type="text"] {
    flex: 1 1 100%;
    padding: 6px 8px;
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    color: var(--text-primary);
}

.url-input-row .btn-tool {
    flex: 1 1 auto;
    margin-bottom: 0;
}

.url-input-hint {
    flex: 1 1 100%;
    margin: 4px 0 0;
    font-size: 10px;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* Mode switcher */
.mode-switcher {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    overflow: hidden;
}

.mode-btn {
    flex: 1;
    padding: 6px 12px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-surface);
    border: none;
    border-right: 1px solid var(--border-color);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.mode-btn:last-child {
    border-right: none;
}

.mode-btn.active {
    background: var(--text-primary);
    color: var(--text-on-dark);
}

/* ---- Main Stage ---- */
.panel-main {
    grid-area: main;
    display: grid;
    grid-template-rows: 300px 6px 1fr 6px 180px;
    overflow: hidden;
    background: var(--bg-body);
}

.panel-behavior-stage {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: var(--density-padding);
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
}

.behavior-stage-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px 8px;
}

/* ---- Data Feed (right panel) ---- */
.panel-datafeed {
    grid-area: datafeed;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.datafeed-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.datafeed-count {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
}

.datafeed-log {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.6;
}

.datafeed-entry {
    padding: 2px 12px;
    border-bottom: 1px solid var(--border-color-light);
    display: flex;
    gap: 8px;
    white-space: nowrap;
}

.datafeed-entry .df-time {
    color: var(--text-muted);
    min-width: 80px;
}

.datafeed-entry .df-behavior {
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
}

.datafeed-entry .df-action {
    color: var(--text-secondary);
    margin-left: auto;
}

.datafeed-log::-webkit-scrollbar {
    width: 4px;
}

.datafeed-log::-webkit-scrollbar-track {
    background: transparent;
}

.datafeed-log::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 2px;
}

/* ---- LED indicators ---- */
.led-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.led-idle {
    background: #999;
}

.led-recording {
    background: var(--color-success);
    box-shadow: 0 0 6px var(--color-success), 0 0 12px rgba(0, 200, 83, 0.3);
    animation: led-pulse 1.5s ease-in-out infinite;
}

@keyframes led-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--color-success); }
    50% { opacity: 0.7; box-shadow: 0 0 2px var(--color-success); }
}

/* ---- Record button (status indicator) ---- */
.btn-record {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    cursor: default;
    width: 100%;
}

.btn-record.recording {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: white;
    animation: record-pulse 2s ease-in-out infinite;
}

@keyframes record-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}

/* ---- Session timer ---- */
.header-center {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
    margin-right: 16px;
}

.session-timer {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
    letter-spacing: 0.05em;
}

.resize-handle-row {
    height: 6px;
    background: var(--bg-body);
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    user-select: none;
}

.resize-handle-grip {
    width: 40px;
    height: 3px;
    border-radius: 2px;
    background: var(--border-color);
    transition: background var(--transition-fast);
}

.resize-handle-row:hover .resize-handle-grip,
.resize-handle-row.dragging .resize-handle-grip {
    background: var(--color-accent);
}

/* --------------------------------------------------------------------------
   Video Panel (.panel-video)
   -------------------------------------------------------------------------- */
.panel-video {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    overflow: hidden;
}

.video-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    min-height: 0;
    overflow: hidden;
}

.video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    border-radius: 0;
}

/* Placeholder when no video loaded */
.video-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 14px;
    padding: 24px;
    text-align: center;
}

.video-placeholder .icon {
    font-size: 36px;
    opacity: 0.4;
}

/* Video controls bar */
.video-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color-light);
    background: var(--bg-card);
}

.video-controls .btn-play {
    padding: 6px 14px;
    font-size: 14px;
    font-weight: 600;
    background: var(--color-primary);
    color: var(--text-on-dark);
    border: none;
    border-radius: var(--radius-btn);
    cursor: pointer;
    transition: background-color var(--transition-fast);
    font-family: var(--font-stack);
}

.video-controls .btn-play:hover {
    background: var(--color-primary-hover);
}

/* Speed buttons group */
.speed-group {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    overflow: hidden;
}

.speed-group button {
    padding: 4px 8px;
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--bg-card);
    border: none;
    border-right: 1px solid var(--border-color);
    cursor: pointer;
    color: var(--text-secondary);
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.speed-group button:last-child {
    border-right: none;
}

.speed-group button:hover {
    background: var(--bg-body);
}

.speed-group button.active {
    background: var(--color-primary);
    color: var(--text-on-dark);
}

/* Frame step buttons */
.frame-step-btn {
    padding: 4px 8px;
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-input);
    cursor: pointer;
    color: var(--text-primary);
    transition: background-color var(--transition-fast);
}

.frame-step-btn:hover {
    background: var(--bg-body);
}

/* Time display */
.time-display {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    padding: 0 4px;
    white-space: nowrap;
}

/* Seek bar */
.seek-bar-wrapper {
    width: 100%;
    padding: 4px 12px 6px;
    background: var(--bg-card);
}

.seek-bar {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    outline: none;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.seek-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    border: 2px solid var(--bg-card);
    transition: transform var(--transition-fast);
}

.seek-bar::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.seek-bar::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    border: 2px solid var(--bg-card);
}

/* Load video button (styled file input trigger) */
.load-video-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    font-family: var(--font-stack);
    font-size: 12px;
    font-weight: 500;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    cursor: pointer;
    color: var(--text-primary);
    transition: background-color var(--transition-fast);
}

.load-video-btn:hover {
    background: #e8ecf1;
}

/* --------------------------------------------------------------------------
   Coding Panel (legacy — kept for modifier popup positioning)
   -------------------------------------------------------------------------- */
.panel-coding {
    display: none;
}

.behavior-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--density-gap);
}

.behavior-btn {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    min-height: var(--btn-min-height);
    padding: 10px 12px;
    padding-left: 16px;
    font-family: var(--font-stack);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    cursor: pointer;
    transition: background-color var(--transition-fast),
                border-color var(--transition-fast);
    user-select: none;
    outline: none;
    line-height: 1.3;
}

/* Left-edge color stripe */
.behavior-btn::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background-color: var(--behavior-color, var(--color-accent));
    border-radius: 2px 0 0 2px;
}

.behavior-btn:hover {
    background-color: #F5F5F5;
    border-color: var(--text-secondary);
}

/* Mechanical "pressed" state */
.behavior-btn:active {
    background-color: #E0E0E0;
    border-color: #999;
    border-style: inset;
}

/* Key badge — top right, monospaced */
.behavior-btn .key-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    min-width: 20px;
    height: 18px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    border-radius: 2px;
    color: var(--text-secondary);
}

/* Active state (recording) — mechanical toggle "down" */
.behavior-btn.active {
    background-color: #E8E8E8;
    border-style: inset;
    border-color: #999;
}

/* LED indicator on active buttons */
.behavior-btn.active::after {
    content: '';
    position: absolute;
    top: 6px;
    left: 10px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-success);
    box-shadow: 0 0 4px var(--color-success);
}

/* Flash for point events */
.behavior-btn.flash {
    animation: mechanical-flash 0.2s ease-out;
}

@keyframes mechanical-flash {
    0% { background-color: var(--bg-surface); }
    40% { background-color: #D0D0D0; border-style: inset; }
    100% { background-color: var(--bg-surface); }
}

/* Subject selector (now in sidebar) */
.subject-selector {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-wrap: wrap;
}

.subject-btn {
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-btn);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.subject-btn.active {
    background: var(--text-primary);
    color: var(--text-on-dark);
    border-color: var(--text-primary);
}

.subject-btn:hover:not(.active) {
    background: var(--bg-body);
    color: var(--text-primary);
}

/* Modifier popup */
.modifier-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    border: 2px solid var(--border-color);
    padding: 20px;
    z-index: 2000;
    min-width: 260px;
    max-width: 400px;
}

.modifier-popup-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.modifier-popup-row {
    margin-bottom: 12px;
}

.modifier-option-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.modifier-option-btn {
    padding: 4px 12px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modifier-option-btn.selected {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.modifier-option-btn:hover:not(.selected) {
    background: rgba(255,255,255,0.06);
}

.modifier-popup-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color-light);
}

/* Scrollbar styling for behavior stage */
.panel-behavior-stage::-webkit-scrollbar {
    width: 4px;
}

.panel-behavior-stage::-webkit-scrollbar-track {
    background: transparent;
}

.panel-behavior-stage::-webkit-scrollbar-thumb {
    background: #d0d0d0;
    border-radius: 2px;
}

/* --------------------------------------------------------------------------
   Timeline Panel (.panel-timeline)
   -------------------------------------------------------------------------- */
.panel-timeline {
    background: var(--bg-dark);
    overflow: hidden;
    position: relative;
}

.panel-timeline canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* --------------------------------------------------------------------------
   IRR View (#view-irr)
   -------------------------------------------------------------------------- */
#view-irr.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: calc(var(--header-height) + 32px) 24px 32px;
}

.irr-container {
    width: 100%;
    max-width: 800px;
}

.irr-container h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 24px;
}

.irr-setup {
    background: var(--bg-card);
    border-radius: var(--radius-card);
    padding: 24px;
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.irr-results {
    background: var(--bg-card);
    border-radius: var(--radius-card);
    padding: 24px;
    border: 1px solid var(--border-color);
}

.irr-results h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* IRR results table */
.irr-table {
    width: 100%;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-input);
    overflow: hidden;
}

.irr-table th,
.irr-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-color-light);
}

.irr-table th {
    background: var(--bg-body);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
}

.irr-table tbody tr:nth-child(even) {
    background: #fafbfc;
}

.irr-table tbody tr:last-child td {
    border-bottom: none;
}

/* Kappa interpretation colors */
.kappa-poor {
    color: var(--color-danger);
    font-weight: 600;
}

.kappa-slight {
    color: #e67e22;
    font-weight: 600;
}

.kappa-fair {
    color: var(--color-warning);
    font-weight: 600;
}

.kappa-moderate {
    color: var(--color-primary);
    font-weight: 600;
}

.kappa-substantial {
    color: var(--color-success);
    font-weight: 600;
}

.kappa-almost-perfect {
    color: #0d7d3c;
    font-weight: 600;
}

/* --------------------------------------------------------------------------
   Toast Notifications (#toast-container)
   -------------------------------------------------------------------------- */
#toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background-color: var(--bg-dark);
    color: var(--text-on-dark);
    padding: 10px 20px;
    border-radius: var(--radius-btn);
    font-size: 13px;
    border: 1px solid var(--border-color);
    animation: fadeIn 0.2s ease-out;
    pointer-events: auto;
    max-width: 400px;
    text-align: center;
}

.toast.fade-out {
    animation: fadeOut 0.3s ease-in forwards;
}

/* --------------------------------------------------------------------------
   Help Overlay (#help-overlay)
   -------------------------------------------------------------------------- */
#help-overlay {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: none;
    align-items: center;
    justify-content: center;
}

#help-overlay.active {
    display: flex;
}

.help-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s ease-out;
}

.help-card {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-card);
    border: 1px solid var(--border-color);
    padding: 32px;
    max-width: 520px;
    width: calc(100% - 48px);
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    z-index: 1;
    animation: fadeIn 0.2s ease-out;
}

.help-card h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
}

.help-card .help-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-input);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 16px;
    transition: all var(--transition-fast);
}

.help-card .help-close:hover {
    background: var(--bg-body);
    color: var(--text-primary);
}

.shortcut-list {
    list-style: none;
}

.shortcut-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color-light);
    font-size: 13px;
}

.shortcut-list li:last-child {
    border-bottom: none;
}

.shortcut-list .shortcut-key {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    background: var(--bg-body);
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.shortcut-list .shortcut-desc {
    color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   Animations / Keyframes
   -------------------------------------------------------------------------- */
/* Legacy pulse/flash removed — replaced by mechanical-flash and led-pulse */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* Spin animation (for loading indicators) */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* --------------------------------------------------------------------------
   Lab / Field Mode density overrides
   -------------------------------------------------------------------------- */
.mode-lab {
    --density-padding: 8px;
    --density-gap: 6px;
    --btn-min-height: 44px;
}

.mode-field {
    --density-padding: 24px;
    --density-gap: 16px;
    --btn-min-height: 72px;
}

.mode-field .behavior-buttons {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.mode-field .behavior-btn {
    font-size: 18px;
    font-weight: 700;
    padding: 16px 20px;
    padding-left: 24px;
    background: #FFFFFF;
    color: #000000;
    border: 2px solid #000000;
}

.mode-field .behavior-btn:active {
    background: #000000;
    color: #FFFFFF;
}

.mode-field .behavior-btn .key-badge {
    font-size: 14px;
    min-width: 28px;
    height: 24px;
    background: #000000;
    color: #FFFFFF;
    border-color: #000000;
}

/* Collapse sidebar in field mode */
.mode-field .panel-sidebar .sidebar-section:not(.sidebar-mode):not(.sidebar-tools) {
    display: none;
}

.mode-field .panel-datafeed {
    display: none;
}

.mode-field .coder-layout {
    grid-template-areas: "sidebar main";
    grid-template-columns: 60px 1fr;
}

.mode-field .panel-sidebar {
    overflow: hidden;
}

.mode-field .sidebar-section {
    padding: 8px;
}

.mode-field .mode-btn {
    padding: 4px 2px;
    font-size: 8px;
}

/* --------------------------------------------------------------------------
   Responsive — below 900px
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
    .coder-layout {
        grid-template-areas:
            "main";
        grid-template-columns: 1fr;
        grid-template-rows: calc(100vh - var(--header-height));
    }

    .panel-sidebar {
        display: none;
    }

    .panel-datafeed {
        display: none;
    }

    .resize-handle-row {
        display: none;
    }

    .panel-main {
        grid-template-rows: auto 1fr 0 0 120px;
    }

    .video-container {
        min-height: 200px;
        max-height: 50vh;
    }

    .landing-actions {
        flex-direction: column;
        align-items: center;
    }

    .landing-actions .btn-large {
        width: 100%;
        max-width: 280px;
    }

    .landing-hero {
        padding: 40px 20px 28px;
    }

    .landing-hero h1 {
        font-size: 36px;
    }

    .add-behavior-form {
        gap: 10px;
    }

    .add-behavior-form .form-group-name,
    .add-behavior-form .form-group-category {
        flex: 1 1 100%;
    }

    .add-behavior-form .form-group-type {
        flex: 1 1 calc(50% - 5px);
    }

    .add-behavior-form .form-group-key {
        flex: 0 0 70px;
    }

    .recent-projects-grid {
        grid-template-columns: 1fr;
    }

    .setup-card {
        padding: 24px;
    }

    .header-project-info {
        display: none;
    }

    .header-center {
        display: none;
    }

    .header-breadcrumb {
        font-size: 12px;
    }

    .panel-timeline {
        min-height: 120px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    #app-header {
        padding: 0 10px;
    }

    .header-logo {
        font-size: 14px;
        letter-spacing: 1.5px;
    }

    .landing-hero h1 {
        font-size: 28px;
    }

    .behavior-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .video-controls {
        padding: 6px 8px;
        gap: 4px;
    }

    .help-card {
        padding: 24px 20px;
    }
}

/* --------------------------------------------------------------------------
   Print styles — hide everything but essential content
   -------------------------------------------------------------------------- */
@media print {
    #app-header,
    .video-controls,
    .seek-bar-wrapper,
    .panel-timeline,
    .panel-sidebar,
    .panel-datafeed,
    #toast-container,
    #help-overlay {
        display: none !important;
    }

    body {
        background: white;
    }

    .header-spacer {
        display: none;
    }

    .coder-layout {
        display: block;
        height: auto;
    }
}
