:root {
  --bg: #f7f6f3; --surface: #fff; --border: #e4e1da; --text: #1f1d1a; --muted: #6f6a62;
  --accent: #b5532f; --accent-soft: #f6e7e0; --focus: #fff4c2;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; height: 100vh; display: flex; overflow: hidden; }
button { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 8px 12px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.link { border: none; background: none; padding: 4px; color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }

/* sidebar */
#sidebar { width: 260px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; padding: 14px; border-right: 1px solid var(--border); background: #efede8; }
.brand { font-weight: 700; font-size: 17px; padding: 4px 2px 8px; }
#conversations { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv { display: flex; align-items: center; border-radius: 8px; padding: 7px 8px; cursor: pointer; font-size: 14px; }
.conv:hover { background: #e4e1da; }
.conv.active { background: var(--surface); box-shadow: 0 0 0 1px var(--border); }
.conv span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv small { color: var(--muted); margin-left: 4px; }
.conv .del { visibility: hidden; }
.conv:hover .del { visibility: visible; }
.sidebar-footer { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--border); padding-top: 10px; }
.sidebar-footer button { text-align: left; }
.user-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.user-row form { margin: 0; }

/* chat */
.view { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.view[hidden] { display: none; }
.view-title { padding: 14px 24px; font-weight: 600; border-bottom: 1px solid var(--border); background: var(--surface); display: flex; align-items: center; gap: 10px; }
.view-title small { color: var(--muted); font-weight: 400; }
.spacer { flex: 1; }
#messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; }
.msg { max-width: 860px; width: 100%; margin: 0 auto; line-height: 1.6; }
.msg.user { background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; }
.msg.user .author { font-size: 12px; color: var(--muted); }
.msg.user .files { font-size: 13px; color: var(--muted); margin-top: 4px; }
.msg.assistant .body { overflow-wrap: anywhere; }
.msg.assistant .body table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.msg.assistant .body th, .msg.assistant .body td { border: 1px solid var(--border); padding: 4px 8px; vertical-align: top; }
.msg.assistant .body blockquote { border-left: 3px solid var(--border); margin: 8px 0; padding: 2px 12px; color: #4b4740; }
details.steps { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
details.steps summary { cursor: pointer; list-style: none; display: inline-flex; gap: 4px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 12px; max-width: 100%; }
details.steps summary::-webkit-details-marker { display: none; }
.steps-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 520px; }
details.steps[open] .steps-last { display: none; }
details.steps ol { margin: 8px 0 0; padding-left: 28px; display: grid; gap: 3px; }
details.steps li .icon { display: inline-block; width: 22px; }
details.steps li .detail { color: #8b857c; }
details.thinking { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
details.thinking div { white-space: pre-wrap; padding: 6px 0 0 12px; border-left: 2px solid var(--border); }
.error-box { color: #a32020; background: #fdecec; border-radius: 8px; padding: 8px 12px; }
.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.cite { display: inline-block; font-size: 12px; line-height: 1.4; padding: 0 7px; margin: 0 1px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); cursor: pointer; text-decoration: none; white-space: nowrap; }
.cite:hover { background: var(--accent); color: #fff; }

.welcome { max-width: 760px; margin: 6vh auto 0; color: var(--muted); }
.welcome h1 { color: var(--text); }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.suggestions button { text-align: left; color: var(--text); }

#composer { padding: 12px 24px 16px; background: var(--bg); }
.composer-row { max-width: 860px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 8px; }
#input { flex: 1; border: none; outline: none; resize: none; font: inherit; max-height: 220px; padding: 6px; }
#mode { font: inherit; font-size: 13px; border: 1px solid var(--border); border-radius: 8px; padding: 7px 6px; background: var(--surface); }
.badge { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.badge b { color: var(--text); font-weight: 600; }
.badge button { font-size: 12px; padding: 1px 8px; }
.attach { cursor: pointer; font-size: 20px; padding: 4px 6px; }
#attachments { max-width: 860px; margin: 0 auto 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 13px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; }
.hint { max-width: 860px; margin: 6px auto 0; font-size: 12px; color: var(--muted); text-align: center; }

/* source panel */
#panel { width: 46%; max-width: 760px; min-width: 380px; display: flex; flex-direction: column; border-left: 1px solid var(--border); background: var(--surface); }
#panel[hidden] { display: none; }
#panel header { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
#panel-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#panel-back { color: var(--accent); font-weight: 600; }
.player { width: 100%; max-height: 70vh; background: #000; border-radius: 8px; }
.desc { font-size: 14px; color: #4b4740; }
#panel-body { flex: 1; overflow-y: auto; padding: 12px 16px; }
#panel-body iframe { width: 100%; height: 100%; border: none; min-height: 80vh; }
#panel-body img, #panel-body video { max-width: 100%; border-radius: 8px; }
.wa { display: flex; flex-direction: column; gap: 6px; }
.wa-msg { max-width: 85%; padding: 6px 10px; border-radius: 10px; font-size: 14px; white-space: pre-wrap; }
.wa-msg.Abdulkadir { align-self: flex-end; background: #dcf8c6; }
.wa-msg.Ecenur { align-self: flex-start; background: #f0f0f0; }
.wa-msg.focus { outline: 2px solid var(--accent); background: var(--focus); }
.wa-msg .meta { font-size: 11px; color: var(--muted); }
.wa-more { align-self: center; font-size: 13px; }
.guide { font-size: 14px; line-height: 1.55; }
.guide table { border-collapse: collapse; font-size: 13px; }
.guide th, .guide td { border: 1px solid var(--border); padding: 4px 6px; vertical-align: top; }


/* login */
body.login { align-items: center; justify-content: center; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box p { margin: 0; color: var(--muted); font-size: 14px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.login-box input { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.error { color: #a32020 !important; }

@media (max-width: 900px) {
  #sidebar { display: none; }
  #panel { position: fixed; inset: 0; width: 100%; max-width: none; min-width: 0; z-index: 10; }
  .suggestions { grid-template-columns: 1fr; }
}

/* sidebar views */
.views { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.view-btn { text-align: left; display: flex; align-items: center; gap: 6px; }
.view-btn.active { background: var(--surface); box-shadow: 0 0 0 2px var(--accent-soft); font-weight: 600; }
.count { margin-left: auto; font-size: 11px; color: var(--muted); }
#mail-badge { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 0 8px; }
#mail-badge.alert { background: var(--accent); color: #fff; }
#new-chat[hidden], #conversations[hidden] { display: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* documents explorer */
.docs { flex: 1; display: flex; min-height: 0; }
.tree { width: 300px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--border); padding: 8px 4px; background: #faf9f6; font-size: 14px; }
.tree-row { display: flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.tree-row:hover { background: #efede8; }
.tree-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.twisty { width: 14px; display: inline-block; color: var(--muted); }
.tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .count { margin-left: 4px; }
.docs-main { flex: 1; overflow-y: auto; padding: 12px 18px; min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input[type=search] { flex: 1; min-width: 180px; font: inherit; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; }
.toolbar select, #mail-filter, #mail-kind { font: inherit; font-size: 13px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.crumb { width: 100%; font-size: 13px; color: var(--muted); }
.check { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); }
.doc-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); padding: 6px; position: sticky; top: 0; background: var(--surface); }
.doc-table td { border-bottom: 1px solid var(--border); padding: 7px 6px; vertical-align: top; }
.doc-table tbody tr:hover { background: var(--bg); cursor: pointer; }
.doc-table .ico { font-size: 18px; width: 28px; }
.doc-name { font-weight: 500; }
.doc-desc { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-cat { font-size: 11px; color: #a39d93; }
.upload-box { display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 12px; font-size: 14px; }
.upload-box label { display: grid; gap: 3px; }
.upload-box input { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; }
.upload-box .row { display: flex; gap: 8px; align-items: center; }

/* correspondence */
#letters { flex: 1; overflow-y: auto; padding: 18px 24px; display: flex; flex-direction: column; gap: 12px; }
.letter { max-width: 760px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; align-self: flex-start; }
.letter.mine { align-self: flex-end; background: #f3f8f1; }
.letter.request { border-left: 4px solid var(--accent); }
.letter .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.letter .text { margin: 6px 0; line-height: 1.5; }
.letter .files { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.letter .actions { font-size: 13px; }
.quote { font-size: 12px; color: var(--muted); border-left: 3px solid var(--border); padding-left: 8px; margin-top: 4px; }
.pill { font-size: 11px; border-radius: 999px; padding: 1px 8px; }
.pill.open { background: #fdecec; color: #a32020; }
.pill.done { background: #e8f5e9; color: #2e7d32; }
.empty { text-align: center; margin-top: 10vh; }
#mail-composer { padding: 12px 24px 16px; }
#mail-composer .composer-row textarea { flex: 1; border: none; outline: none; resize: vertical; font: inherit; padding: 6px; }
.reply-info { max-width: 860px; margin: 0 auto 6px; font-size: 13px; color: var(--muted); }
#mail-attachments { max-width: 860px; margin: 0 auto 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.wa-btn { font-size: 13px; background: #e8f8ee; border-color: #b9e3c7; color: #1b6b3a; }
#wa-buttons.pulse .wa-btn { animation: pulse 1.2s ease-in-out 4; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px #b9e3c7; } }
@media (max-width: 900px) { .tree { display: none; } }

/* elements with a display rule must still honour the hidden attribute */
[hidden] { display: none !important; }
/* with a file open in the side panel, give the file list the room the folder tree used */
body:has(#panel:not([hidden])) .tree { display: none; }
