:root {
    --md-sys-color-primary: #00639B;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-primary-container: #CDE5FF;
    --md-sys-color-on-primary-container: #001D33;
    --md-sys-color-secondary: #526070;
    --md-sys-color-on-secondary: #FFFFFF;
    --md-sys-color-secondary-container: #D6E4F7;
    --md-sys-color-on-secondary-container: #0F1D2A;
    --md-sys-color-tertiary: #6B5778;
    --md-sys-color-on-tertiary: #FFFFFF;
    --md-sys-color-tertiary-container: #F2DAFF;
    --md-sys-color-on-tertiary-container: #251431;
    --md-sys-color-error: #BA1A1A;
    --md-sys-color-on-error: #FFFFFF;
    --md-sys-color-error-container: #FFDAD6;
    --md-sys-color-on-error-container: #410002;
    --md-sys-color-background: #FDFCFF;
    --md-sys-color-on-background: #1A1C1E;
    --md-sys-color-surface: #FDFCFF;
    --md-sys-color-on-surface: #1A1C1E;
    --md-sys-color-surface-variant: #E0E3E7;
    --md-sys-color-on-surface-variant: #43474E;
    --md-sys-color-outline: #73777F;
    --md-sys-color-outline-variant: #C3C7CF;
    --md-sys-elevation-level0: 0px 0px 0px 0px rgba(0,0,0,0);
    --md-sys-elevation-level1: 0px 1px 3px 1px rgba(0,0,0,0.15), 0px 1px 2px 0px rgba(0,0,0,0.30);
    --md-sys-elevation-level2: 0px 2px 6px 2px rgba(0,0,0,0.15), 0px 1px 2px 0px rgba(0,0,0,0.30);
    --md-sys-elevation-level3: 0px 4px 8px 3px rgba(0,0,0,0.15), 0px 1px 3px 0px rgba(0,0,0,0.30);
    --md-sys-shape-extra-small: 4px;
    --md-sys-shape-small: 8px;
    --md-sys-shape-medium: 12px;
    --md-sys-shape-large: 16px;
    --md-sys-shape-extra-large: 28px;
}

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

html {
    font-size: 16px;
}

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    line-height: 1.5;
    min-height: 100vh;
}

h1 { font-size: 2.25rem; font-weight: 400; letter-spacing: -0.25px; }
h2 { font-size: 1.75rem; font-weight: 400; letter-spacing: 0px; }
h3 { font-size: 1.5rem; font-weight: 400; letter-spacing: 0.15px; }

a {
    color: var(--md-sys-color-primary);
    text-decoration: none;
    font-weight: 500;
}
a:hover { text-decoration: underline; }

.app-bar {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: var(--md-sys-elevation-level2);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-bar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-bar-title {
    font-size: 1.375rem;
    font-weight: 500;
    letter-spacing: 0.15px;
}

.app-bar-nav {
    display: flex;
    gap: 4px;
    align-items: center;
}

.nav-link {
    color: var(--md-sys-color-on-primary);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--md-sys-shape-extra-large);
    font-weight: 500;
    font-size: 0.875rem;
    letter-spacing: 0.1px;
    transition: background 0.2s;
}
.nav-link:hover {
    background: rgba(255,255,255,0.15);
    text-decoration: none;
}

.main-content {
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px 16px;
}

.main-content.wide {
    max-width: 1200px;
}

.card {
    background: var(--md-sys-color-surface);
    border-radius: var(--md-sys-shape-medium);
    box-shadow: var(--md-sys-elevation-level1);
    padding: 24px;
    margin-bottom: 24px;
}

.card-title {
    margin-bottom: 24px;
}

.card-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}
.card-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.card-section-title {
    font-size: 1rem;
    font-weight: 500;
    color: var(--md-sys-color-primary);
    margin-bottom: 16px;
    letter-spacing: 0.15px;
}

.field {
    margin-bottom: 20px;
}

.field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.field input,
.field select,
.field textarea {
    display: block;
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    font-family: 'Roboto', sans-serif;
    color: var(--md-sys-color-on-surface);
    background: var(--md-sys-color-surface-variant);
    border: none;
    border-bottom: 2px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-extra-small) var(--md-sys-shape-extra-small) 0 0;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
    line-height: 1.5;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-bottom-color: var(--md-sys-color-primary);
    background: #D6E4F7;
}

