:root {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1b3e;
    --bg-card: rgba(26, 27, 62, 0.6);
    --bg-card-hover: rgba(40, 42, 80, 0.8);
    --border: rgba(139, 92, 246, 0.15);
    --border-hover: rgba(139, 92, 246, 0.4);
    --accent: #8b5cf6;
    --accent-2: #06b6d4;
    --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
    --accent-gradient-hover: linear-gradient(135deg, #a78bfa 0%, #22d3ee 100%);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.3);
    --shadow-lg: 0 16px 64px rgba(0,0,0,0.4);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
}

/* Animated background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(ellipse at 20% 50%, rgba(139, 92, 246, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(6, 182, 212, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(139, 92, 246, 0.04) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.app-wrapper {
    position: relative;
    z-index: 1;
    padding: 20px;
    padding-bottom: 56px;
    max-width: 960px;
    margin: 0 auto;
}

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 28px;
    padding-top: 12px;
    flex-wrap: wrap;
}

.topbar-brand h1 {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 2px;
    line-height: 1.2;
}

.topbar-brand h1 .text {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.topbar-brand p {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 400;
    margin: 0;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    flex-shrink: 0;
}

.topbar-actions button {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    background: var(--bg-card);
    color: var(--text-secondary);
    transition: var(--transition);
    backdrop-filter: blur(12px);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.topbar-actions button:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* Input Section */

/* Toggle button */
.add-content-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 11px 18px;
    margin-bottom: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-sm);
}

.add-content-toggle:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.add-content-toggle.open {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom-color: transparent;
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.add-toggle-icon {
    font-size: 0.9rem;
}

.add-toggle-label {
    flex: 1;
}

.add-toggle-arrow {
    font-size: 0.72rem;
    color: var(--text-muted);
    transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1;
}

.add-content-toggle.open .add-toggle-arrow {
    transform: rotate(180deg);
}

/* Collapsible wrapper */
.input-card-wrap {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.55s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 24px;
}

.input-card-wrap.open {
    grid-template-rows: 1fr;
}

.input-card-wrap > .input-card {
    overflow: hidden;
    min-height: 0;
    margin-bottom: 0;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border-top: none;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.4s ease 0.1s, transform 0.45s cubic-bezier(0.4, 0, 0.2, 1) 0.05s;
}

.input-card-wrap.open > .input-card {
    overflow: visible;
    opacity: 1;
    transform: translateY(0);
}

.input-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.input-card:focus-within {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md), 0 0 0 1px rgba(139, 92, 246, 0.1);
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.input-row-full {
    margin-bottom: 14px;
}

.input-field {
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    background-color: rgba(15, 15, 35, 0.5);
    color: var(--text-primary);
    transition: var(--transition);
    width: 100%;
    font-family: inherit;
}

.input-field::placeholder {
    color: var(--text-muted);
}

.input-field:focus {
    outline: none;
    border-color: var(--accent);
    background-color: rgba(15, 15, 35, 0.8);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

select.input-field {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

select.input-field option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

textarea.input-field {
    resize: vertical;
    min-height: 60px;
    max-height: 200px;
}

.add-btn {
    width: 100%;
    padding: 13px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    letter-spacing: 0.3px;
}

.add-btn:hover {
    background: var(--accent-gradient-hover);
    transform: translateY(-1px);
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.3);
}

.add-btn:active {
    transform: translateY(0);
}

/* Tags/Tabs Section */
.tags-section {
    margin-bottom: 20px;
}

.tags-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.tags-header h3 {
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 700;
}

.manage-tags-btn {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.75rem;
    background: transparent;
    color: var(--text-muted);
    transition: var(--transition);
}

.manage-tags-btn:hover {
    background: var(--bg-card);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.tabs-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 4px 0;
}

.tab {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.78rem;
    background: transparent;
    color: var(--text-muted);
    transition: var(--transition);
    user-select: none;
}

.tab:hover {
    background: var(--bg-card);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.tab.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.tab .count {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 7px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 700;
}

/* Items Container - Card Layout */
.items-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.item-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    transition: var(--transition);
    cursor: grab;
    position: relative;
    overflow: hidden;
}

.item-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--accent-gradient);
    opacity: 0;
    transition: var(--transition);
}

.item-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
    box-shadow: var(--shadow-sm);
}

.item-card:hover::before {
    opacity: 1;
}

.item-card:active {
    cursor: grabbing;
}

.item-card.dragging {
    opacity: 0.5;
    transform: scale(0.98);
}

.item-card.drag-over {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

.item-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 10px;
}

.item-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
}

.label-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    background: var(--accent-gradient);
    color: white;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.tag-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    background: rgba(6, 182, 212, 0.15);
    color: #67e8f9;
    border-radius: 12px;
    font-size: 0.68rem;
    font-weight: 600;
    white-space: nowrap;
}

