/* ---------- Tema değişkenleri ---------- */
:root,
[data-theme="light"] {
    --bg: #f5f6f8;
    --bg-soft: #ffffff;
    --card: #ffffff;
    --border: #e3e6ec;
    --border-strong: #d1d5de;
    --text: #1c2130;
    --muted: #666e80;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-text: #ffffff;
    --primary-soft: #eaf0fe;
    --green: #158a4d;
    --green-soft: #e4f6ec;
    --yellow: #a2650a;
    --yellow-soft: #fbf0dc;
    --red: #c8322a;
    --red-soft: #fbe7e5;
    --violet: #6d3fc0;
    --violet-soft: #f0e9fb;
    --shadow: 0 1px 2px rgba(20, 24, 38, .06), 0 1px 1px rgba(20, 24, 38, .04);
    --radius: 10px;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #14161c;
    --bg-soft: #1a1d25;
    --card: #1e222c;
    --border: #2c313e;
    --border-strong: #3a4051;
    --text: #eaecf1;
    --muted: #9aa1b5;
    --primary: #4b8bff;
    --primary-hover: #6ea0ff;
    --primary-text: #0b1220;
    --primary-soft: #1c2c4d;
    --green: #3ecf82;
    --green-soft: #10301f;
    --yellow: #e0a83f;
    --yellow-soft: #362a10;
    --red: #f0685f;
    --red-soft: #3a1a19;
    --violet: #b295ec;
    --violet-soft: #291f42;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
}

/* ---------- Sıfırlama ve temel ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
    margin: 0;
    min-width: 0;
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { overflow-wrap: break-word; }
button, input, select, textarea { font-family: inherit; }

.container { max-width: 1080px; margin: 0 auto; padding: 20px 16px 60px; width: 100%; }

/* ---------- Üst bar ---------- */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 15px; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: 8px;
    background: var(--primary);
    color: var(--primary-text); font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.brand-full { display: none; }
.brand-short { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 560px) {
    .brand-short { display: none; }
    .brand-full { display: inline; }
}

.user-menu { position: relative; }
.user-menu-trigger {
    display: flex; align-items: center; gap: 8px; width: 100%;
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    padding: 6px 10px; cursor: pointer; color: var(--text); text-align: left;
}
.user-menu-trigger:hover { border-color: var(--border-strong); }
.user-menu-name {
    font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    min-width: 0; flex: 1 1 auto;
}
.user-menu-caret { color: var(--muted); font-size: 11px; flex-shrink: 0; }

.role-pill {
    display: inline-block; font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em; padding: 1px 7px; border-radius: 20px; line-height: 1.5;
}
.user-menu-trigger .role-pill { flex-shrink: 0; }
.role-pill-admin { background: var(--text); color: var(--bg); }
.role-pill-editor { background: transparent; color: var(--muted); border: 1px solid var(--border-strong); }

.user-menu-panel {
    display: none;
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
    min-width: 180px; background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; flex-direction: column; gap: 2px;
}
.user-menu-panel.is-open { display: flex; }
.user-menu-panel a { padding: 9px 10px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--text); }
.user-menu-panel a:hover { background: var(--bg); text-decoration: none; }

@media (max-width: 859px) {
    /* .user-menu-name zaten flex:1 1 auto olduğundan büyüyüp rozet+oku sağa iter, ayrıca space-between gerekmiyor */
    .user-menu-panel { position: static; box-shadow: none; border: none; padding: 4px 0 0 40px; margin-top: 2px; }
}

.nav-toggle {
    display: flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--card); cursor: pointer; padding: 0;
}
.nav-toggle span { display: block; width: 18px; height: 2px; background: var(--text); margin: 0 auto; }

.topnav {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
    margin-top: 12px;
}
.topnav.is-open { display: flex; }
.topnav > a {
    padding: 10px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--text);
}
.topnav > a:hover { background: var(--bg); text-decoration: none; }

.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--card); color: var(--text); cursor: pointer; font-size: 16px;
    align-self: flex-start;
}
.theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-moon { display: inline; }

@media (min-width: 860px) {
    .nav-toggle { display: none; }
    .topbar { flex-wrap: nowrap; padding: 14px 24px; }
    .topnav {
        display: flex !important;
        flex-direction: row;
        align-items: center;
        width: auto;
        margin-top: 0;
        gap: 6px;
    }
    .topnav > a { padding: 8px 10px; }
    .theme-toggle { align-self: center; margin-left: 4px; }
    .user-menu-trigger { width: auto; }
}

