/* ===================================================
   PsyTeam Steyr — Therapy App CSS
   Privacy-first, no external fonts or resources
   =================================================== */

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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #2d3b2a;
    background-color: #f6f8f4;
}

a { color: #6b8f5b; text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Navigation --- */
.navbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 2rem;
    background: #3d4f35;
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-wrap: wrap;
}

.nav-brand {
    display: flex;
    align-items: center;
}

.nav-brand a {
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-brand img {
    height: 32px;
    width: auto;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.nav-link {
    color: #cbd5e1;
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.9rem;
    text-decoration: none;
    transition: background 0.15s;
}

.nav-link:hover, .nav-link.active {
    background: rgba(255,255,255,0.15);
    color: white;
    text-decoration: none;
}

.nav-link--dropdown {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-caret {
    font-size: 0.6rem;
    opacity: 0.7;
}

/* --- Nav dropdown menu --- */
.nav-dropdown {
    position: relative;
}

.nav-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.25rem;
    min-width: 180px;
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15), 0 2px 6px rgba(0,0,0,0.1);
    z-index: 150;
    overflow: hidden;
    padding: 0.25rem 0;
}

.nav-dropdown-item {
    display: block;
    padding: 0.5rem 1rem;
    color: #2d3b2a;
    font-size: 0.875rem;
    text-decoration: none;
    transition: background 0.1s;
}

.nav-dropdown-item:hover {
    background: #f1f5f9;
    text-decoration: none;
}

.nav-dropdown-divider {
    height: 1px;
    background: #e2e8f0;
    margin: 0.25rem 0;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.nav-search {
    margin-left: auto;
    position: relative;
}

.nav-search-input {
    padding: 0.3rem 0.625rem;
    border: 1px solid #475569;
    border-radius: 0.375rem;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 0.8rem;
    width: 160px;
    transition: all 0.2s;
}

.nav-search-input::placeholder {
    color: #94a3b8;
}

.nav-search-input:focus {
    outline: none;
    width: 260px;
    background: rgba(255,255,255,0.15);
    border-color: #8faa7e;
}

[x-cloak] { display: none !important; }

/* --- Autocomplete dropdown --- */
.ac-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.375rem;
    width: 340px;
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15), 0 2px 8px rgba(0,0,0,0.1);
    z-index: 200;
    overflow: hidden;
}

.ac-section {
    padding: 0.25rem 0;
}

.ac-section-title {
    display: block;
    padding: 0.375rem 0.875rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 0.05em;
}

.ac-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    color: #2d3b2a;
    text-decoration: none;
    transition: background 0.1s;
}

.ac-item:hover {
    background: #f1f5f9;
    text-decoration: none;
}

.ac-icon {
    font-size: 1rem;
    flex-shrink: 0;
    width: 1.5rem;
    text-align: center;
}

.ac-label {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
}