.item-card-content {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    padding: 8px 12px;
    background: rgba(15, 15, 35, 0.4);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.03);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    /* collapsed by default for long content */
}

.item-card-content.is-long {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    transition: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border-bottom-color: transparent;
}

.item-card-content.is-long.expanded {
    display: block;
    overflow: visible;
    -webkit-line-clamp: unset;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.content-expand-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 5px 12px;
    background: rgba(139, 92, 246, 0.06);
    border: 1px solid rgba(255,255,255,0.03);
    border-top: 1px solid rgba(139, 92, 246, 0.12);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
    text-align: left;
}

.content-expand-btn:hover {
    background: rgba(139, 92, 246, 0.13);
    color: #a78bfa;
}

.expand-chars {
    margin-left: auto;
    opacity: 0.5;
    font-weight: 400;
    font-size: 0.68rem;
}

.expand-arrow {
    font-size: 0.65rem;
    transition: transform 0.25s ease;
    opacity: 0.7;
}

/* Per-line copy — content shown directly as copyable lines */
.item-card-lines {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 8px;
    background: rgba(15, 15, 35, 0.4);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.03);
}

.item-card-lines.is-long {
    max-height: 168px;
    overflow: hidden;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border-bottom-color: transparent;
    -webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 70%, transparent 100%);
}

.item-card-lines.is-long.expanded {
    max-height: none;
    overflow: visible;
    -webkit-mask-image: none;
    mask-image: none;
}

.line-copy-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s, background 0.15s;
}

.line-copy-row:hover {
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.2);
}

.line-copy-num {
    flex-shrink: 0;
    min-width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    border-radius: 6px;
    font-size: 0.62rem;
    font-weight: 700;
}

.line-copy-text {
    flex: 1;
    min-width: 0;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.4;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.line-copy-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: rgba(139, 92, 246, 0.1);
    color: #a78bfa;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 6px rgba(139, 92, 246, 0.18), inset 0 0 8px rgba(139, 92, 246, 0.12);
}

.line-copy-btn:hover {
    background: rgba(139, 92, 246, 0.18);
    color: #c4b5fd;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.4), inset 0 0 12px rgba(139, 92, 246, 0.25);
}

.line-copy-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(139, 92, 246, 0.25), inset 0 0 10px rgba(139, 92, 246, 0.2);
}

.line-copy-btn svg {
    display: block;
}

.item-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn {
    padding: 7px 12px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.73rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: var(--transition);
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-copy {
    background: rgba(6, 182, 212, 0.15);
    color: #67e8f9;
    border: 1px solid rgba(6, 182, 212, 0.3);
}

.btn-copy:hover {
    background: rgba(6, 182, 212, 0.25);
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.2);
}

.btn-edit {
    background: rgba(251, 191, 36, 0.12);
    color: #fcd34d;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.btn-edit:hover {
    background: rgba(251, 191, 36, 0.2);
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.15);
}

.btn-delete {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-delete:hover {
    background: rgba(239, 68, 68, 0.2);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
}

/* Empty State */
.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.9rem;
    max-width: 300px;
    margin: 0 auto;
    line-height: 1.6;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
}

@media (max-width: 480px) {
    .modal-overlay {
        align-items: center;
        padding: 12px 8px 80px;
    }
}

.modal-overlay.show {
    display: flex;
    animation: fadeInOverlay 0.35s ease;
}

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

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 460px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 60px);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
    from { transform: translateY(32px) scale(0.98); opacity: 0; }
    to   { transform: translateY(0)   scale(1);    opacity: 1; }
}

.modal-header {
    background: var(--accent-gradient);
    color: white;
    padding: 18px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.05rem;
    font-weight: 700;
}

.modal-close {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: rgba(255,255,255,0.25);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-body label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.72rem;
    letter-spacing: 0.8px;
    text-transform: uppercase;
}

.modal-body input,
.modal-body textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    margin-bottom: 16px;
    background: rgba(15, 15, 35, 0.6);
    color: var(--text-primary);
    transition: var(--transition);
    font-family: inherit;
}

.modal-body input:focus,
.modal-body textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.modal-body select {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    margin-bottom: 16px;
    background: rgba(15, 15, 35, 0.6);
    color: var(--text-primary);
    transition: var(--transition);
    cursor: pointer;
    font-family: inherit;
}

.modal-body select:focus {
    outline: none;
    border-color: var(--accent);
}

.modal-body select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-footer {
    padding: 16px 24px;
    background: rgba(0,0,0,0.15);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-footer button {
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.84rem;
    font-family: inherit;
}

.btn-cancel {
    background: rgba(255,255,255,0.06);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-cancel:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
}

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

.btn-save:hover {
    background: var(--accent-gradient-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.3);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.35);
}

.modal-sm {
    max-width: 380px !important;
}

