/* ─── Design Tokens ──────────────────────────────────────────────── */
:root {
    --bg-color: #F6F4F9;
    --surface-color: #FFFFFF;
    --surface-variant: #EDE8F2;
    --primary-color: #6750A4;
    --primary-hover: #5B4397;
    --on-primary: #FFFFFF;
    --text-color: #1C1B1F;
    --text-muted: #5C5777;
    --text-label: #7C6FAB;
    --border-color: #D9D3E3;
    --danger-color: #B3261E;
    --on-danger: #FFFFFF;
    --card-hover: #F0ECF8;
    --header-shadow: 0 1px 0 var(--border-color);
}

[data-theme="dark"] {
    --bg-color: #1C1B1F;
    --surface-color: #2B2930;
    --surface-variant: #36343B;
    --primary-color: #D0BCFF;
    --primary-hover: #E8DDFF;
    --on-primary: #381E72;
    --text-color: #E6E1E5;
    --text-muted: #AEA9B4;
    --text-label: #CCC2DC;
    --border-color: #49454F;
    --danger-color: #F2B8B5;
    --on-danger: #601410;
    --card-hover: #36343B;
    --header-shadow: 0 1px 0 var(--border-color);
}

/* ─── Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.2s, color 0.2s;
}

/* ─── Header ─────────────────────────────────────────────────────── */
header {
    background-color: var(--surface-color);
    padding: 12px 16px;
    box-shadow: var(--header-shadow);
    z-index: 10;
}
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.app-title {
    display: flex;
    align-items: center;
    gap: 8px;
}
.app-title h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
}
.title-icon {
    color: var(--primary-color);
    flex-shrink: 0;
}
.header-actions {
    display: flex;
    gap: 4px;
}
.search-row {
    display: flex;
    gap: 8px;
}
.search-wrapper {
    position: relative;
    flex: 1;
}
.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.search-wrapper input {
    padding-left: 38px;
}

.header-links {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    font-size: 0.82rem;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
}
.header-links span {
    cursor: pointer;
    font-weight: 600;
    color: var(--primary-color);
}
.header-links span:hover {
    text-decoration: underline;
}
.sync-status {
    color: var(--text-muted) !important;
    font-weight: 400 !important;
    margin-right: auto;
    font-size: 0.75rem;
}

/* ─── Buttons ────────────────────────────────────────────────────── */
button {
    cursor: pointer;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background-color 0.15s, opacity 0.15s;
}
.btn-primary {
    background-color: var(--primary-color);
    color: var(--on-primary);
}
.btn-primary:hover {
    background-color: var(--primary-hover);
}
.btn-secondary {
    background-color: transparent;
    color: var(--text-color);
    border: 1.5px solid var(--border-color);
}
.btn-danger {
    background-color: var(--danger-color);
    color: var(--on-danger);
}
.icon-btn {
    background: none;
    color: var(--text-color);
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover {
    background-color: var(--surface-variant);
}
.scan-btn {
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* ─── Inputs ─────────────────────────────────────────────────────── */
input,
select,
textarea {
    background-color: var(--surface-variant);
    border: 1.5px solid var(--border-color);
    color: var(--text-color);
    padding: 10px 12px;
    border-radius: 8px;
    width: 100%;
    font-size: 0.95rem;
    transition: border-color 0.15s;
    font-family: inherit;
}
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* ─── Album List ─────────────────────────────────────────────────── */
#album-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.album-card {
    background-color: var(--surface-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    padding: 10px;
    cursor: pointer;
    transition: background-color 0.15s;
}
.album-card.unsynced {
    border-left: 3px solid var(--primary-color);
}
.album-card:hover,
.album-card:active {
    background-color: var(--card-hover);
}

.album-img {
    width: 52px;
    height: 52px;
    border-radius: 6px;
    object-fit: cover;
    margin-right: 14px;
    flex-shrink: 0;
}
.album-info {
    flex: 1;
    min-width: 0;
}
.album-artist {
    color: var(--primary-color);
    font-weight: 700;
    font-size: 0.9rem;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.album-title {
    font-weight: 500;
    font-size: 0.88rem;
    color: var(--text-color);
    margin: 2px 0 0 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.album-meta {
    font-size: 0.74rem;
    color: var(--text-muted);
    margin-top: 3px;
}
.empty-message {
    text-align: center;
    color: var(--text-muted);
    margin-top: 50px;
    width: 100%;
    padding: 0 20px;
}

/* ─── Modals ─────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: none;
    flex-direction: column;
}
#settings-modal {
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: var(--surface-color);
    margin: auto;
    width: 95%;
    max-width: 500px;
    max-height: 90vh;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
#settings-modal .modal-content {
    height: auto;
}
.modal-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}
.modal-body {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.form-group {
    margin-bottom: 14px;
}
.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-label);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.help-text {
    color: var(--text-muted);
    font-size: 0.8rem;
    display: block;
    margin-top: 4px;
}
.help-text a {
    color: var(--primary-color);
}

#preview-img {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 14px;
    background: var(--surface-variant);
}

/* ─── Camera ─────────────────────────────────────────────────────── */
#camera-modal {
    background: #000;
    position: relative;
    display: none;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.overlay-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80vw;
    height: 80vw;
    max-width: 350px;
    max-height: 350px;
    border: 2px solid rgba(255, 255, 255, 0.85);
    border-radius: 6px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    z-index: 10;
}
.camera-instruction {
    position: absolute;
    top: calc(50% - min(40vw, 175px) - 36px);
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 11;
    pointer-events: none;
}
.camera-controls {
    position: absolute;
    bottom: 50px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 40px;
    align-items: center;
    z-index: 11;
}
.btn-camera-cancel {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-radius: 20px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}
.shutter-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: white;
    border: 4px solid rgba(255, 255, 255, 0.4);
    padding: 0;
    flex-shrink: 0;
}

/* ─── Loading ────────────────────────────────────────────────────── */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 200;
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 16px;
    color: white;
    font-weight: 600;
}
.spinner {
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top: 3px solid white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.hidden-input { display: none; }
