:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --brand: #2f5bea; --brand-d: #2347c4; --danger: #d23b3b; --ok: #1f9d55; --warn: #c98a00;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,30,50,.06), 0 1px 8px rgba(20,30,50,.04);
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0 0 .2rem; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
code { background: #eef0f4; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .danger { color: var(--danger); } .center { text-align: center; }
.right { text-align: right; } .grow { flex: 1; min-width: 0; } .pre { white-space: pre-wrap; }

.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.5rem; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand.big { font-size: 1.3rem; justify-content: center; margin-bottom: 1.2rem; }
.logo { background: var(--brand); color: #fff; border-radius: 7px; padding: 2px 7px; font-size: .9rem; }
.topbar nav { display: flex; gap: .2rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); padding: .4rem .7rem; border-radius: 7px; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.topbar nav a.on { background: #e9eefc; color: var(--brand); font-weight: 600; }
.logout { display: flex; gap: .6rem; align-items: center; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 1.5rem; }
.pagehead { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.pagehead h1 { margin-right: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; }
.card.flush { padding: 0; overflow: auto; }
.card.narrow { max-width: 720px; }
.card.empty { text-align: center; padding: 3rem; }
details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: 1rem; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #eaf7ef; border-color: #bfe5cd; color: #145c33; }
.flash.error { background: #fdeeee; border-color: #f3c4c4; color: #8b1f1f; }
.flash.info { background: #eef3fe; border-color: #cbd8fb; color: #1e3a8a; }

label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; color: var(--muted); font-weight: 500; }
label.checkbox { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: .5rem .65rem; background: #fff; width: 100%; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c9d6fb; border-color: var(--brand); }
textarea { resize: vertical; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
form.inline { display: inline-flex; align-items: center; gap: .5rem; }
.inline input[type=search] { width: 280px; }
.w-sm { width: 120px; flex: none; }

.btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--text); padding: .48rem .9rem; border-radius: 7px; white-space: nowrap; display: inline-block; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-d); }
button.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }
button.link.danger { color: var(--danger); }
summary.link { color: var(--brand); cursor: pointer; margin: .4rem 0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.2rem; }
.stat { margin: 0; }
.stat .num { font-size: 1.9rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .88rem; }
.stat.alert .num { color: var(--danger); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.grid2 > .card { margin-bottom: 1.2rem; }

.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: .7rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row.done .grow { text-decoration: line-through; color: var(--muted); }
.check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #b8bfcc; background: #fff; cursor: pointer; padding: 0; flex: none; }
.check:hover { border-color: var(--ok); }
.check.on { background: var(--ok); border-color: var(--ok); }
.tag { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 99px; background: #eef0f4; color: var(--muted); font-weight: 500; vertical-align: middle; }

.badge { display: inline-block; font-size: .78rem; padding: 2px 8px; border-radius: 99px; font-weight: 600; }
.st-yeni { background: #e9eefc; color: #2347c4; }
.st-iletisim { background: #fff4dc; color: #8a5d00; }
.st-teklif { background: #f1e8fd; color: #6b2fb3; }
.st-kazanildi { background: #e3f6ea; color: #17733f; }
.st-kaybedildi { background: #f1f2f4; color: #6b7385; }

.funnel { display: grid; grid-template-columns: repeat(5, 1fr); gap: .6rem; }
.funnel-step { border-radius: 8px; padding: .8rem; text-align: center; color: inherit; }
.funnel-step:hover { text-decoration: none; filter: brightness(.97); }
.funnel-step .num { font-size: 1.5rem; font-weight: 700; }
.funnel-step .lbl { font-size: .85rem; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .65rem .9rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #f8f9fb; }

.detail { display: grid; grid-template-columns: minmax(300px, 1fr) 1.6fr; gap: 1.2rem; align-items: start; }
.deal-row { display: flex; gap: .5rem; align-items: center; margin: .5rem 0; }
.deal-row select { width: auto; }
.deal-row input[type=datetime-local] { width: auto; }

details.mail { border: 1px solid var(--line); border-radius: 8px; padding: .55rem .8rem; margin-bottom: .5rem; }
details.mail > summary { display: flex; gap: .7rem; align-items: center; cursor: pointer; list-style: none; }
details.mail > summary::-webkit-details-marker { display: none; }
details.mail.out { background: #f8faff; }
details.mail .dir { font-size: .78rem; font-weight: 600; width: 64px; flex: none; color: var(--muted); }
details.mail.in .dir { color: var(--ok); }
details.mail.out .dir { color: var(--brand); }
.mailbody { white-space: pre-wrap; font-family: inherit; font-size: .9rem; background: #fafbfc; border-radius: 6px; padding: .8rem; margin: .6rem 0 0; max-height: 420px; overflow: auto; }
.actions { display: flex; gap: .5rem; margin-top: .6rem; }

.timeline { list-style: none; padding: 0; margin: .8rem 0 0; }
.timeline li { border-left: 2px solid var(--line); padding: .1rem 0 .8rem .9rem; position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: .4rem; width: 8px; height: 8px; border-radius: 50%; background: #b8bfcc; }
.timeline li.act-note::before { background: var(--warn); }
.timeline li.act-lead::before { background: var(--brand); }
.timeline li.act-email_out::before, .timeline li.act-auto_reply::before { background: var(--ok); }
.timeline li.act-error::before { background: var(--danger); }

.kanban { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: .9rem; overflow-x: auto; align-items: start; }
.khead { display: flex; justify-content: space-between; padding: .55rem .8rem; border-radius: 8px; font-weight: 600; margin-bottom: .6rem; }
.kcard { padding: .8rem; margin-bottom: .6rem; display: flex; flex-direction: column; gap: .3rem; }
.kcard select { margin-top: .3rem; font-size: .85rem; padding: .3rem .5rem; }

.tabs { display: flex; gap: .3rem; }
.tabs a { padding: .4rem .8rem; border-radius: 7px; color: var(--muted); }
.tabs a.on { background: #fff; border: 1px solid var(--line); color: var(--text); font-weight: 600; }
.kv { border-collapse: collapse; margin-bottom: 1rem; width: 100%; }
.kv th { text-align: left; color: var(--muted); font-weight: 500; padding: .3rem 1rem .3rem 0; width: 40%; }
.kv td { padding: .3rem 0; }

.login-box { max-width: 380px; margin: 12vh auto; padding: 2rem; }

@media (max-width: 900px) {
  .stats, .grid2, .detail, .funnel, .cols2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .inline input[type=search] { width: 100%; }
  .wrap { padding: 1rem; }
}
