/**
 * CariPro - Ultra Sade & Canlı Tablo Tasarım Sistemi
 * Tek sayfa, sıfır pop-up, satır içi canlı hesaplama ve yüksek okunabilirlik
 */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  --bg-page: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-subtle: #F1F5F9;
  --border-color: #E2E8F0;
  --border-focus: #3B82F6;

  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-light: #94A3B8;

  --green: #10B981;
  --green-bg: #DCFCE7;
  --green-text: #15803D;

  --red: #EF4444;
  --red-bg: #FEE2E2;
  --red-text: #B91C1C;

  --blue: #2563EB;
  --blue-bg: #EFF6FF;
  --blue-text: #1D4ED8;

  --gray-bg: #F1F5F9;
  --gray-text: #475569;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding: 20px 16px 40px;
}

.num {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ================================================= */
/* CONTAINER & LAYOUT                                */
/* ================================================= */
.sheet-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ================================================= */
/* 1. HEADER & STATS BAR                             */
/* ================================================= */
.sheet-header {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-logo {
  width: 40px;
  height: 40px;
  background: #0F172A;
  color: #FFFFFF;
  font-weight: 800;
  font-size: 1.1rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.03em;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-main);
  line-height: 1.1;
}

.app-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.cloud-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.cloud-pill:hover {
  background: #E2E8F0;
  color: var(--text-main);
}

.pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-light);
}