.modal-header-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
}

.confirm-msg {
    color: var(--text-secondary);
    font-size: 0.88rem;
    line-height: 1.6;
    white-space: pre-line;
    margin: 0;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 22px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: white;
    border-radius: var(--radius-md);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.35s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 2000;
    font-weight: 600;
    font-size: 0.84rem;
    box-shadow: var(--shadow-lg);
    max-width: 320px;
}

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

/* Tag management styles */
.tag-list {
    max-height: 460px;
    overflow-y: auto;
}

.tag-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: rgba(15, 15, 35, 0.4);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: var(--transition);
}

.tag-item:hover {
    border-color: var(--border-hover);
}

.tag-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.tag-item-name {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.88rem;
}

.tag-item-count {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.tag-item-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    width: 280px;
    justify-content: flex-end;
}

.tag-item-btn {
    min-width: 62px;
    height: 30px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.72rem;
    font-weight: 600;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    font-family: inherit;
    box-sizing: border-box;
}

.tag-item-btn.show {
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-secondary);
}

.tag-item-btn.show:hover {
    background: rgba(100, 116, 139, 0.3);
}

.tag-item-btn.show.active {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
}

.tag-item-btn.show.active:hover {
    background: rgba(16, 185, 129, 0.25);
}

.tag-item-btn.delete {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
}

.tag-item-btn.delete:hover {
    background: rgba(239, 68, 68, 0.22);
}

.tag-item-btn.rename {
    background: rgba(251, 191, 36, 0.12);
    color: #fbbf24;
}

.tag-item-btn.rename:hover {
    background: rgba(251, 191, 36, 0.22);
}

.new-tag-input {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
}

.new-tag-input input {
    flex: 1;
    margin-bottom: 0 !important;
}

.new-tag-input button {
    padding: 8px 20px;
    background: var(--accent-gradient);
    color: white;
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.88rem;
    transition: var(--transition);
    white-space: nowrap;
    font-family: inherit;
    line-height: 1.5;
}

.new-tag-input button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

/* ===== TAG TREE STRUCTURE ===== */
.tag-tree-node {
    margin-bottom: 6px;
}

.tag-tree-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(15, 15, 35, 0.5);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: var(--transition);
    user-select: none;
}

.tag-tree-main:hover {
    border-color: var(--border-hover);
    background: rgba(26, 27, 62, 0.6);
}

.tag-tree-main.tree-drop-target {
    border-color: var(--accent);
    background: rgba(139, 92, 246, 0.12);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.25);
}

.tag-tree-main.tree-drop-nest {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.1);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
    border-style: dashed;
}

.tag-tree-main.tree-dragging {
    opacity: 0.45;
    transform: scale(0.98);
}

.tag-tree-subtag {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px 8px 36px;
    background: rgba(10, 10, 25, 0.3);
    border: 1px solid rgba(139, 92, 246, 0.07);
    border-radius: var(--radius-sm);
    margin-top: 3px;
    cursor: grab;
    transition: var(--transition);
    user-select: none;
}

.tag-tree-subtag:hover {
    border-color: var(--border-hover);
    background: rgba(20, 20, 45, 0.5);
}

.tag-tree-subtag.tree-drop-target {
    border-color: var(--accent);
    background: rgba(139, 92, 246, 0.08);
}

.tag-tree-subtag.tree-dragging {
    opacity: 0.45;
    transform: scale(0.97);
}

.tag-tree-add-subtag-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px 8px 36px;
    background: rgba(10, 10, 25, 0.2);
    border: 1px dashed rgba(139, 92, 246, 0.3);
    border-radius: var(--radius-sm);
    margin-top: 3px;
}

.tag-drag-handle {
    color: var(--text-muted);
    font-size: 0.95rem;
    cursor: grab;
    padding: 0 4px;
    opacity: 0.45;
    flex-shrink: 0;
    line-height: 1;
}