/* ---------- Genel yapı ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; }

h1 { font-size: 24px; margin: 0 0 12px; letter-spacing: -0.01em; }
h3 { margin: 0 0 6px; font-size: 16px; }
.muted { color: var(--muted); }
.muted.small { font-size: 13px; }

/* ---------- Butonlar ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px;
    padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
    font-size: 14px; font-weight: 600; cursor: pointer; background: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--border-strong); }
.btn-block { width: 100%; }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.btn-disabled { background: var(--green-soft); border-color: transparent; color: var(--green); cursor: default; }
.inline-form { display: inline-block; }

/* ---------- Filtreler ---------- */
.filters {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    background: var(--bg-soft); padding: 14px; border-radius: var(--radius); border: 1px solid var(--border);
}
.filters select, .filters input:not([type="checkbox"]):not([type="radio"]),
.rb-form input:not([type="checkbox"]):not([type="radio"]), .rb-form select, .rb-form textarea,
.login-card input {
    background: var(--card); color: var(--text); border: 1px solid var(--border);
    border-radius: 8px; padding: 10px 12px; font-size: 15px; width: 100%; min-height: 42px;
}
.filters .search-input { flex: 1 1 auto; min-width: 0; }
.filters > .btn { flex: 0 0 auto; }

.filters-secondary { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
.filters-secondary select {
    width: auto; flex: 1 1 160px; min-height: 38px; padding: 7px 10px; font-size: 13px;
}

/* Checkbox / radio: tarayıcı varsayılan boyutuna dön, formdaki genel input kuralından muaf tut */
.rb-form input[type="checkbox"], .rb-form input[type="radio"],
.filters input[type="checkbox"], .filters input[type="radio"] {
    width: 16px; height: 16px; min-height: 0; flex: 0 0 auto; accent-color: var(--primary); cursor: pointer;
}

@media (min-width: 620px) {
    .filters { flex-direction: row; flex-wrap: wrap; align-items: center; }
    .filters-secondary { width: auto; flex: 1 1 auto; }
}

.active-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; }
.filter-chip {
    display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
    padding: 4px 10px; border-radius: 20px; background: var(--primary-soft); color: var(--primary);
}
.filter-chip:hover { text-decoration: none; opacity: .8; }
.filter-chip-clear { background: none; color: var(--muted); text-decoration: underline; }

.result-count { margin: 0 0 12px; }

/* ---------- Sayfalama ---------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 28px 0 10px; }
.pagination-pages { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pagination-page {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--text);
}
.pagination-page:hover { background: var(--card); text-decoration: none; }
.pagination-page-current { background: var(--primary); color: var(--primary-text); }
.pagination-ellipsis { color: var(--muted); padding: 0 2px; }

/* ---------- Kart ızgarası ---------- */
.card-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 620px) { .card-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .card-grid { grid-template-columns: repeat(3, 1fr); } }

.rb-card {
    display: block; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; color: var(--text); box-shadow: var(--shadow); min-width: 0;
}
.rb-card:hover { border-color: var(--primary); text-decoration: none; }
.rb-card-top { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.rb-summary { font-size: 14px; min-height: 20px; overflow-wrap: break-word; }
.rb-meta { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* ---------- Rozetler ve etiketler ---------- */
.badge {
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
    padding: 3px 9px; border-radius: 20px; display: inline-block; white-space: nowrap;
}
.severity-low { background: var(--primary-soft); color: var(--primary); }
.severity-medium { background: var(--yellow-soft); color: var(--yellow); }
.severity-high { background: var(--yellow-soft); color: var(--yellow); }
.severity-critical { background: var(--red-soft); color: var(--red); }
.stale-fresh { background: var(--green-soft); color: var(--green); }
.stale-due { background: var(--yellow-soft); color: var(--yellow); }
.stale-stale, .stale-never { background: var(--red-soft); color: var(--red); }
.badge.draft { background: var(--border); color: var(--muted); }

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 20px; border: 1px solid var(--border); white-space: nowrap; }
.chip-service { background: var(--primary-soft); color: var(--primary); }
.chip-incident { background: var(--violet-soft); color: var(--violet); }

.empty-state { text-align: center; padding: 50px 16px; color: var(--muted); grid-column: 1 / -1; }

/* ---------- Giriş ---------- */
.login-wrap { display: flex; justify-content: center; padding-top: 40px; }
.login-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 28px; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

/* ---------- Formlar ---------- */
.rb-form { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
.rb-form-narrow { max-width: 400px; }
.rb-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.rb-form textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; resize: vertical; }
.form-grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 560px) { .form-grid-2 { grid-template-columns: 1fr 1fr; } }
.tag-fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.tag-fieldset legend { color: var(--muted); font-size: 13px; padding: 0 6px; }
.tag-check-row { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.tag-check { flex-direction: row !important; align-items: center; gap: 6px !important; font-size: 14px; color: var(--text); }
.checkbox-line { flex-direction: row !important; align-items: center; gap: 8px !important; }
.md-toolbar { margin-bottom: 4px; }
.md-preview-hidden { display: none; }
#md-preview { border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px; overflow-wrap: break-word; }

.view-head { margin-bottom: 24px; }
.action-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }

