:root {
    --bg: #0f172a;
    --card: #1e293b;
    --accent: #38bdf8;
    --danger: #f87171;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #334155;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', sans-serif;
    margin: 0;
    background: linear-gradient(180deg, #0f172a 0%, #111b2f 50%, #12203a 100%);
    color: var(--text);
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(32% 32% at 18% 18%, rgba(56,189,248,0.16), transparent 62%),
        radial-gradient(28% 28% at 82% 12%, rgba(255,255,255,0.12), transparent 58%),
        radial-gradient(36% 36% at 72% 78%, rgba(56,189,248,0.14), transparent 62%),
        radial-gradient(32% 32% at 12% 82%, rgba(255,255,255,0.08), transparent 58%);
    opacity: 0.65;
    filter: blur(36px);
    mix-blend-mode: screen;
    animation: drift 80s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes drift {
    0% { background-position: 0% 0%, 0% 0%, 0% 0%, 0% 0%; }
    25% { background-position: 6% 12%, -12% 6%, 10% -8%, -10% 14%; }
    50% { background-position: -8% 10%, 14% -10%, -12% 12%, 8% -14%; }
    75% { background-position: 12% -8%, 8% 14%, -10% -12%, 14% 8%; }
    100% { background-position: 0% 0%, 0% 0%, 0% 0%, 0% 0%; }
}

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

a:hover {
    text-decoration: underline;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    background: rgba(15,23,42,0.9);
    backdrop-filter: blur(6px);
    position: sticky;
    top: 0;
    z-index: 2000;
}

.top-bar.non-sticky {
    position: static !important;
    top: auto !important;
    z-index: auto !important;
}

.content {
    padding: 2rem;
    display: grid;
    gap: 1.5rem;
    position: relative;
    z-index: 1;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.card h2 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.content-grid {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.folder-card {
    padding: 1rem;
}

.folder-list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.folder-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.folder-item:hover,
.folder-item.active {
    background: rgba(56,189,248,0.08);
    border-color: var(--accent);
}

.folder-item.drop-target {
    background: rgba(56,189,248,0.08);
    border-color: var(--accent);
}

.folder-item .count {
    color: var(--muted);
    font-size: 0.85rem;
}

.folder-create-drop {
    margin-top: 0.75rem;
    padding: 0.6rem 0.75rem;
    border: 1px dashed var(--border);
    border-radius: 8px;
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
}

.folder-create-drop.drop-target {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(56,189,248,0.05);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.table-actions {
    gap: 0.75rem;
}

.title-group {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.folder-heading {
    margin: 0;
    font-size: 1.35rem;
    color: #c7d2e2;
    font-weight: 700;
}

.action-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.search-input,
#search-input {
    background: rgba(15,23,42,0.6);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 0.45rem 0.9rem;
    min-width: 180px;
}

.btn {
    background: var(--accent);
    border: none;
    color: #0f172a;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
}

.btn.ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn.danger {
    background: var(--danger);
    color: #0f172a;
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(56,189,248,0.08);
}

.table-wrapper {
    overflow-x: auto;
}

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

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

th {
    text-align: left;
}

th[data-sort] {
    cursor: pointer;
    user-select: none;
}

th[data-sort].sorted-asc::after,
th[data-sort].sorted-desc::after {
    content: '';
    display: inline-block;
    margin-left: 6px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
}

th[data-sort].sorted-asc::after {
    border-bottom: 6px solid var(--accent);
}

th[data-sort].sorted-desc::after {
    border-top: 6px solid var(--accent);
}

tbody tr {
    cursor: pointer;
    transition: background 0.2s;
}

tbody tr:hover {
    background: rgba(56,189,248,0.05);
}

.muted {
    color: var(--muted);
    font-size: 0.9rem;
}

.summary-container {
    white-space: pre-line;
}

.summary-container.collapsed {
    max-height: 4.8em;
    overflow: hidden;
}

.summary-container.expanded {
    max-height: none;
}

.summary-container .link-button {
    padding-left: 0;
}

.small {
    font-size: 0.85rem;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.32rem 0.85rem;
    border-radius: 999px;
    font-size: 0.8rem;
    text-transform: capitalize;
    line-height: 1.2;
    margin: 2px 0;
}

.status-duration {
    display: inline-flex;
    align-items: center;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    margin-left: 0.35rem;
    background: rgba(148,163,184,0.2);
    color: var(--muted);
    line-height: 1.2;
    margin-top: 2px;
}

.status-queued { background: rgba(59,130,246,0.2); color: #93c5fd; }
.status-uploading { background: rgba(59,130,246,0.2); color: #93c5fd; }
.status-processing { background: rgba(250,204,21,0.2); color: #fde047; }
.status-done { background: rgba(34,197,94,0.2); color: #bbf7d0; }
.status-error { background: rgba(248,113,113,0.2); color: #fecaca; }

.progress {
    height: 6px;
    background: rgba(148,163,184,0.2);
    border-radius: 999px;
    margin-top: 0.4rem;
}

.progress > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    width: 0;
}

.tag-editor, .tag-inline {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.tag-input {
    background: rgba(15,23,42,0.6);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 0.3rem 0.8rem;
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
}

.alert.success { background: rgba(34,197,94,0.15); color: #4ade80; }
.alert.error { background: rgba(248,113,113,0.15); color: #fca5a5; }

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.auth-card {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 2rem;
    border-radius: 12px;
    width: 320px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    text-align: left;
}

.auth-card h1 {
    margin: 0 0 0.5rem;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.auth-card input {
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(15,23,42,0.6);
    color: var(--text);
}

.detail-grid {
    display: flex;
    gap: 1.2rem;
    align-items: flex-start;
}

.detail-main {
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    width: 65%;
}

.detail-main > .title-row,
.detail-main > audio,
.detail-main > p {
    padding: 0;
}

.info-line {
    margin: 0;
}

.detail-main audio {
    width: 100%;
    margin-bottom: 0.2rem;
}

.actions-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.detail-sidebar {
    width: 35%;
    padding-right: 0.5rem;
    margin-top: 7.8rem;
    align-self: flex-start;
    position: sticky;
    top: 100px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.detail-head {
    position: sticky;
    top: 80px;
    background: var(--bg);
    padding-bottom: 0.4rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.card.nested {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 400px;
}

.title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.title-row h1 {
    margin: 0;
    font-size: 1.7rem;
    outline: none;
    border-bottom: 1px dashed transparent;
}

.title-row h1:focus {
    border-color: var(--accent);
}

.full-width {
    grid-column: 1 / -1;
}

.transcript {
    white-space: pre-wrap;
    background: rgba(15,23,42,0.6);
    padding: 1rem;
    border-radius: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.transcript.compact {
    max-height: 200px;
}

.utterance-list {
    max-height: none;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.utterance {
    padding: 0.6rem;
    border: 1px solid var(--border);
    cursor: pointer;
    margin: 0;
}

.utterance.active {
    border-color: var(--accent);
    background: rgba(56,189,248,0.1);
}

.utterance-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.25rem;
}

.utterance .speaker-label {
    display: block;
    font-weight: 600;
    color: #cdd7e5;
}

.utterance .timecode {
    margin-left: auto;
    color: var(--muted);
    font-weight: 500;
    font-size: 0.9rem;
}

.btn.full {
    width: 100%;
    text-align: center;
}

.link-button {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 0.25rem 0;
    text-align: left;
}

.link-button:hover {
    text-decoration: underline;
}

.action-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.speaker-editor {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.speaker-row {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.speaker-row label {
    font-size: 0.85rem;
    color: var(--muted);
}

.speaker-row input {
    padding: 0.4rem 0.7rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: rgba(15,23,42,0.5);
    color: var(--text);
}

.card label {
    font-size: 0.85rem;
    color: var(--muted);
    display: block;
    margin-bottom: 0.2rem;
}

.card input[type="text"],
.card input[type="datetime-local"] {
    width: 100%;
    padding: 0.45rem 0.7rem;
    margin-bottom: 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(15,23,42,0.6);
    color: var(--text);
}

.summary-card #summary-status {
    min-height: 1.2rem;
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

.summary-clamp {
    max-height: 6.5em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    transition: max-height 0.2s ease;
}

.summary-clamp.expanded {
    max-height: none;
    -webkit-line-clamp: unset;
}

.summary-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.meta-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: rgba(56,189,248,0.15);
    color: #bae6fd;
    border: 1px solid var(--border);
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
    align-items: stretch;
}

.summary-spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(226,232,240,0.4);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-left: 0.4rem;
}

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

.tag-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}

.tag-badge {
    background: rgba(56,189,248,0.15);
    color: #bae6fd;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin: 2px;
}

.tag-badge button {
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 0.85rem;
}

.tag-editor.add input {
    flex: 1;
}

.transcript.collapsed {
    display: none;
}

.file-label {
    color: var(--accent);
    cursor: pointer;
}

@media (max-width: 960px) {
    .detail-grid {
        flex-direction: column;
    }

    .detail-main {
        width: 100%;
    }

    .detail-sidebar {
        width: 100%;
        padding-right: 0;
        margin-top: 1.5rem;
        position: static;
        max-height: none;
        overflow: visible;
    }

    .detail-head {
        position: static;
    }

.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 9999;
    pointer-events: none;
}

.toast-container .toast {
    pointer-events: auto;
}

.toast-container .toast {
    min-width: 240px;
    background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text);
    padding: 1rem 1.1rem 1rem 1.35rem;
    border-radius: 14px;
    box-shadow: 0 14px 38px rgba(0,0,0,0.38);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    backdrop-filter: blur(14px) saturate(130%);
    -webkit-backdrop-filter: blur(14px) saturate(130%);
    position: relative;
    overflow: hidden;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-container .toast::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 7px;
    background: var(--accent);
}

.toast-container .toast.success::before { background: #34d399; }
.toast-container .toast.error::before { background: var(--danger); }
.toast-container .toast.warning::before { background: #fbbf24; }

.toast-icon {
    margin-right: 0.6rem;
    font-size: 1rem;
    opacity: 0.9;
}

.toast-text {
    display: inline-block;
    line-height: 1.3;
}

.actions-cell .btn {
    margin: 2px 0;
    flex: 0 0 auto;
}

@media (max-width: 960px) {
    body {
        background: linear-gradient(180deg, #0f172a 0%, #0f172a 40%, #111b2f 100%);
    }
    body::before {
        opacity: 0.5;
    }
    .content {
        padding: 1rem;
        gap: 1rem;
    }
    .content-grid {
        grid-template-columns: 1fr;
    }
    .folder-card {
        order: 1;
    }
    .recordings-card {
        order: 2;
    }
    .top-bar {
        padding: 1rem 1.25rem;
    }
    .card {
        padding: 1.1rem;
    }
    .action-group {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.35rem;
    }
    #search-input {
        min-width: 140px;
        width: 100%;
    }
    .table-wrapper {
        overflow-x: auto;
    }
    table {
        min-width: 640px;
    }
    .actions-cell {
        gap: 0.35rem;
    }
    .actions-cell .btn {
        padding: 0.35rem 0.75rem;
    }
    .status-pill,
    .status-duration {
        display: inline-flex;
    }
}

@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    body, .content, .detail-grid, .detail-main, .nested, .utterance-list {
        background: #fff !important;
        color: #000 !important;
        display: block;
        position: relative;
    }
    body::before,
    .top-bar,
    .detail-sidebar,
    .summary-card,
    .tag-editor,
    .tag-badges,
    .card-header,
    audio,
    button,
    .action-row,
    #toggle-transcript,
    #transcript {
        display: none !important;
    }
    body::before {
        content: none !important;
    }
    .card,
    .nested {
        border: none;
        box-shadow: none;
        padding: 0;
        margin: 0 0 0.75rem 0;
    }
    .detail-head {
        position: static;
        padding: 0;
        margin-bottom: 0.75rem;
    }
    .title-row h1 {
        font-size: 1.5rem;
        color: #000;
    }
    .info-line {
        color: #000;
        margin: 0 0 0.5rem 0;
    }
    .utterance-list {
        gap: 0;
    }
    .utterance {
        border: 1px solid #ddd;
        margin: 0 0 0.25rem 0;
        padding: 0.5rem 0.6rem;
        page-break-inside: avoid;
    }
    .utterance-header {
        margin-bottom: 0.25rem;
    }
    .speaker-label {
        color: #000;
    }
    .timecode {
        color: #444;
    }
}