.tag-item-name-group {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.subtag-parent-label {
    display: none;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tag-tree-connector {
    color: var(--text-muted);
    font-family: monospace;
    font-size: 0.78rem;
    opacity: 0.45;
    flex-shrink: 0;
    margin-right: 2px;
}

.subtag-count-badge {
    display: inline-flex;
    padding: 2px 7px;
    background: rgba(139, 92, 246, 0.14);
    color: #a78bfa;
    border-radius: 10px;
    font-size: 0.64rem;
    font-weight: 600;
    white-space: nowrap;
}

.add-subtag-btn {
    background: rgba(139, 92, 246, 0.12) !important;
    color: #a78bfa !important;
    border: 1px solid rgba(139, 92, 246, 0.2) !important;
}

.add-subtag-btn:hover {
    background: rgba(139, 92, 246, 0.22) !important;
    border-color: rgba(139, 92, 246, 0.4) !important;
}

.promote-btn {
    background: rgba(16, 185, 129, 0.1) !important;
    color: #34d399 !important;
    border: 1px solid rgba(16, 185, 129, 0.2) !important;
}

.promote-btn:hover {
    background: rgba(16, 185, 129, 0.2) !important;
    border-color: rgba(16, 185, 129, 0.4) !important;
}

.promote-all-btn {
    background: rgba(16, 185, 129, 0.08) !important;
    color: #6ee7b7 !important;
    border: 1px solid rgba(16, 185, 129, 0.2) !important;
    font-size: 0.75rem !important;
}

.promote-all-btn:hover {
    background: rgba(16, 185, 129, 0.18) !important;
    border-color: rgba(16, 185, 129, 0.45) !important;
    color: #34d399 !important;
}

.btn-promote-all {
    background: rgba(16, 185, 129, 0.1);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-right: auto;
}

.btn-promote-all:hover {
    background: rgba(16, 185, 129, 0.2);
    border-color: rgba(16, 185, 129, 0.5);
    transform: translateY(-1px);
}

.subtag-name-input {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    background: rgba(15, 15, 35, 0.7);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-family: inherit;
    transition: var(--transition);
}

.subtag-name-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.12);
}

/* ===== SUBTAG FILTER CHIPS ===== */
.subtag-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    width: 100%;
    padding: 8px 2px 2px 2px;
    margin-top: 2px;
    border-top: 1px solid rgba(139, 92, 246, 0.12);
}

.subtag-chip {
    padding: 5px 12px;
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.72rem;
    background: rgba(139, 92, 246, 0.06);
    color: var(--text-muted);
    transition: var(--transition);
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.subtag-chip:hover {
    background: rgba(139, 92, 246, 0.13);
    border-color: rgba(139, 92, 246, 0.38);
    color: var(--text-primary);
}

.subtag-chip.active {
    background: rgba(139, 92, 246, 0.22);
    color: #c4b5fd;
    border-color: rgba(139, 92, 246, 0.55);
}

.subtag-chip .count {
    display: inline-block;
    padding: 1px 5px;
    background: rgba(255,255,255,0.12);
    border-radius: 8px;
    font-size: 0.63rem;
    font-weight: 700;
}

.subtag-indicator {
    font-size: 0.6rem;
    opacity: 0.65;
    vertical-align: middle;
}

/* Tab with subtags — distinct styling */
.tab-has-subtags {
    border-bottom: 2px solid rgba(139, 92, 246, 0.5);
    padding-bottom: calc(var(--tab-padding-v, 8px) - 2px);
    position: relative;
}

.tab-has-subtags::before {
    content: '';
    position: absolute;
    left: 0;
    top: 25%;
    height: 50%;
    width: 3px;
    background: var(--accent-gradient);
    border-radius: 0 3px 3px 0;
    opacity: 0.7;
}

.tab-has-subtags.active::before {
    display: none;
}

.tab-subtag-badge {
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
    padding: 1px 6px;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    border-radius: 8px;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.2px;
    vertical-align: middle;
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.tab.active .tab-subtag-badge {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.25);
}

[data-theme="light"] .tab-subtag-badge {
    background: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
    border-color: rgba(139, 92, 246, 0.25);
}

[data-theme="light"] .tab.active .tab-subtag-badge {
    background: rgba(255, 255, 255, 0.3);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.3);
}

/* Tag badge parent label */
.tag-badge-parent {
    opacity: 0.6;
    font-weight: 500;
    font-size: 0.63rem;
}

/* ===== CUSTOM SELECT ===== */
.custom-select {
    position: relative;
    width: 100%;
    margin-bottom: 0;
    z-index: 10;
}

.custom-select.open {
    z-index: 200;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(15, 15, 35, 0.5);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    font-size: 0.88rem;
    font-family: inherit;
    min-height: 44px;
}

.custom-select-trigger:hover {
    border-color: var(--border-hover);
    background: rgba(15, 15, 35, 0.7);
}

.custom-select.open .custom-select-trigger {
    border-color: var(--accent);
    background: rgba(15, 15, 35, 0.8);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.custom-select-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
}

.custom-select-label.placeholder {
    color: var(--text-muted);
}

.custom-select-arrow {
    color: var(--text-muted);
    font-size: 0.75rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
    line-height: 1;
}

.custom-select.open .custom-select-arrow {
    transform: rotate(180deg);
}

.custom-select-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1.5px solid var(--accent);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 600;
    max-height: 220px;
    overflow-y: auto;
    animation: slideDown 0.15s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.custom-select.open .custom-select-menu {
    display: block;
}

.custom-select-option {
    padding: 9px 14px;
    cursor: pointer;
    font-size: 0.86rem;
    color: var(--text-secondary);
    transition: background 0.12s;
}

