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

:root {
    --bg: #0e1117;
    --surface: #1a1a2e;
    --surface2: #262730;
    --border: #3a3a4a;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #4a9eff;
    --red: #ff4b4b;
    --green: #2ea043;
    --field-green: #2d8a4e;
    --radius: 6px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    color-scheme: dark;
    font-size: 14px;
    line-height: 1.4;
}

/* ====== Views ====== */
.view { display: block; }
.hidden { display: none !important; }

/* ====== Buttons ====== */
.btn {
    background: #444;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    transition: background .15s;
    white-space: nowrap;
}
.btn:hover { background: #555; }
.btn:active { background: #666; }
.btn.active { background: var(--accent); }
.btn-primary { background: var(--accent); }
.btn-primary:hover { background: #3a8aee; }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-tiny { padding: 4px 7px; font-size: 11px; }
.btn-lg { padding: 12px 28px; font-size: 16px; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #ff6b6b; }

.btn-tag {
    font-weight: 600;
    padding: 6px 12px;
    font-size: 12px;
}
.btn-tag.tag-opponent_bypassed { background: #4a9eff; }
.btn-tag.tag-opponent_bypassed:hover { background: #6ab0ff; }
.btn-tag.tag-one_vs_one { background: #b0b030; color: #fff; }
.btn-tag.tag-one_vs_one:hover { background: #c8c840; }
.btn-tag.tag-shot { background: #ff4b4b; }
.btn-tag.tag-shot:hover { background: #ff6b6b; }
.btn-tag.tag-cross { background: #ff9f43; }
.btn-tag.tag-cross:hover { background: #ffb76b; }
.btn-tag.tag-line_dribbled { background: #a855f7; }
.btn-tag.tag-line_dribbled:hover { background: #bf7fff; }
.btn-tag.tag-ball_won { background: #2ea043; }
.btn-tag.tag-ball_won:hover { background: #3fb950; }
.btn-tag.tag-ball_lost { background: #ef4444; }
.btn-tag.tag-ball_lost:hover { background: #f87171; }
.btn-tag.tag-opponent_shot { background: #f97316; }
.btn-tag.tag-opponent_shot:hover { background: #fb923c; }
.btn-tag.flash { opacity: .6; transition: opacity .1s; }

.btn-dir { font-size: 18px; padding: 4px 10px; }

/* ====== Card ====== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

/* ====== Forms ====== */
input[type="text"],
input[type="number"],
select {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
}

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

/* ====== Toggle ====== */
.toggle-label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    user-select: none;
}
.toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* ====== Sessions View ====== */
.sessions-container {
    max-width: 700px;
    margin: 40px auto;
    padding: 0 20px;
}
.sessions-container h1 { margin-bottom: 20px; }
.sessions-actions { display: flex; gap: 12px; align-items: center; }
.btn-help { background: var(--surface2); color: var(--text-muted); text-decoration: none; }
.btn-help:hover { background: var(--border); color: var(--text); }
.sessions-container h2 { margin: 24px 0 12px; color: var(--text-muted); font-size: 16px; }

.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color .15s;
}
.session-item:hover { border-color: var(--accent); }
.session-item .meta { flex: 1; }
.session-item .meta .teams { font-weight: 600; }
.session-item .meta .info { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.session-item .actions { display: flex; gap: 6px; }

/* ====== Tagging View ====== */
#view-tagging {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
#tagging-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
#header-session-name { font-weight: 600; flex: 1; }
#header-controls { display: flex; gap: 10px; align-items: center; }

#kickoff-group {
    display: flex;
    align-items: center;
    gap: 4px;
}
.kickoff-lbl {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.kickoff-input {
    width: 42px;
    padding: 3px 4px !important;
    font-size: 12px;
    text-align: center;
}
.kickoff-sep {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
}
#btn-save-kickoff {
    transition: background .2s;
}
#btn-save-kickoff.saved {
    background: var(--green);
}

#direction-toggle {
    display: flex;
    gap: 2px;
}

/* Main content */
#main-content {
    display: flex;
    flex: 3;
    min-height: 0;
    overflow: hidden;
}

#video-area {
    flex: 1.2;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#video-selector {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

#video-picker {
    display: flex;
    align-items: center;
    gap: 8px;
}
.text-muted { color: var(--text-muted); font-size: 12px; }

#video-loaded {
    display: flex;
    align-items: center;
    gap: 8px;
}
#loaded-video-name {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 260px;
}
.kickoff-label {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    white-space: nowrap;
}
.kickoff-label input {
    width: 55px;
    padding: 3px 6px !important;
    font-size: 12px;
}

#video-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0 8px;
}

#video-player {
    width: 100%;
    max-height: calc(100% - 24px);
    background: #000;
    border-radius: var(--radius);
}

#seek-bar {
    width: 100%;
    height: 6px;
    margin-top: 4px;
    cursor: pointer;
    accent-color: var(--accent);
}

#field-area {
    flex: 0.8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 8px;
    min-width: 0;
}

#football-field {
    width: 100%;
    max-height: 100%;
    border-radius: var(--radius);
}

#field-status {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: center;
    min-height: 18px;
}

/* Controls bar */
#controls-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--surface2);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    gap: 4px;
    align-items: center;
}
.control-group .label {
    color: var(--text-muted);
    font-size: 11px;
    margin-right: 2px;
}

#speed-buttons { display: flex; gap: 2px; }

.time-displays { gap: 6px; }
.time-display {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 15px;
    padding: 4px 10px;
    background: var(--surface);
    border-radius: var(--radius);
    min-width: 60px;
    text-align: center;
}

/* Tag buttons bar */
#tag-buttons-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 12px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* Attribute selection bar */
#attr-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 34px;
}
.attr-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.btn-attr {
    font-weight: 600;
    background: var(--accent);
}
.btn-attr:hover {
    background: #3a8aee;
}

/* Tag table */
#tag-table-area {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 8px;
    min-height: 80px;
}

#tag-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
#tag-table th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    background: var(--bg);
}
#tag-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
}
#tag-table tbody tr { cursor: pointer; transition: background .1s; }
#tag-table tbody tr:hover { background: var(--surface); }
#tag-table tbody tr .btn-delete {
    visibility: hidden;
    font-size: 11px;
    padding: 2px 8px;
}
#tag-table tbody tr:hover .btn-delete { visibility: visible; }

.tag-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    color: white;
}
.tag-type-badge.opponent_bypassed { background: #4a9eff; }
.tag-type-badge.one_vs_one { background: #b0b030; }
.tag-type-badge.shot { background: #ff4b4b; }
.tag-type-badge.cross { background: #ff9f43; }
.tag-type-badge.line_dribbled { background: #a855f7; }
.tag-type-badge.ball_won { background: #2ea043; }
.tag-type-badge.ball_lost { background: #ef4444; }
.tag-type-badge.opponent_shot { background: #f97316; }

#tag-table-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
}

/* Export bar */
#export-bar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface2);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* Dialog overlay */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.dialog {
    min-width: 400px;
    max-width: 90vw;
}

/* ====== Responsive ====== */
@media (max-width: 900px) {
    #main-content { flex-direction: column; }
    #field-area { max-height: 300px; }
}

/* Field crosshair cursors */
#football-field.mode-start #field-click-area { cursor: crosshair; }
#football-field.mode-end #field-click-area { cursor: crosshair; }