/* ---------- Yönetim sayfaları (Etiketler / Kullanıcılar) ---------- */
.tag-admin-section {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 16px; margin-bottom: 20px; overflow-x: hidden;
}
.tag-admin-section h3 { margin-bottom: 12px; }
.inline-fields { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-fields input, .inline-fields select {
    background: var(--card); color: var(--text); border: 1px solid var(--border);
    border-radius: 8px; padding: 7px 10px; font-size: 14px; min-height: 36px; width: auto;
}
.merge-form { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }

.tags-grid { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 860px) { .tags-grid { grid-template-columns: 1fr 1fr; } }

.tag-add-form { margin-bottom: 14px; }
.tag-add-form input[type="text"] { flex: 1 1 auto; min-width: 0; }

.tag-quick-filter {
    display: block; width: 100%; margin-bottom: 10px; background: var(--card); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 13px; min-height: 34px;
}

.tag-list { display: flex; flex-direction: column; gap: 4px; }
.tag-row, .tag-row-editing {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 8px 6px; border-radius: 8px;
}
.tag-row:hover { background: var(--bg); }
.tag-row-unused .chip { opacity: .55; }
.tag-usage { flex: 1 1 auto; min-width: 0; }
.tag-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.tag-row-editing input[type="text"] { flex: 1 1 160px; min-width: 0; }

.merge-details { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.merge-details summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--primary); list-style: revert; }
.merge-details .merge-form { margin-top: 10px; padding-top: 0; border-top: none; }

/* ---------- Ayarlar ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 760px) { .settings-grid { grid-template-columns: 280px 1fr; } }

.settings-profile-row { margin-bottom: 16px; }
.name-edit-form { margin-bottom: 4px; }
.name-edit-form input[type="text"] { font-weight: 700; font-size: 15px; flex: 1 1 auto; min-width: 0; }

.settings-meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; margin: 0 0 14px; }
.settings-meta dt { color: var(--muted); }
.settings-meta dd { margin: 0; }

.password-field { position: relative; display: block; }
/* !important: dış "input:not(checkbox):not(radio)" kısayol kuralı daha yüksek özgüllükte olduğundan padding-right'ı geçersiz kılıyor */
.password-field input { padding-right: 42px !important; }
.pw-toggle {
    position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
    width: 32px; height: 32px; border: none; background: none; cursor: pointer;
    font-size: 15px; color: var(--muted); border-radius: 6px;
}
.pw-toggle:hover { background: var(--bg); }

.markdown-body {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow); overflow-wrap: break-word; min-width: 0;
}
.markdown-body h2 { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.markdown-body code { background: var(--bg); padding: 2px 5px; border-radius: 4px; font-size: 13px; }
.markdown-body pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow-x: auto; }
.markdown-body img { border-radius: 6px; }
.markdown-body table { display: block; overflow-x: auto; max-width: 100%; border-collapse: collapse; }

@media (min-width: 700px) { .markdown-body { padding: 24px; } }

/* ---------- Yönetim tabloları (Etiketler / Kullanıcılar) ---------- */
.version-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); }
.version-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.version-table th, .version-table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
.version-table tbody tr:last-child td { border-bottom: none; }

.diff-view {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px; overflow-x: auto; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.diff-add-line { color: var(--green); }
.diff-remove-line { color: var(--red); }
.diff-same { color: var(--muted); }
.diff-field { margin: 6px 0; overflow-wrap: break-word; }
.diff-add { color: var(--green); }
.diff-remove { color: var(--red); text-decoration: line-through; }

/* ---------- Sürüm geçmişi zaman çizelgesi ---------- */
.timeline { position: relative; margin: 20px 0; padding-left: 26px; }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item:not(:last-child)::before {
    content: ''; position: absolute; left: -21px; top: 16px; bottom: -4px; width: 2px; background: var(--border);
}
.timeline-marker {
    position: absolute; left: -26px; top: 4px; width: 12px; height: 12px; border-radius: 50%;
    background: var(--primary); box-shadow: 0 0 0 3px var(--bg);
}
.timeline-marker-checkpoint { background: var(--green); }
.timeline-marker-origin { background: var(--muted); }

.timeline-card {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.timeline-card-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.timeline-note { font-weight: 600; margin: 0 0 4px; overflow-wrap: break-word; }
.timeline-diff { margin-top: 10px; }
.timeline-diff summary {
    cursor: pointer; font-size: 13px; font-weight: 600; color: var(--primary); list-style: revert;
}
.timeline-diff .diff-view { margin-top: 8px; }

.diffstat { display: inline-flex; gap: 6px; font-size: 12px; font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.diffstat-add { color: var(--green); }
.diffstat-remove { color: var(--red); }

@media (max-width: 480px) {
    .timeline { padding-left: 20px; }
    .timeline-marker { left: -20px; }
    .timeline-item:not(:last-child)::before { left: -15px; }
}

/* ---------- Uyarılar ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-error { background: var(--red-soft); color: var(--red); border: 1px solid var(--red); }
.alert-info { background: var(--primary-soft); color: var(--primary); border: 1px solid var(--primary); }

.confirm-box { max-width: 480px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }

.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 30px 0; }

/* ---------- Erişilebilirlik ---------- */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

@media (max-width: 420px) {
    .container { padding: 16px 12px 48px; }
    h1 { font-size: 21px; }
}
