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

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent: #7289da;
    --accent-hover: #5b6eae;
    --success: #43b581;
    --danger: #f04747;
    --warning: #faa61a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

#user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

#user-info img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

#user-info a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
}

#user-info a:hover {
    color: var(--text-primary);
}

.screen {
    display: block;
}

.screen.hidden {
    display: none;
}

/* Offline Banner */
.offline-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--danger);
    color: white;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 500;
}

.offline-banner.hidden {
    display: none;
}

.offline-icon {
    font-size: 1.2rem;
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
}

.card.centered {
    max-width: 400px;
    margin: 100px auto;
    text-align: center;
}

/* Section Disabled State */
.section-disabled {
    opacity: 0.5;
    pointer-events: none;
    user-select: none;
}

.section-disabled * {
    cursor: default !important;
}

.card h2 {
    font-size: 1.2rem;
    margin-bottom: 16px;
}

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

.card-header h2 {
    margin-bottom: 0;
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-secondary);
    border-radius: 12px;
    transition: background 0.2s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--success);
}

.toggle-switch input:checked + .toggle-slider::after {
    transform: translateX(20px);
    background: white;
}

.toggle-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.toggle-switch input:checked ~ .toggle-label {
    color: var(--success);
}

/* Toggle wrapper for disabled state */
.toggle-wrapper {
    position: relative;
}

.toggle-wrapper.disabled .toggle-switch {
    opacity: 0.5;
    pointer-events: none;
}

.toggle-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-primary);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.toggle-wrapper.disabled:hover .toggle-tooltip {
    opacity: 1;
    visibility: visible;
}

.toggle-wrapper.cooldown .toggle-switch {
    opacity: 0.6;
    pointer-events: none;
}

.toggle-wrapper.cooldown .toggle-slider {
    cursor: not-allowed;
}

/* Sound Count */
.sound-count {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 1rem;
    font-weight: 600;
    padding: 6px 14px;
    background: var(--bg-secondary);
    border-radius: 20px;
}

.sound-count #sound-count-current {
    color: var(--accent);
}

.sound-count.at-limit #sound-count-current {
    color: var(--warning);
}

/* Weight Mode */
.weight-mode-section {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.weight-mode-section label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.weight-mode-toggle {
    display: flex;
    background: var(--bg-secondary);
    border-radius: 6px;
}

.weight-mode-toggle .mode-btn:first-child {
    border-radius: 6px 0 0 6px;
}

.weight-mode-toggle .mode-btn:last-child {
    border-radius: 0 6px 6px 0;
}

.mode-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.mode-btn:hover {
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent);
    color: white;
}

/* Info Icon & Tooltip */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: help;
    position: relative;
}

.mode-btn.active .info-icon {
    background: rgba(255, 255, 255, 0.3);
}

.info-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-primary);
    width: 220px;
    text-align: center;
    line-height: 1.4;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.info-icon:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Sound Weight Input */
.sound-weight {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sound-weight label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.sound-weight input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-primary);
    border-radius: 3px;
    cursor: pointer;
}

.sound-weight input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.sound-weight input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.sound-weight .weight-value {
    min-width: 45px;
    text-align: right;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--accent);
}

.weight-total {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.weight-total .total-label {
    color: var(--text-secondary);
}

.weight-total .total-value {
    font-weight: 600;
}

.weight-total .total-value.valid {
    color: var(--success);
}

.weight-total .total-value.invalid {
    color: var(--warning);
}

.card .subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: -12px;
    margin-bottom: 16px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, opacity 0.2s;
    text-decoration: none;
}

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

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

.btn-discord:hover {
    background: var(--accent-hover);
}

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

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

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

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

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

.btn-success:hover {
    background: #3da574;
}

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

.btn-danger:hover {
    background: #d93636;
}

.btn-warning {
    background: var(--warning);
    color: #111;
}

.btn-warning:hover {
    background: #e8960f;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Bot Status */
.bot-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-secondary);
}

.status-indicator.running {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-indicator.stopped {
    background: var(--danger);
}

.status-indicator.error {
    background: var(--warning);
}

.bot-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Guild List */
.guild-list {
    display: grid;
    gap: 10px;
}

.guild-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    border: 2px solid transparent;
}

.guild-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.guild-item.selected {
    border-color: var(--accent);
}