.field input:hover,
.field select:hover,
.field textarea:hover {
    background: #D6E4F7;
}

.field textarea {
    resize: vertical;
    min-height: 100px;
    border-radius: var(--md-sys-shape-extra-small);
}

.field select {
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' viewBox='0 -960 960 960' width='24'%3E%3Cpath fill='%2343474E' d='M480-344 240-584l56-56 184 184 184-184 56 56-240 240Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 40px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 24px;
    font-family: 'Roboto', sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.1px;
    line-height: 1.25;
    border: none;
    border-radius: var(--md-sys-shape-extra-large);
    cursor: pointer;
    transition: box-shadow 0.2s, background 0.2s;
    text-decoration: none;
    min-height: 40px;
}

.btn-filled {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    box-shadow: var(--md-sys-elevation-level1);
}
.btn-filled:hover {
    box-shadow: var(--md-sys-elevation-level2);
    background: #005488;
}

.btn-tonal {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}
.btn-tonal:hover {
    background: #C4D1E4;
}

.btn-text {
    background: transparent;
    color: var(--md-sys-color-primary);
    padding: 10px 12px;
}
.btn-text:hover {
    background: rgba(0,99,155,0.08);
}

.btn-danger {
    background: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
}
.btn-danger:hover {
    background: #991515;
}

.btn-small {
    padding: 6px 16px;
    font-size: 0.8125rem;
    min-height: 32px;
}

.btn-full {
    width: 100%;
}

.actions {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 24px;
    flex-wrap: wrap;
}

.table-wrap {
    overflow-x: auto;
    border-radius: var(--md-sys-shape-small);
    box-shadow: var(--md-sys-elevation-level1);
}

table.m3-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--md-sys-color-surface);
}

table.m3-table th {
    text-align: left;
    padding: 16px;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    color: var(--md-sys-color-on-surface-variant);
    background: var(--md-sys-color-surface);
    border-bottom: 2px solid var(--md-sys-color-outline-variant);
    text-transform: uppercase;
}

table.m3-table td {
    padding: 16px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

table.m3-table tr:hover td {
    background: var(--md-sys-color-surface-variant);
}

table.m3-table tr:last-child td {
    border-bottom: none;
}

table.m3-table .unread td {
    font-weight: 500;
}

table.m3-table .subject-link {
    color: var(--md-sys-color-on-surface);
    text-decoration: none;
}
table.m3-table .subject-link:hover {
    color: var(--md-sys-color-primary);
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.6875rem;
    font-weight: 500;
    border-radius: 10px;
    background: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
    line-height: 1;
}

.message {
    padding: 12px 16px;
    border-radius: var(--md-sys-shape-small);
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.message-info {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.message-error {
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}

.message-success {
    background: #D7F0DD;
    color: #00210E;
}

.thread-container {
    max-width: 800px;
    margin: 0 auto;
}

.thread-message {
    margin-bottom: 12px;
}

.thread-message-sent {
    text-align: right;
}

.thread-bubble {
    display: inline-block;
    max-width: 80%;
    text-align: left;
    border-radius: var(--md-sys-shape-medium);
    padding: 12px 16px;
    background: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
}

.thread-message-sent .thread-bubble {
    background: var(--md-sys-color-primary-container);
    border-color: #B0D1F0;
}

.thread-header {
    font-size: 0.75rem;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 4px;
}

.thread-subject {
    font-weight: 500;
    margin-bottom: 8px;
}

.thread-body {
    white-space: pre-wrap;
    font-size: 0.875rem;
    line-height: 1.6;
}

.links {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
    justify-content: center;
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--md-sys-color-on-surface-variant);
}

.empty-state p {
    font-size: 1rem;
    margin-bottom: 16px;
}

.loading {
    text-align: center;
    padding: 48px;
    color: var(--md-sys-color-on-surface-variant);
}

.centered-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 64px);
    padding: 24px 16px;
}

.centered-card {
    width: 100%;
    max-width: 420px;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--md-sys-color-on-surface-variant);
    border-top-color: var(--md-sys-color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

@media (max-width: 600px) {
    .app-bar-inner {
        padding: 0 12px;
    }
    .main-content {
        padding: 16px 12px;
    }
    .card {
        padding: 16px;
    }
    table.m3-table th,
    table.m3-table td {
        padding: 12px 8px;
    }
    .centered-card {
        max-width: 100%;
    }
}