.custom-select-option:hover {
    background: rgba(139, 92, 246, 0.1);
    color: var(--text-primary);
}

.custom-select-option.selected {
    background: rgba(139, 92, 246, 0.14);
    color: #c4b5fd;
    font-weight: 600;
}

.custom-select-option.cs-no-tag {
    color: var(--text-muted);
    font-style: italic;
}

.custom-select-sub {
    padding-left: 30px;
    font-size: 0.83rem;
    color: var(--text-muted);
}

.custom-select-sub:hover {
    color: var(--text-primary);
}

.custom-select-group-label {
    padding: 7px 14px 4px;
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
    pointer-events: none;
    border-top: 1px solid var(--border);
    margin-top: 2px;
}

.custom-select-group-label:first-child {
    border-top: none;
    margin-top: 0;
}

[data-theme="light"] .custom-select-trigger {
    background: rgba(241, 245, 249, 0.8);
    color: #1e293b;
    border-color: rgba(139, 92, 246, 0.2);
}

[data-theme="light"] .custom-select-trigger:hover {
    background: #ffffff;
}

[data-theme="light"] .custom-select.open .custom-select-trigger {
    background: #ffffff;
}

[data-theme="light"] .custom-select-menu {
    background: #ffffff;
    border-color: var(--accent);
}

[data-theme="light"] .custom-select-option {
    color: #475569;
}

[data-theme="light"] .custom-select-option:hover {
    background: rgba(139, 92, 246, 0.08);
    color: #1e293b;
}

[data-theme="light"] .custom-select-option.selected {
    background: rgba(139, 92, 246, 0.12);
    color: #6d28d9;
}

/* ===== CUSTOM SELECT ===== */
.custom-select {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(15, 15, 35, 0.5);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
    font-size: 0.88rem;
    font-family: inherit;
    min-height: 44px;
}

.custom-select-trigger:hover {
    border-color: var(--border-hover);
    background: rgba(15, 15, 35, 0.7);
}

.custom-select.open .custom-select-trigger {
    border-color: var(--accent);
    background: rgba(15, 15, 35, 0.8);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.custom-select-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select-label.placeholder {
    color: var(--text-muted);
}

.custom-select-arrow {
    color: var(--text-muted);
    font-size: 0.75rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
    line-height: 1;
}

.custom-select.open .custom-select-arrow {
    transform: rotate(180deg);
}

.custom-select-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1.5px solid var(--accent);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 600;
    max-height: 220px;
    overflow-y: auto;
    animation: slideDown 0.15s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.custom-select.open .custom-select-menu {
    display: block;
}

.custom-select-option {
    padding: 9px 14px;
    cursor: pointer;
    font-size: 0.86rem;
    color: var(--text-secondary);
    transition: background 0.12s;
}

.custom-select-option:hover {
    background: rgba(139, 92, 246, 0.1);
    color: var(--text-primary);
}

.custom-select-option.selected {
    background: rgba(139, 92, 246, 0.14);
    color: #c4b5fd;
    font-weight: 600;
}

.custom-select-option.cs-no-tag {
    color: var(--text-muted);
    font-style: italic;
}

.custom-select-sub {
    padding-left: 30px;
    font-size: 0.83rem;
    color: var(--text-muted);
}

.custom-select-sub:hover {
    color: var(--text-primary);
}

.custom-select-group-label {
    padding: 7px 14px 4px;
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
    pointer-events: none;
    border-top: 1px solid var(--border);
    margin-top: 2px;
}

.custom-select-group-label:first-child {
    border-top: none;
    margin-top: 0;
}

[data-theme="light"] .custom-select-trigger {
    background: rgba(241, 245, 249, 0.8);
    color: #1e293b;
    border-color: rgba(139, 92, 246, 0.2);
}

[data-theme="light"] .custom-select-trigger:hover,
[data-theme="light"] .custom-select.open .custom-select-trigger {
    background: #ffffff;
}

[data-theme="light"] .custom-select-menu {
    background: #ffffff;
    border-color: var(--accent);
}

[data-theme="light"] .custom-select-option {
    color: #475569;
}

[data-theme="light"] .custom-select-option:hover {
    background: rgba(139, 92, 246, 0.08);
    color: #1e293b;
}

[data-theme="light"] .custom-select-option.selected {
    background: rgba(139, 92, 246, 0.12);
    color: #6d28d9;
}

/* Search */
.search-bar {
    position: relative;
    margin-bottom: 16px;
}

.search-bar input {
    width: 100%;
    padding: 11px 14px 11px 40px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: var(--transition);
    font-family: inherit;
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

.search-bar input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.08);
}

.search-bar .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.85rem;
    pointer-events: none;
}

/* Footer */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 10px 20px;
    color: var(--text-muted);
    font-size: 0.82rem;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
    backdrop-filter: blur(12px);
    z-index: 100;
}