.cloud-pill.active .pill-dot {
  background: var(--green);
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-badge {
  padding: 6px 14px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.stat-label {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.stat-val {
  font-weight: 800;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.stat-green {
  background: var(--green-bg);
  color: var(--green-text);
}

.stat-red {
  background: var(--red-bg);
  color: var(--red-text);
}

.stat-net {
  background: var(--blue-bg);
  color: var(--blue-text);
  border: 1px solid rgba(37, 99, 235, 0.2);
}

/* ================================================= */
/* 2. BULUT AYAR ÇEKMECESİ                          */
/* ================================================= */
.cloud-drawer {
  background: #0F172A;
  color: #F8FAFC;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin-top: -6px;
}

.cloud-drawer-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.drawer-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.drawer-field label {
  font-size: 0.74rem;
  color: #94A3B8;
  font-weight: 600;
}

.input-sm {
  background: #1E293B;
  border: 1px solid #334155;
  color: #FFFFFF;
  padding: 6px 10px;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
  outline: none;
}

.input-sm:focus {
  border-color: #60A5FA;
}

.drawer-actions {
  display: flex;
  gap: 6px;
}

.drawer-help {
  font-size: 0.74rem;
  color: #94A3B8;
}

.drawer-help code {
  color: #38BDF8;
  background: #1E293B;
  padding: 2px 6px;
  border-radius: 4px;
}

/* ================================================= */
/* 3. ADD FIRM BAR (TEK SATIR GİRİŞİ)                */
/* ================================================= */
.add-firm-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-sm);
}

.add-firm-form {
  display: flex;
  gap: 10px;
  align-items: center;
}

.firm-input {
  flex: 2;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 500;
  outline: none;
  background: var(--bg-page);
  transition: all 0.15s;
}

.firm-phone-input {
  flex: 1;
  max-width: 220px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  outline: none;
  background: var(--bg-page);
}

.firm-input:focus,
.firm-phone-input:focus {
  border-color: var(--border-focus);
  background: #FFFFFF;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* BUTONLAR */
.btn {
  height: 42px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.12s;
  white-space: nowrap;
}

.btn-primary {
  background: #0F172A;
  color: #FFFFFF;
}

.btn-primary:hover {
  background: #1E293B;
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: #E2E8F0;
}

.btn-dark {
  background: #2563EB;
  color: #FFFFFF;
}

.btn-dark:hover {
  background: #1D4ED8;
}

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-icon-only {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-icon-only:hover {
  background: var(--bg-subtle);
}

.btn-whatsapp {
  color: #15803D;
  border-color: rgba(22, 163, 74, 0.3);
  background: #F0FDF4;
}

.btn-whatsapp:hover {
  background: #DCFCE7;
}

.btn-danger {
  color: #DC2626;
}

.btn-danger:hover {
  background: #FEE2E2;
  border-color: #FCA5A5;
}

/* ================================================= */
/* 4. CANLI FİRMA TABLOSU                            */
/* ================================================= */
.firm-table-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.sheet-table-header {
  display: grid;
  grid-template-columns: 260px 1fr 230px 100px;
  padding: 12px 20px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.firm-rows-list {
  display: flex;
  flex-direction: column;
}

/* FİRMA SATIRI (CARD / ROW) */
.firm-row-card {
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.1s;
}

.firm-row-card:last-child {
  border-bottom: none;
}

.firm-row-card:hover {
  background-color: #F8FAFC;
}

.firm-row-main {
  display: grid;
  grid-template-columns: 260px 1fr 230px 100px;
  padding: 14px 20px;
  align-items: center;
  gap: 14px;
}

/* Sütun 1: Firma Adı & Tel */
.cell-name {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.firm-name {
  font-weight: 700;
  font-size: 0.96rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.firm-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.btn-history-toggle {
  background: none;
  border: none;
  color: var(--blue);
  font-weight: 600;
  font-size: 0.74rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* Sütun 2: Satır İçi Para Giriş Kutuları */
.cell-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-alinan {
  width: 130px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid rgba(16, 185, 129, 0.4);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  color: #065F46;
  background: #F0FDF4;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.input-alinan:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.input-verilen {
  width: 130px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  color: #991B1B;
  background: #FEF2F2;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.input-verilen:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.input-desc {
  flex: 1;
  min-width: 110px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  outline: none;
  background: #FFFFFF;
}

.input-desc:focus {
  border-color: var(--border-focus);
}

.btn-row-add {
  height: 38px;
  padding: 0 14px;
  background: #0F172A;
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-row-add:hover {
  background: #1E293B;
}

/* Sütun 3: CANLI BAKİYE ROZETİ (Satır Sonunda) */
.cell-balance {
  display: flex;
  align-items: center;
}

.live-balance-badge {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.live-balance-badge .bal-amount {
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.1;
}

.live-balance-badge .bal-status {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.9;
}

/* Bakiye Renk Durumları */
.bal-alacakli {
  background: var(--green-bg);
  color: var(--green-text);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.bal-borcluyuz {
  background: var(--red-bg);
  color: var(--red-text);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.bal-kapali {
  background: var(--gray-bg);
  color: var(--gray-text);
  border: 1px solid var(--border-color);
}

/* Sütun 4: Aksiyon Butonları */
.cell-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

/* GEÇMİŞ HAREKETLER AKORDEONU (DRAWER) */
.firm-history-drawer {
  background: #F8FAFC;
  border-top: 1px dashed var(--border-color);
  padding: 12px 20px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.history-table th {
  text-align: left;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-color);
}

.history-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #EDF2F7;
}

.history-table tr:last-child td {
  border-bottom: none;
}

.btn-del-tx {
  background: none;
  border: none;
  color: #94A3B8;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
}

.btn-del-tx:hover {
  color: var(--red);
}

/* BOŞ DURUM (EMPTY STATE) */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.empty-state h3 {
  font-size: 1.15rem;
  color: var(--text-main);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 0.88rem;
  max-width: 440px;
  margin: 0 auto;
}

/* FOOTER */
.sheet-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 8px 4px;
}

.btn-text-danger {
  background: none;
  border: none;
  color: #DC2626;
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: underline;
}

/* ================================================= */
/* MOBİL UYUMLULUK (RESPONSIVE)                      */
/* ================================================= */
@media (max-width: 900px) {
  body {
    padding: 10px 8px 30px;
  }

  .sheet-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .header-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
  }

  .stat-badge {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 6px 8px;
    gap: 2px;
  }

  .stat-val {
    font-size: 0.88rem;
  }

  .add-firm-form {
    flex-direction: column;
    align-items: stretch;
  }

  .firm-phone-input {
    max-width: 100%;
  }

  .sheet-table-header {
    display: none; /* Mobilde tablo başlığı gizlenir */
  }

  .firm-row-main {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px 12px;
  }

  .cell-inputs {
    flex-wrap: wrap;
  }

  .input-alinan,
  .input-verilen {
    flex: 1;
    width: auto;
  }

  .input-desc {
    width: 100%;
    flex: none;
  }

  .btn-row-add {
    width: 100%;
    height: 40px;
  }

  .cell-balance {
    order: -1; /* Mobilde bakiye firma adının hemen altında dursun */
  }

  .live-balance-badge {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .cell-actions {
    justify-content: stretch;
  }

  .cell-actions .btn-icon-only {
    flex: 1;
    height: 38px;
  }
}
