:root {
    --bg-color: #f1f5f9;
    --surface-color: #ffffff;
    --card-border: #e2e8f0;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --text-main: #1e293b;
    --text-dim: #64748b;
    --font-family: 'Inter', -apple-system, system-ui, sans-serif;
    --mono-family: 'JetBrains Mono', monospace;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --transition: all 0.2s ease;
}

body.dark-mode {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --card-border: #334155;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
}

/* Header & Profile Top Right */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--surface-color);
    border-bottom: 1px solid var(--card-border);
    margin-bottom: 2rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--card-border);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.2rem;
}

.profile-trigger {
    cursor: pointer;
    position: relative;
    width: 40px;
    height: 40px;
}

.profile-dropdown {
    position: absolute;
    top: 50px;
    right: 0;
    width: 250px;
    background: var(--surface-color);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 1rem;
    z-index: 1000;
    display: none;
}

.profile-dropdown.show {
    display: block;
}

body {
    font-family: var(--font-family);
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
}

h1,
h2,
h3,
h4 {
    color: #0f172a;
    font-weight: 600;
}

h1 {
    font-size: 2.25rem;
    text-align: center;
    padding: 2.5rem 0;
    font-weight: 800;
}

/* --- Layout --- */
.main-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem 2rem;
}

@media (min-width: 1024px) {
    .main-grid {
        grid-template-columns: 350px 1fr;
    }
}

/* --- Components --- */
.card {
    background: var(--surface-color);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

/* --- Tabs --- */
.tab-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 0px;
}

.tab-button {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: var(--transition);
}

.tab-button:hover {
    color: var(--primary);
}

.tab-button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* --- Form Elements --- */
label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-main);
}

input,
select {
    width: 100%;
    background: #fff;
    border: 1px solid var(--card-border);
    color: var(--text-main);
    padding: 0.625rem 0.875rem;
    border-radius: 8px;
    font-size: 0.95rem;
    margin-bottom: 1rem;
    transition: var(--transition);
}

input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

button {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
}

button:hover {
    background: var(--primary-hover);
    transform: translateY(-0.5px);
}

button:active {
    transform: translateY(0);
}

/* --- Pomodoro --- */
.pomodoro-container {
    text-align: center;
}

#pomodoroTimer {
    font-family: var(--mono-family);
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary);
    margin: 1rem 0;
}

.pomodoro-modes {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    background: #f8fafc;
    padding: 0.35rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.mode-btn {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    background: transparent;
    color: var(--text-dim);
    border: none;
    flex: 1;
}

.mode-btn.active {
    background: #fff;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* --- Achievements --- */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.badge {
    text-align: center;
    filter: grayscale(1);
    opacity: 0.4;
    transition: var(--transition);
}

.badge.unlocked {
    filter: grayscale(0);
    opacity: 1;
}

.badge-icon {
    font-size: 1.75rem;
    display: block;
}

.badge-name {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-dim);
}

/* --- Chat --- */
#chat-window {
    height: 450px;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.msg-wrapper {
    display: flex;
    gap: 0.75rem;
}

.msg-wrapper.me {
    flex-direction: row-reverse;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #e2e8f0;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
}

.me .avatar {
    background: var(--primary);
    color: #fff;
}

.msg-bubble {
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    font-size: 0.95rem;
}

.me .msg-bubble {
    background: var(--primary);
    color: #fff;
    border: none;
}

.msg-info {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 0.15rem;
    display: flex;
    gap: 0.5rem;
}

.me .msg-info {
    justify-content: flex-end;
}

/* --- Tables --- */
table {
    width: 100%;
    border-collapse: collapse;
}

th {
    padding: 0.75rem 1rem;
    text-align: left;
    color: var(--text-dim);
    font-size: 0.75rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--card-border);
}

td {
    padding: 1rem;
    border-bottom: 1px solid #f1f5f9;
}

tr:hover td {
    background: #f8fafc;
}

/* --- Library --- */
.library-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.library-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-main);
    transition: var(--transition);
}

.library-item:hover {
    background: #fff;
    border-color: var(--primary);
    box-shadow: var(--shadow-sm);
    transform: translateX(4px);
}

.library-icon {
    font-size: 1.25rem;
}

.library-info {
    display: flex;
    flex-direction: column;
}

.library-title {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--primary);
}

.library-desc {
    font-size: 0.7rem;
    color: var(--text-dim);
}

/* --- Quote --- */
#dailyQuote {
    max-width: 800px;
    margin: 0 auto 2rem;
    background: #fffbeb;
    border-color: #fef3c7;
    color: #92400e;
    font-style: italic;
}