.footer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    transition: var(--transition);
}

.footer a:hover {
    color: #a78bfa;
}

.footer .heart {
    color: #ef4444;
    display: inline-block;
    animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.4);
}

/* Animations */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.item-card {
    animation: fadeInUp 0.3s ease backwards;
}

.input-card {
    animation: fadeInUp 0.4s ease;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .app-wrapper {
        padding: 16px;
    }

    header {
        margin-bottom: 24px;
    }

    header h1 {
        font-size: 1.6rem;
    }

    /* Topbar */
    .topbar {
        flex-direction: column;
        align-items: center;
        gap: 20px;
        text-align: center;
    }

    .topbar-brand {
        text-align: center;
    }

    .topbar-actions {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Input card */
    .input-row {
        grid-template-columns: 1fr;
    }

    /* Item cards */
    .item-card-top {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .item-card-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .btn {
        flex: 1;
        justify-content: center;
    }

    /* Tag tree: stack name top-left, buttons bottom-right */
    .tag-tree-main,
    .tag-tree-subtag {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .tag-item-left {
        align-self: flex-start;
    }

    .tag-item-actions {
        width: 100% !important;
        flex-wrap: wrap;
        justify-content: flex-end;
        align-self: flex-end;
    }

    /* Manage Tags modal full-width */
    #tagsModal .modal {
        max-width: 100% !important;
    }

    /* Modal footer promote-all full-width when stacked */
    .modal-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .btn-promote-all {
        margin-right: 0;
        width: 100%;
        text-align: center;
        justify-content: center;
    }

    /* Custom select menu inside modal — stay inside viewport */
    .custom-select-menu {
        max-height: 180px;
    }
}

@media (max-width: 480px) {
    .app-wrapper {
        padding: 10px;
        padding-bottom: 64px;
    }

    /* Topbar */
    .topbar {
        gap: 8px;
        margin-bottom: 18px;
    }

    .topbar-brand h1 {
        font-size: 1.3rem;
    }

    .topbar-brand p {
        font-size: 0.74rem;
    }

    .topbar-actions {
        gap: 6px;
        justify-content: center;
    }

    .topbar-actions button {
        padding: 7px 10px;
        font-size: 0.76rem;
    }

    /* Cards */
    .input-card {
        padding: 14px;
        border-radius: var(--radius-md);
    }

    .item-card {
        padding: 14px;
        border-radius: var(--radius-sm);
    }

    .item-card-content {
        font-size: 0.8rem;
        padding: 6px 10px;
    }

    /* Tabs */
    .tabs-container {
        gap: 6px;
    }

    .tab {
        padding: 6px 12px;
        font-size: 0.72rem;
    }

    .subtag-chip {
        font-size: 0.68rem;
        padding: 4px 10px;
    }

    /* Modals */
    .modal {
        border-radius: var(--radius-md);
        max-height: 92vh;
        margin: 0 8px;
    }

    .modal-sm {
        max-width: calc(100vw - 16px) !important;
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-header h2 {
        font-size: 1rem;
    }

    .modal-body {
        padding: 14px 16px;
    }

    .modal-footer {
        padding: 12px 16px;
        flex-direction: column;
        gap: 8px;
    }

    .modal-footer button,
    .btn-promote-all,
    .btn-cancel,
    .btn-save,
    .btn-danger {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    /* Tag tree compact on phone */
    .tag-tree-main,
    .tag-tree-subtag {
        padding: 8px 10px;
    }

    .tag-tree-subtag {
        padding-left: 20px;
    }

    .tag-item-btn {
        min-width: 54px;
        font-size: 0.75rem;
        height: 28px;
        padding: 0 6px;
    }

    .tag-drag-handle {
        display: none;
    }

    /* Keep drag handle visible inside tag modal (touch DnD) */
    #tagList .tag-drag-handle,
    #untaggedOption .tag-drag-handle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 36px;
        min-height: 36px;
        font-size: 1.1rem;
        cursor: grab;
        color: rgba(139, 92, 246, 0.7);
        background: rgba(139, 92, 246, 0.08);
        border: 1px solid rgba(139, 92, 246, 0.2);
        border-radius: 6px;
        margin-right: 4px;
        touch-action: none; /* critical: stops browser from stealing touch for scroll */
    }

    .tag-tree-connector {
        display: none;
    }

    /* Keep connector visible inside tag modal */
    #tagList .tag-tree-connector {
        display: inline;
    }

    /* Show parent label badge on subtag rows */
    .subtag-parent-label {
        display: block;
    }

    /* Strong left border on subtag rows so hierarchy is obvious */
    #tagList .tag-tree-subtag {
        border-left: 3px solid rgba(139, 92, 246, 0.45) !important;
        padding-left: 14px;
        margin-left: 10px;
        background: rgba(139, 92, 246, 0.05);
    }

    /* Custom select */
    .custom-select-menu {
        max-height: 160px;
        position: fixed;
        left: 10px;
        right: 10px;
        width: auto;
        top: auto;
        border-radius: var(--radius-sm);
        border-top: 1.5px solid var(--accent);
    }

    /* Toast */
    .toast {
        left: 12px;
        right: 12px;
        bottom: 12px;
        font-size: 0.8rem;
        max-width: none;
    }

    /* Footer */
    .footer {
        padding: 10px 14px;
        font-size: 0.7rem;
    }
}

/* Light theme */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.8);
    --bg-card-hover: rgba(241, 245, 249, 0.95);
    --border: rgba(139, 92, 246, 0.18);
    --border-hover: rgba(139, 92, 246, 0.45);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.08);
    --shadow-lg: 0 16px 64px rgba(0,0,0,0.1);
}

