:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #1d2330;
    --muted: #6b7385;
    --border: #dfe3ea;
    --accent: #3b5bdb;
    --accent-text: #ffffff;
    --user-bg: #e7edff;
    --danger: #c92a2a;
    --ok-bg: #e6f6ea;
    --ok-text: #1f7a35;
    --bad-bg: #fdecec;
    --bad-text: #b02525;
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151b;
        --surface: #1a1e26;
        --surface-2: #222733;
        --text: #e4e7ee;
        --muted: #9099ab;
        --border: #2e3442;
        --accent: #6f8cff;
        --accent-text: #0d1020;
        --user-bg: #23305a;
        --danger: #ff7b7b;
        --ok-bg: #173523;
        --ok-text: #7fd99a;
        --bad-bg: #3a1c1c;
        --bad-text: #ff9b9b;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 0.9em ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
h1 { font-size: 1.4rem; margin: 0 0 8px; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.nowrap { white-space: nowrap; }

button, .button {
    display: inline-block;
    font: inherit;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    text-align: center;
}
button:hover, .button:hover { text-decoration: none; border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: none; padding: 0; color: var(--accent); }
button.link.danger { color: var(--danger); }
.block { display: block; width: 100%; }

input, select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.alert { padding: 10px 14px; border-radius: 8px; margin: 0 0 12px; border: 1px solid var(--border); background: var(--surface-2); }
.alert.error { background: var(--bad-bg); color: var(--bad-text); border-color: transparent; }
.alert.info { background: var(--surface-2); }

/* Üst menü */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 16px; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); padding: 4px 0; }
.topbar nav a.active { color: var(--text); border-bottom: 2px solid var(--accent); }
.topbar .logout { display: flex; gap: 10px; align-items: center; margin: 0; }
.topbar .user { color: var(--muted); }

/* Giriş */
.login-page { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
}
.login-card form { display: flex; flex-direction: column; gap: 8px; }
.login-card button { margin-top: 10px; }

/* Sohbet */
.chat-layout { display: grid; grid-template-columns: 1fr; height: calc(100vh - 53px); }
.chat-layout.with-sidebar { grid-template-columns: 280px 1fr; }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); padding: 14px; overflow-y: auto; }
.session-list { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 4px; }
.session-list li { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; padding: 8px 10px; border-radius: 8px; }
.session-list li.active { background: var(--surface-2); }
.session-list li a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; grid-column: 1 / -1; }
.session-list li .delete-session { justify-self: end; font-size: 0.82rem; }

.chat-main { display: flex; flex-direction: column; min-height: 0; padding: 16px 20px; gap: 12px; max-width: 980px; width: 100%; margin: 0 auto; }
.messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 4px; }
.messages .empty { margin: auto; text-align: center; }
.msg { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; background: var(--surface); max-width: 92%; }
.msg-user { align-self: flex-end; background: var(--user-bg); border-color: transparent; }
.msg-assistant { align-self: flex-start; }
.msg .meta { display: flex; gap: 12px; justify-content: space-between; font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.pending .body { color: var(--muted); font-style: italic; }
.msg.error { background: var(--bad-bg); color: var(--bad-text); border-color: transparent; }

.composer { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.composer .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.composer label { font-size: 0.82rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.composer .actions { display: flex; justify-content: space-between; align-items: center; }
.system-prompt summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }

/* Tablolar */
.page { padding: 20px; max-width: 1300px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.disabled-row { opacity: 0.6; }
.error-cell { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--surface-2); }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.bad { background: var(--bad-bg); color: var(--bad-text); }
.pager { display: flex; gap: 16px; justify-content: center; padding: 14px; }

@media (max-width: 760px) {
    .topbar { gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
    .chat-layout, .chat-layout.with-sidebar { grid-template-columns: 1fr; height: auto; min-height: calc(100vh - 53px); }
    .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 220px; }
    .chat-main { padding: 12px 16px; }
    .messages { min-height: 40vh; }
    .composer .row { grid-template-columns: 1fr; }
    .msg { max-width: 100%; }
    .page { padding: 16px; }
}
