[hidden] { display: none !important; }
.modal:not([hidden]) { display: flex; }
.logo .bot { display: block; object-fit: cover; }
.compact-sidebar-actions .user-badge { display: flex; align-items: center; gap: 6px; width: 100%; margin: 0; border: 1px solid rgba(200,163,90,.25); text-align: left; cursor: pointer; font: inherit; font-weight: 700; }
.compact-sidebar-actions .user-badge:hover { background: rgba(168,199,125,.28); }
#user-avatar { width: 28px; height: 28px; object-fit: cover; border-radius: 50%; flex: 0 0 auto; }
#user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-avatar-area { width: 80px; height: 80px; display: grid; place-items: center; overflow: hidden; border-radius: 50%; background: rgba(136,166,109,.2); font-size: 38px; }
.profile-avatar-area img { width: 100%; height: 100%; object-fit: cover; }
.modal-content input[type=file] { height: auto; padding: 10px; font-size: 13px; }
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(100%, 470px); padding: 32px; background: var(--white); border: 1px solid var(--beige); border-radius: 28px; box-shadow: 0 18px 55px rgba(49,88,62,.16); }
.auth-card h1 { color: var(--green-dark); margin-bottom: 8px; }
.auth-card p { color: var(--muted); line-height: 1.5; }
.auth-logo { width: 72px; height: 72px; border-radius: 20px; object-fit: cover; }
.auth-card form { display: grid; gap: 14px; }
.auth-card label { display: grid; gap: 5px; color: var(--green-dark); font-weight: 700; }
.auth-card input:not([type=checkbox]) { height: 46px; padding: 0 13px; border: 1px solid var(--beige); border-radius: 12px; font: inherit; }
.auth-card .checkbox-line { display: flex; align-items: center; font-size: 14px; }
.auth-card code { display: block; overflow-wrap: anywhere; padding: 14px; margin: 16px 0; border-radius: 12px; background: var(--cream); }
.auth-card .error { color: var(--danger); }
.upload-help { font-size: 11px; font-weight: 500; opacity: .78; }
.upload-case-label { color: var(--muted); font-size: 11px; font-weight: 700; }
.upload-case { width: 100%; flex: 0 0 auto; margin: 3px 0 6px; }
.header-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.case-line { color: var(--muted); font-size: 12px; margin: 0 5px 6px; }
.case-line select, .modal-content select { max-width: 100%; padding: 7px; border: 1px solid var(--beige); border-radius: 10px; background: var(--white); color: var(--green-dark); }
.chat-message { white-space: pre-wrap; }
.file-item .file-info { display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left; }
.file-item .file-info:focus-visible { outline: 2px solid var(--green-soft); }
.wide-modal { max-width: 780px; }
.document-text { max-height: 38vh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; padding: 13px; border-radius: 14px; background: rgba(233,222,199,.38); font: inherit; }
.document-preview { display: block; max-width: 100%; max-height: 45vh; object-fit: contain; margin: 10px auto; border-radius: 12px; }
.compact-form { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.compact-form input { width: auto; flex: 1 1 180px; }
.compact-form button { flex: 0 0 auto; }
.modal-list { display: grid; gap: 6px; margin: 12px 0; }
.modal-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px; border-radius: 12px; background: rgba(233,222,199,.35); }
.modal-row button, .related button { border: 0; border-radius: 10px; padding: 7px 10px; cursor: pointer; color: var(--green-dark); background: rgba(136,166,109,.2); }
.related { display: grid; gap: 6px; margin-top: 12px; }
.modal-content a.btn { text-decoration: none; display: inline-block; }
.toast { position: fixed; z-index: 2000; right: 20px; bottom: 20px; max-width: min(90vw, 500px); padding: 13px 17px; border-radius: 14px; color: white; background: var(--green-dark); box-shadow: 0 12px 30px #0003; }
.toast.error { background: var(--danger); }
@media (max-width: 820px) {
  .sidebar { height: auto !important; max-height: none !important; min-height: 45vh; overflow: visible !important; }
  #fileList.file-list { max-height: 35vh !important; min-height: 70px !important; }
  .main { height: 65vh; min-height: 420px; }
}

/* Keep the owner's archive and controls reachable even in a short window. */
body { height: auto; min-height: 100vh; overflow-y: auto; }
.app { height: auto; min-height: 100vh; align-items: start; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); }
.sidebar { height: auto !important; max-height: none !important; min-height: 100vh; overflow: visible !important; }
#fileList.file-list { flex: 0 0 auto !important; max-height: none !important; overflow: visible !important; }
.main { position: sticky; top: 0; height: 100vh; min-height: 440px; }
.header { padding: 17px 18px; }
.header h1 { font-size: 24px; }
.header-line { flex-wrap: wrap; }
.header-line > div:first-child { flex: 1 1 180px; min-width: 0; }
.marfa-logo-button { border: 0; padding: 0; border-radius: 50%; background: transparent; cursor: pointer; line-height: 0; }
.marfa-logo-button .bot { transition: transform .25s ease, box-shadow .25s ease; }
.marfa-logo-button:hover .bot, .marfa-logo-button:focus-visible .bot { transform: rotate(-7deg) scale(1.1); box-shadow: 0 8px 24px rgba(49,88,62,.38); }
.marfa-logo-button:focus-visible { outline: 3px solid var(--green-soft); outline-offset: 4px; }
.header-actions { display: flex; flex: 0 0 auto; align-items: center; flex-wrap: nowrap; justify-content: flex-end; gap: 7px; }
.header-actions .user-badge { display: flex; align-items: center; gap: 6px; max-width: 150px; margin: 0; padding: 9px 10px; border: 1px solid var(--beige); cursor: pointer; font: inherit; font-size: 13px; font-weight: 700; }
.header-actions .btn { padding: 9px 10px; font-size: 12px; }
.assignment-question { flex: 0 0 auto; margin: 0 0 10px; padding: 11px 14px; border: 1px solid rgba(136,166,109,.5); border-radius: 16px; background: rgba(255,253,247,.92); }
.assignment-question p { margin: 0 0 7px; font-weight: 700; overflow-wrap: anywhere; }
.assignment-question form { display: flex; flex-wrap: wrap; gap: 7px; }
.assignment-question input { flex: 1 1 190px; min-width: 0; padding: 9px; border: 1px solid var(--beige); border-radius: 10px; font: inherit; }
.assignment-question select, #document-topic-suggestion { display: block; width: 100%; min-width: 0; margin: 0 0 7px; padding: 7px; border: 1px solid var(--beige); border-radius: 10px; background: var(--white); color: var(--green-dark); font: inherit; }
.assignment-question button { padding: 8px 12px; border: 0; border-radius: 10px; color: var(--green-dark); background: rgba(168,199,125,.35); font-weight: 700; cursor: pointer; }
#document-modal { padding: 12px; }
#document-modal .document-dialog { display: flex; flex-direction: column; padding: 0; overflow: hidden; max-height: calc(100vh - 24px); }
.document-dialog-header { flex: 0 0 auto; padding: 15px 20px 8px; border-bottom: 1px solid rgba(200,163,90,.22); }
.document-dialog-header h2 { margin: 0 0 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 20px; }
.document-classification { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.document-classification label { display: grid; gap: 3px; margin: 0; font-size: 12px; }
.document-classification select { width: 100%; min-width: 0; }
#document-country-source { margin: 4px 0 0; font-size: 11px; }
.document-dialog-body { flex: 1 1 auto; min-height: 30px; overflow-y: auto; padding: 8px 20px 16px; }
.document-download { margin-top: 12px; }
.document-dialog-footer, .document-dialog-preview-close { flex: 0 0 auto; padding: 10px 20px 14px; border-top: 1px solid rgba(200,163,90,.3); background: var(--white); }
.document-dialog-footer label { margin: 0 0 5px; font-size: 13px; }
.document-dialog-controls { display: flex; flex-wrap: wrap; gap: 7px; }
.document-dialog-controls input { flex: 1 1 180px; width: auto; min-width: 0; height: 40px; }
.document-dialog-controls .btn, .document-dialog-preview-close .btn { padding: 9px 13px; }
#document-context-status { margin: 4px 0 0; max-height: 2.8em; overflow-y: auto; line-height: 1.4; }
#document-context-status:empty, #document-country-source:empty { display: none; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { min-height: 0; }
  .main { position: static; height: 70vh; min-height: 480px; }
  .header-line { align-items: flex-start; flex-wrap: wrap; }
  .header-actions { justify-content: flex-start; }
  #fileList.file-list { max-height: none !important; }
}
@media (max-height: 500px) { .main { position: static; min-height: 440px; } #document-modal { padding: 6px; } #document-modal .document-dialog { max-height: calc(100vh - 12px); } }
@media (prefers-reduced-motion: reduce) { .marfa-logo-button .bot { transition: none; } }

/* On phones the assistant and its controls come first, followed by the archive. */
@media (max-width: 820px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  body { touch-action: pan-y pinch-zoom; overscroll-behavior-x: none; }
  .app { display: flex; flex-direction: column; width: 100%; min-width: 0; }
  .main { order: -1; width: 100%; max-width: 100%; min-width: 0; padding: 12px; }
  .sidebar { width: 100%; max-width: 100%; min-width: 0; }
  .header-actions { flex-wrap: wrap; max-width: 100%; min-width: 0; }
  .header-actions .user-badge { min-width: 0; }
  .archive-folders { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .archive-folder, .archive-folder > span:first-child { min-width: 0; overflow-wrap: anywhere; }
  .chat-input, .chat-input input { min-width: 0; }
  .chat-message { overflow-wrap: anywhere; }
}