[data-theme="light"] body::before {
    background:
        radial-gradient(ellipse at 20% 50%, rgba(139, 92, 246, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(6, 182, 212, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(139, 92, 246, 0.03) 0%, transparent 50%);
}

[data-theme="light"] .input-field {
    background-color: rgba(241, 245, 249, 0.8);
    border-color: rgba(139, 92, 246, 0.2);
    color: #1e293b;
}

[data-theme="light"] .input-field:focus {
    background-color: #ffffff;
}

[data-theme="light"] .input-field::placeholder {
    color: #94a3b8;
}

[data-theme="light"] .add-content-toggle {
    background: rgba(255, 255, 255, 0.85);
    color: #475569;
    border-color: rgba(139, 92, 246, 0.2);
}

[data-theme="light"] .add-content-toggle:hover,
[data-theme="light"] .add-content-toggle.open {
    background: #ffffff;
    color: #1e293b;
    border-color: rgba(139, 92, 246, 0.4);
}

[data-theme="light"] select.input-field option {
    background: #ffffff;
    color: #1e293b;
}

[data-theme="light"] .modal-body input,
[data-theme="light"] .modal-body textarea {
    background: #f8fafc;
    color: #1e293b;
    border-color: rgba(139, 92, 246, 0.2);
}

[data-theme="light"] .modal-body select {
    background: #f8fafc;
    color: #1e293b;
    border-color: rgba(139, 92, 246, 0.2);
}

[data-theme="light"] .modal-body select option {
    background: #ffffff;
    color: #1e293b;
}

[data-theme="light"] .tag-item {
    background: rgba(241, 245, 249, 0.8);
}

[data-theme="light"] .tag-tree-main {
    background: rgba(241, 245, 249, 0.9);
    border-color: rgba(139, 92, 246, 0.18);
}

[data-theme="light"] .tag-tree-main:hover {
    background: rgba(233, 236, 245, 0.95);
}

[data-theme="light"] .tag-tree-subtag {
    background: rgba(248, 250, 252, 0.7);
    border-color: rgba(139, 92, 246, 0.1);
}

[data-theme="light"] .tag-tree-subtag:hover {
    background: rgba(241, 245, 249, 0.9);
}

@media (max-width: 480px) {
    [data-theme="light"] #tagList .tag-tree-subtag {
        border-left-color: rgba(139, 92, 246, 0.4) !important;
        background: rgba(139, 92, 246, 0.04) !important;
    }
}

[data-theme="light"] .tag-tree-add-subtag-row {
    background: rgba(248, 250, 252, 0.6);
}

[data-theme="light"] .subtag-name-input {
    background: #ffffff;
    color: #1e293b;
    border-color: rgba(139, 92, 246, 0.2);
}

[data-theme="light"] .subtag-chip {
    background: rgba(139, 92, 246, 0.06);
    border-color: rgba(139, 92, 246, 0.2);
    color: #64748b;
}

[data-theme="light"] .subtag-chip:hover {
    background: rgba(139, 92, 246, 0.1);
    color: #1e293b;
}

[data-theme="light"] .subtag-chip.active {
    background: rgba(139, 92, 246, 0.15);
    color: #6d28d9;
    border-color: rgba(139, 92, 246, 0.4);
}

[data-theme="light"] .search-bar input {
    background: rgba(255, 255, 255, 0.9);
    color: #1e293b;
}

[data-theme="light"] .toast {
    background: #ffffff;
    color: #1e293b;
    border-color: rgba(0,0,0,0.08);
}

[data-theme="light"] .label-badge {
    color: white;
}

[data-theme="light"] .tag-badge {
    background: rgba(6, 182, 212, 0.12);
    color: #0e7490;
}

[data-theme="light"] .btn-copy {
    background: rgba(6, 182, 212, 0.1);
    color: #0e7490;
    border-color: rgba(6, 182, 212, 0.35);
}

[data-theme="light"] .btn-edit {
    background: rgba(217, 119, 6, 0.1);
    color: #92400e;
    border-color: rgba(217, 119, 6, 0.35);
}

[data-theme="light"] .btn-delete {
    background: rgba(220, 38, 38, 0.08);
    color: #b91c1c;
    border-color: rgba(220, 38, 38, 0.3);
}

[data-theme="light"] select.input-field {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%231e293b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
}

[data-theme="light"] .item-card-content {
    background: rgba(241, 245, 249, 0.7);
    border-color: rgba(0,0,0,0.06);
    color: #334155;
}

[data-theme="light"] .content-expand-btn {
    background: rgba(139, 92, 246, 0.04);
    border-color: rgba(0,0,0,0.06);
    border-top-color: rgba(139, 92, 246, 0.15);
    color: #64748b;
}

[data-theme="light"] .content-expand-btn:hover {
    background: rgba(139, 92, 246, 0.09);
    color: #6d28d9;
}

[data-theme="light"] .item-card-lines {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(0,0,0,0.06);
}

[data-theme="light"] .line-copy-row {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .line-copy-row:hover {
    background: rgba(139, 92, 246, 0.07);
    border-color: rgba(139, 92, 246, 0.2);
}

[data-theme="light"] .line-copy-num {
    background: rgba(139, 92, 246, 0.12);
    color: #6d28d9;
}

[data-theme="light"] .line-copy-text {
    color: #334155;
}

[data-theme="light"] .line-copy-btn {
    background: rgba(139, 92, 246, 0.08);
    color: #6d28d9;
    border: none;
    box-shadow: 0 2px 6px rgba(139, 92, 246, 0.15), inset 0 0 8px rgba(139, 92, 246, 0.1);
}

[data-theme="light"] .line-copy-btn:hover {
    background: rgba(139, 92, 246, 0.16);
    color: #5b21b6;
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.3), inset 0 0 12px rgba(139, 92, 246, 0.2);
}

[data-theme="light"] .topbar-actions button {
    background: rgba(255,255,255,0.8);
    color: #475569;
    border-color: rgba(139, 92, 246, 0.2);
}

[data-theme="light"] .topbar-actions button:hover {
    background: #ffffff;
    color: #1e293b;
}

[data-theme="light"] .modal {
    background: #ffffff;
    border-color: rgba(0,0,0,0.08);
}

[data-theme="light"] .modal-footer {
    background: rgba(241, 245, 249, 0.5);
}

[data-theme="light"] .btn-cancel {
    background: rgba(0,0,0,0.05);
    color: #475569;
    border-color: rgba(0,0,0,0.1);
}

/* Theme toggle button */
.theme-toggle {
    padding: 10px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.82rem;
    background: var(--bg-card);
    color: var(--text-secondary);
    transition: var(--transition);
    backdrop-filter: blur(12px);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.theme-toggle:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* Share button */
.btn-share {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.btn-share:hover {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.5);
}

/* Share modal styles */
.share-modal-body {
    text-align: center;
}

.share-snippet-label {
    color: var(--text-primary);
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.share-link-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    align-items: stretch;
    flex-wrap: nowrap;
}

.share-link-row .input-field {
    flex: 1;
    min-width: 0;
    font-size: 0.75rem;
    padding: 8px 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0;
    box-sizing: border-box;
}

.share-link-row .btn-copy {
    padding: 8px 12px;
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
    margin: 0;
    box-sizing: border-box;
}

.share-qr-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.share-qr-section canvas {
    border-radius: 8px;
    background: #fff;
    padding: 8px;
    max-width: 100%;
    height: auto !important;
}

[data-theme="light"] .btn-share {
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
    border-color: rgba(59, 130, 246, 0.3);
}

[data-theme="light"] .btn-share:hover {
    background: rgba(59, 130, 246, 0.2);
}

/* QR Scanner Modal */
.scanner-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    padding: 4px;
}

.scanner-tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.scanner-tab.active {
    background: var(--accent);
    color: #fff;
}

.scanner-video-wrap {
    position: relative;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--border);
    aspect-ratio: 1;
    background: #000;
}

.scanner-video-wrap video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60%;
    height: 60%;
    border: 2px solid rgba(139, 92, 246, 0.6);
    border-radius: 12px;
    pointer-events: none;
    animation: scanPulse 2s ease-in-out infinite;
}

@keyframes scanPulse {
    0%, 100% { border-color: rgba(139, 92, 246, 0.3); }
    50% { border-color: rgba(139, 92, 246, 0.8); }
}

.upload-drop-zone {
    padding: 40px 20px;
    border: 2px dashed var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.upload-drop-zone:hover {
    border-color: var(--accent);
    background: rgba(139, 92, 246, 0.05);
}

.scanner-view {
    min-height: 200px;
}
