:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --text: #e0e0e0;
    --text-muted: #a0a0a0;
    --accent: #0f3460;
    --highlight: #e94560;
    --border: #2a2a4a;
    --input-bg: #0f3460;
}

[data-theme="light"] {
    --bg: #f5f5f5;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-muted: #666;
    --accent: #e8e8e8;
    --highlight: #e94560;
    --border: #ddd;
    --input-bg: #fff;
}

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

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

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: #1e3a5f;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.5rem;
}
[data-theme="light"] header { background: #3a7bd5; }

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-left h1 { font-size: 1.4rem; letter-spacing: 2px; }
.logo { height: 40px; width: 40px; }
.logo-light { display: none; }
[data-theme="light"] .logo-dark { display: none; }
[data-theme="light"] .logo-light { display: block; }

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

#search, #cat-filter {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text);
    font-size: 0.9rem;
}

#search { width: 200px; }
.search-wrap { position: relative; display: inline-block; }
.search-wrap #search { padding-right: 1.8rem; }
.search-clear {
    position: absolute;
    right: 0.4rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.2rem;
}
.search-clear:hover { color: var(--text); }

nav { display: flex; gap: 1rem; }
nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
}
nav a.active, nav a:hover { color: var(--highlight); }

#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 1.1rem;
}

main { padding: 1.5rem; }

.parts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.part-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.2s;
}
.part-card:hover { border-color: var(--highlight); }
.part-card h3 { font-size: 0.95rem; margin-bottom: 0.4rem; color: var(--highlight); }
.part-card p { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.part-card .meta {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.8rem;
}
.part-card .meta span { background: var(--accent); padding: 0.2rem 0.5rem; border-radius: 3px; }

/* Detail view */
#part-detail {
    max-width: 800px;
    margin: 0 auto;
}
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.detail-header h2 { color: var(--highlight); }
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.detail-grid .field label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.detail-grid .field p { margin-top: 0.25rem; }
.detail-grid .full { grid-column: 1 / -1; }

/* Form */
#part-form {
    max-width: 600px;
    margin: 0 auto;
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}
#part-form h2 { margin-bottom: 1rem; color: var(--highlight); }
#part-form label { display: block; font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; margin-top: 0.75rem; }
#part-form input, #part-form select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text);
    margin-top: 0.25rem;
}
#part-form .row { display: flex; gap: 1rem; }
#part-form .row > div { flex: 1; }

.btn {
    display: inline-block;
    padding: 0.5rem 1.2rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    margin-top: 1rem;
    margin-right: 0.5rem;
}
.btn-primary { background: var(--highlight); color: #fff; }
.btn-secondary { background: var(--accent); color: var(--text); border: 1px solid var(--border); }

.hidden { display: none; }

@media (max-width: 600px) {
    .header-right { width: 100%; }
    #search { width: 100%; }
    .detail-grid { grid-template-columns: 1fr; }
}

/* Login */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}
.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2rem;
    width: 320px;
    text-align: center;
}
.login-logo { height: 60px; width: 60px; margin-bottom: 1rem; }
.login-box h2 { margin-bottom: 1.5rem; }
.login-box input {
    width: 100%;
    padding: 0.5rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text);
}
.password-field {
    position: relative;
}
.password-field input { padding-right: 2.5rem; }
.reveal-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-70%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    opacity: 0.6;
}
.reveal-toggle:hover { opacity: 1; }
.login-box .btn { width: 100%; }
.error-msg { color: var(--highlight); font-size: 0.85rem; margin-top: 0.5rem; }
.hint { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.75rem; }

#logout-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text);
}

/* PDF Preview */
.pdf-preview {
    margin-top: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.pdf-preview object { display: block; }

/* Admin Panel */
.admin-panel, .profile-panel, .directory-panel {
    max-width: 800px;
    margin: 0 auto;
}
.admin-panel h2, .profile-panel h2, .directory-panel h2 { color: var(--highlight); margin-bottom: 1rem; }
.admin-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}
.admin-tab {
    padding: 0.6rem 1.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--highlight); border-bottom-color: var(--highlight); }
.invite-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}
.invite-form input, .invite-form select {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text);
}
.invite-form input { flex: 1; min-width: 200px; }
#invite-msg { width: 100%; font-size: 0.85rem; color: var(--highlight); }

.users-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.users-table th, .users-table td {
    padding: 0.6rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.users-table th { font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); }
.users-table select {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text);
}

/* Profile */
.profile-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
}
.profile-form label { display: block; font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; margin-top: 0.75rem; }
.profile-form input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text);
    margin-top: 0.25rem;
}
.profile-form input:disabled { opacity: 0.6; }
.profile-form .row { display: flex; gap: 1rem; }
.profile-form .row > div { flex: 1; }
.avatar-section { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.avatar-preview {
    width: 80px;
    height: 80px;
    min-width: 80px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 2rem;
    aspect-ratio: 1;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

/* Directory */
.directory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}
.directory-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}
.directory-card h3 { font-size: 0.95rem; margin: 0.5rem 0 0.25rem; }
.directory-card p { font-size: 0.8rem; color: var(--text-muted); margin: 0.2rem 0; }
.directory-card a { color: var(--highlight); }
.directory-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    overflow: hidden;
    font-size: 1.5rem;
}
.directory-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    min-width: 300px;
}
.modal-box h3 { margin-bottom: 0.75rem; color: var(--highlight); }
.modal-box select, .modal-box input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text);
    margin-top: 0.5rem;
}

/* Voice */
#voice-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text);
}
#voice-btn.voice-active {
    background: var(--highlight);
    color: #fff;
    border-color: var(--highlight);
    animation: pulse 1s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}
.voice-status {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    z-index: 3000;
    transition: opacity 0.3s;
}
.voice-status.hidden { opacity: 0; pointer-events: none; }
.voice-status.voice-error { border-color: var(--highlight); color: var(--highlight); }

/* Invited user card */
.directory-card.invited { opacity: 0.7; border-style: dashed; }
.invited-badge { color: var(--highlight); font-style: italic; }