.guild-item img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-primary);
}

.guild-item .guild-info {
    flex: 1;
}

.guild-item .guild-name {
    font-weight: 500;
}

.guild-item .guild-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.guild-item .guild-status.active {
    color: var(--success);
}

/* Favorite Button */
.btn-favorite {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s, transform 0.2s;
    flex-shrink: 0;
}

.btn-favorite:hover {
    color: var(--warning);
    transform: scale(1.1);
}

.btn-favorite.favorited {
    color: var(--warning);
}

.btn-favorite svg {
    width: 20px;
    height: 20px;
}

.invite-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

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

.invite-section a:hover {
    text-decoration: underline;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding-top: 12px;
    margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.pagination .page-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group select,
.form-group input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
}

.form-group select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23aaa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    cursor: pointer;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.range-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
}

.range-inputs input {
    width: 100px;
}

.range-inputs span {
    color: var(--text-secondary);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

/* Volume Slider */
.volume-slider {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-secondary);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.volume-slider::-webkit-slider-thumb:hover {
    background: var(--accent-hover);
}

.volume-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: background 0.2s;
}

.volume-slider::-moz-range-thumb:hover {
    background: var(--accent-hover);
}

/* Sounds */
.upload-section {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.sounds-list {
    display: grid;
    gap: 8px;
}

.sound-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
}

.sound-item .sound-name {
    font-weight: 500;
}

.sound-item .sound-size {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-left: 12px;
}

.sound-item .sound-actions {
    display: flex;
    gap: 8px;
}

/* Loading */
.loading {
    color: var(--text-secondary);
    font-style: italic;
}

.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    color: var(--text-secondary);
}

.loading-spinner::before {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--bg-secondary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease;
    z-index: 1000;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Sound item with inline waveform */
.sound-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.sound-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sound-item-info {
    flex: 1;
    min-width: 0;
}

.sound-item .sound-name {
    font-weight: 500;
    word-break: break-word;
}

.sound-item .sound-size {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-left: 8px;
}

.sound-item .sound-trim {
    font-size: 0.75rem;
    color: var(--accent);
    margin-left: 8px;
}

/* Inline waveform */
.waveform-inline {
    position: relative;
    background: var(--bg-primary);
    border-radius: 6px;
    height: 50px;
    width: 100%;
    overflow: hidden;
}

.waveform-inline canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.waveform-inline .waveform-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.waveform-inline .waveform-selection {
    position: absolute;
    top: 0;
    height: 100%;
    background: rgba(114, 137, 218, 0.3);
    pointer-events: none;
}

.waveform-inline .waveform-handle {
    position: absolute;
    top: 0;
    width: 8px;
    height: 100%;
    background: var(--accent);
    cursor: ew-resize;
    pointer-events: auto;
    opacity: 0.9;
    transition: opacity 0.2s, transform 0.1s;
}

.waveform-inline .waveform-handle:hover {
    opacity: 1;
    transform: scaleX(1.2);
}

.waveform-inline .waveform-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 20px;
    background: white;
    border-radius: 1px;
}

.waveform-inline .handle-start {
    border-radius: 3px 0 0 3px;
}

.waveform-inline .handle-end {
    border-radius: 0 3px 3px 0;
}

.waveform-inline .time-labels {
    position: absolute;
    bottom: 2px;
    left: 4px;
    right: 4px;
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.6);
    pointer-events: none;
}

.waveform-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 50px;
    width: 100%;
    background: var(--bg-primary);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.waveform-saved {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(67, 181, 129, 0.9);
    color: white;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    pointer-events: none;
    transition: opacity 0.3s;
}

.waveform-saved.fade-out {
    opacity: 0;
}

/* Activity Logs */
.logs-list {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.log-entry {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 0.9rem;
}

.log-entry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.log-entry-user {
    font-weight: 500;
    color: var(--accent);
}

.log-entry-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.log-entry-action {
    color: var(--text-primary);
}

.log-entry-details {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: monospace;
    background: var(--bg-primary);
    padding: 4px 8px;
    border-radius: 4px;
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 15px;
    }

    header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .bot-controls {
        justify-content: center;
    }

    .range-inputs {
        flex-direction: column;
        align-items: stretch;
    }

    .range-inputs input {
        width: 100%;
    }
}
