:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

body.login-locked { overflow: hidden; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }
.positive { color: var(--success); }
.negative { color: var(--danger); }
.error { color: var(--danger); font-size: 0.9rem; margin-top: 8px; }
.hint { margin-top: 16px; font-size: 0.85rem; color: var(--muted); text-align: center; }
.hint code { background: var(--surface2); padding: 2px 6px; border-radius: 4px; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; text-decoration: underline; font: inherit; }

/* Giriş */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-brand {
  text-align: center;
  margin-bottom: 20px;
}

.logo-header {
  width: 52px !important;
  height: 52px !important;
  max-width: 52px;
  max-height: 52px;
  object-fit: contain;
  flex-shrink: 0;
}

.login-brand .logo {
  width: 72px !important;
  height: 72px !important;
  max-width: 72px;
  max-height: 72px;
  object-fit: contain;
  margin-bottom: 12px;
}

.logo-modal {
  width: 36px !important;
  height: 36px !important;
  max-width: 36px;
  max-height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

.login-brand h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.mode-hint {
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 16px;
  text-align: center;
}

.mode-local { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.mode-server { background: rgba(34, 197, 94, 0.15); color: var(--success); }

/* Kart & form */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.form label {
  display: block;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--muted);
}

.form input,
.form select,
.form textarea,
.input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}

.form input:focus,
.form select:focus,
.form textarea:focus,
.input:focus {
  outline: none;
  border-color: var(--primary);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* Butonlar */
.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
  background: var(--surface2);
  color: var(--text);
  transition: background 0.15s;
}

.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-danger { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* Uygulama */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.header {
  margin-bottom: 20px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-label {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
}

.logo-sm {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.modal-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-title-row h2 {
  margin: 0;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.sum-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.sum-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.sum-value {
  font-size: 1.2rem;
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 5px;
}

.tab {
  flex: 1;
  padding: 4px 10px;
  background: transparent;
  border: 1.5px solid #60a5fa;
  border-radius: 5px;
  color: #60a5fa;
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.3;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.tab:hover {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35);
}

.tab.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35);
}

.panel { display: none; }
.panel.active { display: block; }

.toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar .input {
  flex: 1;
  min-width: 140px;
  margin-top: 0;
  padding: 5px 10px;
  font-size: 0.8rem;
}

.toolbar-label {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.toolbar .input-period {
  flex: 0 1 auto;
  min-width: 88px;
}

/* Cari listesi */
.cari-grid {
  display: grid;
  gap: 12px;
}

.cari-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  flex-wrap: wrap;
}

.cari-card h3 { font-size: 1rem; margin-bottom: 2px; }
.cari-card .bakiye { font-weight: 600; margin-top: 4px; }

.cari-card-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
}

.btn-card {
  padding: 3px 8px;
  border-radius: 5px;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.3;
  cursor: pointer;
  background: transparent;
  border: 1.5px solid;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn-card-view {
  color: #60a5fa;
  border-color: #60a5fa;
}

.btn-card-view:hover {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35);
}

.btn-card-islem {
  color: #34d399;
  border-color: #34d399;
}

.btn-card-islem:hover {
  background: #10b981;
  border-color: #10b981;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.35);
}

.btn-card-edit {
  color: #fbbf24;
  border-color: #fbbf24;
}

.btn-card-edit:hover {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #111;
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35);
}

.btn-card-print {
  color: #a78bfa;
  border-color: #a78bfa;
}

.btn-card-print:hover {
  background: #8b5cf6;
  border-color: #8b5cf6;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.35);
}

.btn-card-pdf {
  color: #38bdf8;
  border-color: #38bdf8;
}

.btn-card-pdf:hover {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.35);
}

.btn-card-share {
  color: #2dd4bf;
  border-color: #2dd4bf;
}

.btn-card-share:hover {
  background: #14b8a6;
  border-color: #14b8a6;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(20, 184, 166, 0.35);
}

.btn-card-delete {
  color: #f87171;
  border-color: #f87171;
}

.btn-card-site {
  color: #93c5fd;
  border-color: #93c5fd;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-card-site:hover {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}

.btn-card-delete:hover {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.35);
}

/* Tablo */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.tag-borc { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.tag-alacak { background: rgba(34, 197, 94, 0.2); color: var(--success); }
.tag-masraf { background: rgba(245, 158, 11, 0.22); color: #d97706; }

.cari-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

.islem-list {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.islem-totals {
  margin-top: 12px;
}

.islem-totals-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-box {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-box h2 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.modal-box-lg {
  max-width: min(720px, 96vw);
  width: 100%;
}

#cariViewModal .modal-box-lg {
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}

#cariViewModal .modal-header {
  flex-shrink: 0;
  margin-bottom: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

#cariViewModal .cari-view-body {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  margin-bottom: 0;
  padding: 16px 0;
}

#cariViewModal .view-actions {
  flex-shrink: 0;
  margin-top: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-header h2 {
  margin-bottom: 0;
}

.cari-view-body {
  margin-bottom: 16px;
}

.view-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.view-sum-item {
  background: var(--surface2);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}

.view-sum-item span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.view-sum-item strong {
  font-size: 1rem;
}

.detail-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.detail-row {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.detail-label {
  flex: 0 0 100px;
  color: var(--muted);
  font-size: 0.85rem;
}

.detail-value {
  flex: 1;
  font-size: 0.9rem;
}

.view-section-title {
  font-size: 0.95rem;
  margin-bottom: 10px;
  color: var(--muted);
}

.view-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.view-table-wrap .table th:last-child,
.view-table-wrap .table td:last-child {
  width: 1%;
  white-space: nowrap;
}

.view-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.view-actions-main {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
}

.view-actions-pair {
  display: flex;
  flex-shrink: 0;
  flex-wrap: nowrap;
  gap: 5px;
}

.view-actions-pair .btn-card {
  white-space: nowrap;
}

.row-actions {
  display: inline-flex;
  gap: 4px;
  flex-wrap: nowrap;
  align-items: center;
}

.row-actions .btn-sm {
  padding: 3px 8px;
  font-size: 0.72rem;
  white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
  z-index: 200;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (max-width: 600px) {
  .summary { grid-template-columns: 1fr; }
  .islem-totals-grid { grid-template-columns: 1fr; }
  .view-summary { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .cari-card { flex-direction: column; align-items: flex-start; }
  .view-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .view-actions-main,
  .view-actions-pair {
    justify-content: center;
  }
  .view-actions-pair {
    width: 100%;
  }
  .view-actions-pair .btn-card {
    flex: 1 1 0;
    text-align: center;
  }
}