.ac-label strong {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ac-sub {
    display: block;
    font-size: 0.75rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ac-footer {
    display: block;
    padding: 0.5rem 0.875rem;
    font-size: 0.8rem;
    color: #6b8f5b;
    text-align: center;
    border-top: 1px solid #e2e8f0;
    text-decoration: none;
}

.ac-footer:hover {
    background: #f8fafc;
    text-decoration: none;
}

.ac-section + .ac-section {
    border-top: 1px solid #e2e8f0;
}

.nav-email { color: #94a3b8; }

.nav-link-sm {
    color: #94a3b8;
    font-size: 0.85rem;
}

.btn-logout {
    background: none;
    border: 1px solid #475569;
    color: #cbd5e1;
    padding: 0.25rem 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}
.btn-logout:hover { background: rgba(255,255,255,0.1); color: white; }

/* --- Main content --- */
.main-content {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* --- Footer --- */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: #64748b;
    font-size: 0.8rem;
    border-top: 1px solid #e2e8f0;
    margin-top: 3rem;
}

/* --- Alerts --- */
.alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.5rem;
    font-size: 0.9rem;
}

.alert-error { background: #fef2f2; color: #dc2626; border-bottom: 2px solid #fca5a5; }
.alert-success { background: #f0fdf4; color: #16a34a; border-bottom: 2px solid #86efac; }

.alert-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: inherit;
    opacity: 0.6;
}
.alert-close:hover { opacity: 1; }

/* --- Cards --- */
.card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    transition: all 0.15s;
}

.btn-primary {
    background: #6b8f5b;
    color: white;
    border-color: #6b8f5b;
}
.btn-primary:hover { background: #5a7a4c; text-decoration: none; color: white; }

.btn-secondary {
    background: white;
    color: #374151;
    border-color: #d1d5db;
}
.btn-secondary:hover { background: #f9fafb; text-decoration: none; }

.btn-danger {
    background: white;
    color: #dc2626;
    border-color: #fca5a5;
}
.btn-danger:hover { background: #fef2f2; text-decoration: none; }

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.8rem;
}

/* --- Forms --- */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.375rem;
}

.form-label .optional {
    color: #9ca3af;
    font-weight: normal;
    font-size: 0.8rem;
}

.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    color: #1a1a2e;
    background: white;
    transition: border-color 0.15s;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
    outline: none;
    border-color: #8faa7e;
    box-shadow: 0 0 0 3px rgba(143,170,126,0.15);
}

.form-textarea { min-height: 100px; resize: vertical; }

.form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1.5rem;
}

/* --- Tables --- */
.table-wrapper { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    text-align: left;
    padding: 0.625rem 0.875rem;
    font-weight: 600;
    color: #6b7280;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #e5e7eb;
}

td {
    padding: 0.75rem 0.875rem;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* --- Status badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-pending    { background: #f3f4f6; color: #6b7280; }
.badge-uploading  { background: #eef3eb; color: #6b8f5b; }
.badge-transcribing { background: #fef3c7; color: #d97706; }
.badge-summarizing  { background: #fef3c7; color: #d97706; }
.badge-complete   { background: #f0fdf4; color: #16a34a; }
.badge-manual     { background: #eff6ff; color: #2563eb; }
.badge-error      { background: #fef2f2; color: #dc2626; }

/* --- Page headings --- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
}

.page-subtitle {
    font-size: 0.9rem;
    color: #64748b;
    margin-top: 0.25rem;
}

/* --- Login page --- */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #8faa7e;
    padding: 1.5rem;
}

.login-card {
    background: white;
    border-radius: 1rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1e293b;
    text-align: center;
    margin-bottom: 0.5rem;
}

.login-subtitle {
    text-align: center;
    color: #64748b;
    font-size: 0.875rem;
    margin-bottom: 2rem;
}

.login-privacy {
    font-size: 0.75rem;
    color: #94a3b8;
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #f1f5f9;
}

/* --- Stats grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
    text-align: center;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: #6b8f5b;
}

.stat-label {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 0.25rem;
}

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #94a3b8;
}

.empty-state h3 { font-size: 1rem; color: #6b7280; margin-bottom: 0.5rem; }
.empty-state p { font-size: 0.875rem; margin-bottom: 1.25rem; }

/* --- HTMX loading indicator --- */
.htmx-request .htmx-indicator { display: inline-flex !important; }
.htmx-indicator { display: none; }

/* --- Calendar view --- */
.calendar-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.calendar-nav-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
    min-width: 180px;
    text-align: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    overflow: hidden;
}

.calendar-weekday {
    padding: 0.5rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.calendar-day {
    min-height: 90px;
    padding: 0.375rem;
    border-right: 1px solid #f1f5f9;
    border-bottom: 1px solid #f1f5f9;
    background: white;
    cursor: pointer;
    transition: background 0.1s;
    position: relative;
}

.calendar-day:nth-child(7n) {
    border-right: none;
}

.calendar-day:hover {
    background: #f0f5ed;
}

.calendar-day--today {
    background: #eef3eb;
    box-shadow: inset 0 0 0 2px #8faa7e;
}

.calendar-day--today:hover {
    background: #e2ebdc;
}

.calendar-day--outside {
    background: #f8fafc;
    opacity: 0.5;
}

.calendar-day--outside:hover {
    background: #f1f5f9;
}

.calendar-day--weekend {
    background: #fafafa;
}

.calendar-day--weekend.calendar-day--today {
    background: #eff6ff;
}

.calendar-day-number {
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.25rem;
}

.calendar-day--outside .calendar-day-number {
    color: #9ca3af;
}

.calendar-day--today .calendar-day-number {
    color: #6b8f5b;
}

.calendar-event {
    display: block;
    padding: 0.125rem 0.375rem;
    margin-bottom: 0.125rem;
    border-radius: 0.25rem;
    font-size: 0.7rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    transition: opacity 0.1s;
}

.calendar-event:hover {
    opacity: 0.8;
    text-decoration: none;
}

.calendar-event--caldav {
    background: #e2ebdc;
    color: #3d4f35;
}

.calendar-event--complete {
    background: #dcfce7;
    color: #166534;
}

.calendar-event--pending {
    background: #f3f4f6;
    color: #6b7280;
}

.calendar-event--progress {
    background: #fef3c7;
    color: #92400e;
}

.calendar-event--error {
    background: #fef2f2;
    color: #991b1b;
}

.calendar-day-add {
    position: absolute;
    top: 0.25rem;
    right: 0.375rem;
    font-size: 0.85rem;
    color: #94a3b8;
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s;
    line-height: 1;
}

.calendar-day:hover .calendar-day-add {
    opacity: 1;
}

.calendar-day-add:hover {
    color: #6b8f5b;
    text-decoration: none;
}

/* --- Timeline --- */
.timeline {
    position: relative;
    padding-left: 1.75rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 0.5rem;
    top: 0.5rem;
    bottom: 0.5rem;
    width: 2px;
    background: #e2e8f0;
}

.timeline-item {
    position: relative;
    padding-bottom: 1.25rem;
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #d1d5db;
    background: white;
    position: absolute;
    left: -1.75rem;
    top: 0.35rem;
    z-index: 1;
}

.timeline-dot--complete {
    border-color: #16a34a;
    background: #dcfce7;
}

.timeline-dot--error {
    border-color: #dc2626;
    background: #fef2f2;
}

.timeline-dot--progress {
    border-color: #d97706;
    background: #fef3c7;
}

.timeline-dot--pending {
    border-color: #9ca3af;
    background: #f3f4f6;
}

.timeline-content {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: #f8fafc;
    border-radius: 0.5rem;
    border: 1px solid #f1f5f9;
}

.timeline-content:hover {
    background: #f1f5f9;
}

/* Note timeline items (indigo) */
.timeline-dot--note {
    border-color: #6366f1;
    background: #eef2ff;
}

.timeline-content--note {
    border-left: 3px solid #6366f1;
}

.badge-note {
    background: #eef2ff;
    color: #4338ca;
}

/* Document timeline items (teal) */
.timeline-dot--document {
    border-color: #0d9488;
    background: #f0fdfa;
}

.timeline-content--document {
    border-left: 3px solid #0d9488;
}

.badge-document {
    background: #f0fdfa;
    color: #0f766e;
}

.doc-file-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.btn-icon-danger {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.btn-icon-danger:hover {
    color: #dc2626;
}

/* --- Diagnosis list --- */
.diag-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.diag-item {
    padding: 0.625rem 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-left: 3px solid #6366f1;
    border-radius: 0.5rem;
}

.diag-item-main {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.diag-code {
    font-weight: 700;
    font-size: 0.875rem;
    color: #6366f1;
    min-width: 4rem;
}

.diag-desc {
    font-size: 0.875rem;
    color: #1e293b;
    flex: 1;
}

.diag-item-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.25rem;
    font-size: 0.8rem;
}

/* --- Utilities --- */
.text-muted { color: #64748b; font-size: 0.875rem; }
.text-danger { color: #dc2626; }
.text-success { color: #16a34a; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.gap-2 { gap: 0.5rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
