:root {
  --bg: #f8fafc;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --card: #ffffff;
  --sidebar-bg: #0f172a;
  --sidebar-fg: #e2e8f0;
  --sidebar-muted: #94a3b8;
  --sidebar-active: #1e293b;
  --primary: #0f172a;
  --primary-fg: #ffffff;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
}

a { color: inherit; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-header { padding: 16px; }
.sidebar-header .brand { font-weight: 600; font-size: 15px; }
.sidebar-header .sub { font-size: 12px; color: var(--sidebar-muted); }
.sidebar-nav { flex: 1; padding: 8px; }
.sidebar-nav .group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--sidebar-muted); padding: 8px 8px 4px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; text-decoration: none;
  color: var(--sidebar-fg); font-size: 14px; margin-bottom: 2px;
}
.sidebar-nav a:hover { background: var(--sidebar-active); }
.sidebar-nav a.active { background: var(--sidebar-active); font-weight: 600; }
.sidebar-footer { padding: 12px; border-top: 1px solid #1e293b; font-size: 12px; }
.sidebar-footer .name { color: var(--sidebar-fg); font-weight: 500; }
.sidebar-footer .role { color: var(--sidebar-muted); }
.sidebar-footer form { margin-top: 8px; }
.sidebar-footer button {
  width: 100%; background: none; border: 1px solid #334155; color: var(--sidebar-fg);
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.sidebar-footer button:hover { background: var(--sidebar-active); }

.sidebar-toggle {
  display: none;
}

/* Topbar (mobile) */
.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { font-weight: 600; }
.topbar button {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 18px; line-height: 1;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 24px;
}

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.page-header h1 { margin: 0; font-size: 22px; }
.page-header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; margin-bottom: 16px;
}
.card h2, .card h3 { margin-top: 0; font-size: 14px; }
.card-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stat-card .label { font-size: 12px; text-transform: uppercase; color: var(--muted); }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.stat-card .value.danger { color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--primary); color: var(--primary-fg);
  border: none; border-radius: 10px; padding: 10px 18px; min-height: 44px;
  font-size: 14px; cursor: pointer; text-decoration: none;
  transition: opacity .12s, transform .05s;
}
.btn:hover { opacity: .9; }
.btn:active { transform: scale(0.97); }
.btn.secondary { background: #f1f5f9; color: var(--fg); border: 1px solid var(--border); }
.btn.outline { background: transparent; color: var(--fg); border: 1px solid var(--border); }
.btn.ghost { background: none; color: var(--fg); min-height: auto; padding: 6px 10px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.success {
  background: #ecfdf5; color: #15803d; border: 1px solid #bbf7d0;
  font-weight: 600; transition: background-color .12s, border-color .12s, transform .05s;
}
.btn.success:hover { background: #dcfce7; border-color: #86efac; }
.btn.success:active { transform: scale(0.98); }
.btn.success::before {
  content: "✓"; display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 999px; background: #16a34a; color: #fff;
  font-size: 10px; font-weight: 700; flex-shrink: 0;
}
.btn.sm { padding: 8px 14px; min-height: 38px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:not(:disabled) { cursor: pointer; }

/* Forms */
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=tel],
input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--fg);
}
textarea { resize: vertical; }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-row { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; }
.checkbox-row input { margin-top: 3px; }
.help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.error-box { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.note-box { background: #fef3c7; border: 1px solid #fde68a; color: #92400e; padding: 6px 9px; border-radius: 8px; font-size: 12px; margin-top: 8px; font-weight: 500; }
.push-bar {
  display: none; align-items: center; justify-content: space-between; gap: 12px;
  background: #fef3c7; border: 1px solid #fde68a; color: #92400e;
  padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}

/* Mesajlaşma (WhatsApp benzeri baloncuklar) */
.msg-thread {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 460px; overflow-y: auto; padding: 14px; margin: 0 0 12px;
  background: #eef2f5; border-radius: 14px;
}
.msg-bubble {
  max-width: 80%; padding: 9px 13px; border-radius: 16px; font-size: 14px; line-height: 1.45;
  box-shadow: 0 1px 1px rgba(15,23,42,.06);
}
.msg-bubble.from-admin { align-self: flex-start; background: #ffffff; color: var(--fg); border-bottom-left-radius: 4px; }
.msg-bubble.from-technician { align-self: flex-end; background: #d9fdd3; color: #111b21; border-bottom-right-radius: 4px; }
.msg-quote {
  border-left: 3px solid rgba(15,23,42,.18); padding: 4px 8px; margin-bottom: 6px;
  font-size: 12px; color: var(--muted); background: rgba(15,23,42,.04); border-radius: 6px;
}
.msg-meta {
  font-size: 10px; color: var(--muted); margin-top: 3px;
  display: flex; gap: 4px; align-items: center; justify-content: flex-end;
}
.msg-sender { font-size: 12px; display: block; font-weight: 600; margin-bottom: 3px; color: var(--primary); }
.msg-actions { display: flex; gap: 10px; margin-top: 6px; }
.msg-actions form { margin: 0; }
.msg-actions a, .msg-delete-btn {
  font-size: 12px; color: var(--muted); text-decoration: none;
  background: rgba(15,23,42,.06); border: none; border-radius: 20px;
  padding: 6px 12px; min-height: 30px; display: inline-flex; align-items: center;
  cursor: pointer;
}
.msg-reply-quote {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #f1f5f9; border-left: 3px solid var(--primary); border-radius: 8px;
  padding: 8px 12px; font-size: 12px; color: var(--muted); margin-bottom: 8px;
}
.msg-compose { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.msg-compose textarea {
  flex: 1; border-radius: 22px; padding: 11px 18px; resize: none;
  min-height: 44px; max-height: 44px; line-height: 1.3;
}
.msg-send-btn {
  border-radius: 999px; width: 44px; height: 44px; padding: 0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.msg-send-btn svg { width: 19px; height: 19px; }

/* Fotoğraf/dosya eki (kamera + galeri) */
.msg-attach-btn {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 38px; height: 38px; border-radius: 50%; background: rgba(15,23,42,.06);
  color: var(--muted); cursor: pointer; transition: background-color .12s;
}
.msg-attach-btn:hover { background: rgba(15,23,42,.12); }
.msg-attach-btn svg { width: 18px; height: 18px; }
.msg-attach-btn input[type=file] { display: none; }
.msg-attach-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.msg-preview-chip {
  display: none; align-items: center; gap: 8px; flex: 1 0 100%; order: -1;
  background: #f1f5f9; border-radius: 10px; padding: 6px 10px; font-size: 12px; color: var(--muted);
}
.msg-preview-chip.show { display: flex; }
.msg-preview-chip .remove { margin-left: auto; cursor: pointer; color: var(--danger); font-weight: 700; }
.msg-attachment-img { display: block; max-width: 220px; border-radius: 10px; margin-bottom: 6px; overflow: hidden; }
.msg-attachment-img img { width: 100%; display: block; }
.msg-attachment-file {
  display: flex; align-items: center; gap: 6px; background: rgba(15,23,42,.05);
  border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px;
  text-decoration: none; color: inherit;
}

.hidden-by-search { display: none !important; }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
.table-empty { text-align: center; color: var(--muted); padding: 24px 0; }
.muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid transparent;
}
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* Filter form */
.filter-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filter-form .field { margin-bottom: 0; min-width: 160px; }
.filter-form .field.grow { flex: 1; min-width: 200px; }

/* Mobile card list (shown instead of table on small screens) */
.mobile-list { display: none; }
.mobile-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px;
  display: block; text-decoration: none; color: inherit; background: var(--card);
}
.mobile-card .row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.mobile-card .title { font-weight: 600; }
.mobile-card .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mobile-card .desc { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* Region cards (binalar overview) */
.region-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.region-card { border: 1px solid var(--border); border-radius: 12px; padding: 16px; text-decoration: none; color: inherit; background: var(--card); display: block; }
.region-card:hover { border-color: #94a3b8; }
.region-card h3 { margin: 0 0 8px; }
.region-card .stats-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.region-card .breakdown { display: flex; gap: 12px; font-size: 12px; margin-top: 8px; }

/* Simple bar chart */
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.bar-row .bar-label { width: 110px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; background: #f1f5f9; border-radius: 4px; height: 10px; overflow: hidden; }
.bar-fill { background: #0f172a; height: 100%; }
.bar-value { width: 28px; text-align: right; flex-shrink: 0; }
.bar-value.wide { width: 64px; }

/* Dialog (native <dialog>) */
dialog {
  border: none; border-radius: 12px; padding: 0; width: 100%; max-width: 420px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
dialog::backdrop { background: rgba(15, 23, 42, .4); }
.dialog-inner { padding: 18px; }
.dialog-inner h3 { margin-top: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }

@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar { display: flex; }
  .main { padding: 16px; }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .region-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  table.responsive-table { display: none; }
  .mobile-list { display: block; }

  .sidebar.open {
    display: flex; position: fixed; inset: 0 30% 0 0; z-index: 30; height: 100vh;
  }
  .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }
  .sidebar-backdrop.open { display: block; }

  .msg-thread { max-height: 60vh; padding: 10px; }
  .msg-bubble { max-width: 88%; font-size: 14px; }
  .msg-attach-btn { width: 40px; height: 40px; }
}

@media print {
  .sidebar, .topbar, .btn { display: none !important; }
  .main { padding: 0; }
  .app-shell { display: block; }
  table.responsive-table { display: table !important; }
  .mobile-list { display: none !important; }
}
