@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #0f172a;          
  --sidebar: #1e293b;     
  --card-bg: #1e293b;     
  --border: #334155;      
  --text: #e2e8f0;        
  --text-muted: #94a3b8;  
  
  --primary: #3b82f6;     
  --primary-hover: #2563eb;
  --success: #10b981;     
  --danger: #ef4444;      
  --warning: #f59e0b;     
  
  --radius: 8px;          
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);

  /* iOS safe area (fallback: 0px) */
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

header {
  position: sticky; top: 0; z-index: 50;
  background: var(--sidebar); 
  border-bottom: 1px solid var(--border);
  height: 64px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 250px 1fr auto; 
  align-items: center;
  gap: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.header-left { display: flex; align-items: center; gap: 15px; }
header h1 { 
  font-size: 18px; font-weight: 700; margin: 0; color: white; letter-spacing: -0.5px; cursor: pointer;
}

.view-mode-switch { display: flex; gap: 4px; }
.view-mode-switch button { 
  width: 28px; height: 28px; padding: 0; border-radius: 4px; 
  background: transparent; border: 1px solid var(--border); color: var(--text-muted);
}
.view-mode-switch button:hover { background: rgba(255,255,255,0.05); color: var(--text); }

.header-center { display: flex; justify-content: center; width: 100%; }
.search-container { position: relative; width: 100%; max-width: 480px; }
.search-container input {
  background: #0f172a; border: 1px solid var(--border);
  color: var(--text); padding: 8px 40px 8px 16px; 
  border-radius: 6px; width: 100%; font-size: 13px; margin: 0;
  transition: all 0.2s;
}
.search-container input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2); }
.search-container button {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; color: var(--text-muted);
  width: 28px; height: 28px; padding: 0; cursor: pointer;
}
.search-container button:hover { color: var(--primary); }

.header-right { display: flex; justify-content: flex-end; }
.action-group { display: flex; gap: 8px; }
.group-btn {
  border: 1px solid var(--border); background: transparent;
  border-radius: 6px; padding: 6px 12px; font-size: 12px; font-weight: 600; 
  color: var(--text); cursor: pointer; transition: 0.2s;
  display: flex; align-items: center; gap: 6px;
}
.group-btn:hover { background: rgba(255,255,255,0.05); border-color: var(--text-muted); }
.group-btn.success { color: var(--success); border-color: rgba(16, 185, 129, 0.3); }
.group-btn.success:hover { background: rgba(16, 185, 129, 0.1); }
.group-btn.warning { color: var(--warning); border-color: rgba(245, 158, 11, 0.3); }

.wrap { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 64px); }

nav {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 0;
  display: flex; flex-direction: column;
  position: sticky; top: 64px; height: calc(100vh - 64px); overflow-y: auto;
}

nav button.navbtn {
  width: 100%;
  text-align: left;
  padding: 16px 24px;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255,255,255,0.03); 
  color: var(--text-muted);
  border-radius: 0; 
  display: flex; align-items: center; gap: 12px;
  font-size: 14px; font-weight: 500;
  transition: all 0.2s ease;
  margin: 0;
}

/* Nav: icon + label layout */
.nav-ico{ display:inline-flex; align-items:center; justify-content:center; width: 22px; height: 22px; font-size: 18px; }
.nav-lbl{ display:inline-block; }

nav button.navbtn:hover {
  background: rgba(255,255,255,0.02);
  color: var(--text);
  padding-left: 28px; 
}

nav button.navbtn.active {
  background: rgba(59, 130, 246, 0.08);
  color: var(--primary);
  border-right: 3px solid var(--primary); 
  font-weight: 600;
}

main { padding: 30px; display: block; width: 100%; overflow-x: hidden; }
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 24px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.card h2 {
  font-size: 16px; font-weight: 600; color: var(--text);
  margin: 0 0 20px 0; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

.row { display: flex; gap: 15px; } .row > * { flex: 1; }

input, select, textarea {
  width: 100%; padding: 10px 14px; border-radius: 6px;
  background: #0f172a; border: 1px solid var(--border);
  color: var(--text); font-size: 14px; outline: none;
  transition: border-color 0.2s; margin-bottom: 15px;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; display: block; font-weight: 600; }

.card:has(table) { padding: 0; overflow: hidden; }
.card:has(table) h2 { margin: 20px 24px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { 
  text-align: left; padding: 14px 24px; 
  background: rgba(0,0,0,0.2); color: var(--text-muted);
  font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
td { 
  padding: 14px 24px; border-bottom: 1px solid var(--border); 
  color: var(--text); vertical-align: middle; 
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.btn-group { display: flex; gap: 6px; }
td button { padding: 6px 10px; font-size: 11px; }

button.primary { background: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: 6px; font-weight: 600; }
button.primary:hover { background: var(--primary-hover); }

button.success { background: var(--success); color: white; border:none; }
button.warning { background: rgba(245, 158, 11, 0.1); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
button.danger { background: rgba(239, 68, 68, 0.1); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }

.kpi {
  grid-column: span 4;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 30px; text-align: center;
  background: var(--card-bg); 
  border: 1px solid var(--border);
}
.kpi .val { font-size: 28px; font-weight: 700; color: white; margin-top: 8px; }
.kpi .label { font-size: 13px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 1px; }

.urun-img {
  width: 250px; height: 250px; object-fit: cover; border-radius: 12px;
  border: 3px solid rgba(255, 255, 255, 0.1); box-shadow: 0 10px 15px rgba(0,0,0,0.3); cursor: pointer; transition: transform 0.2s;
}
.urun-img:hover { transform: scale(1.05); z-index: 100; border-color: var(--primary); box-shadow: 0 20px 30px rgba(0,0,0,0.5); }
.img-preview-box { display: flex; align-items: center; gap: 10px; background: rgba(255, 255, 255, 0.05); padding: 10px; border-radius: 8px; margin-bottom: 10px; border: 1px dashed var(--border); }
.img-preview-box img { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); backdrop-filter: blur(4px); z-index: 100; display: flex; justify-content: center; align-items: center; padding: 20px; }
.modal-content { background: var(--card-bg); border: 1px solid var(--border); width: 100%; max-width: 800px; max-height: 90vh; overflow-y: auto; border-radius: 12px; padding: 30px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); position: relative; }
.modal-close { position: absolute; top: 20px; right: 20px; background: none; border: none; font-size: 24px; color: var(--text-muted); cursor: pointer; }

.toast {
    background: #1e293b; border-left: 4px solid var(--primary); color: white;
    padding: 16px 24px; margin-bottom: 10px; border-radius: 6px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    display: flex; align-items: center; gap: 12px; font-weight: 500;
    animation: slideIn 0.3s ease-out; min-width: 320px;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.hide { display: none !important; }

@media (max-width: 1024px) {
  .wrap { grid-template-columns: 1fr; }
  
  header { 
      height: auto; padding: 15px; 
      grid-template-columns: 1fr; gap: 15px;
      position: relative;
  }
  
  .header-left { justify-content: center; margin-bottom: 5px; }
  .header-center { order: 2; }
  .header-right { order: 3; justify-content: center; }
  .action-group { width: 100%; justify-content: space-between; }
  .group-btn { flex: 1; justify-content: center; }

  nav {
    position: sticky; top: 0; z-index: 40; height: auto;
    flex-direction: row; overflow-x: auto; padding: 0;
    background: var(--bg); border-bottom: 1px solid var(--border); border-right: none;
  }
  nav button.navbtn { 
    width: auto; flex-shrink: 0; padding: 12px 20px; border-bottom: 3px solid transparent; border-right: none;
  }
  nav button.navbtn.active {
    border-bottom-color: var(--primary); border-right: none; background: rgba(59, 130, 246, 0.05);
  }

  main { padding: 15px; }
  .grid { display: flex; flex-direction: column; gap: 20px; }
  .card { width: 100%; }
  .kpi { width: 100%; }
  
  .row { flex-direction: column; gap: 0; }

  /* Mobil tablo kaydırma + kompakt görünüm */
  .card table{ display:block; overflow-x:auto; -webkit-overflow-scrolling:touch; }
  .card table thead, .card table tbody{ display:table; width:100%; }
  .card table{ min-width: 720px; }
  th, td{ padding: 10px 14px; }

  /* Ürün resimleri çok büyük olmasın */
  .urun-img{ width:120px; height:120px; }

  /* Modal içerik daha rahat */
  .modal-content{ padding: 18px; }
}


body.force-mobile .wrap { grid-template-columns: 1fr !important; }
body.force-mobile header { grid-template-columns: 1fr !important; height: auto !important; padding-bottom: 15px; }
body.force-mobile nav { height: auto !important; flex-direction: row !important; overflow-x: auto !important; border-right: none !important; }
body.force-mobile .grid { display: flex !important; flex-direction: column !important; }
body.force-mobile .row { flex-direction: column !important; }

body.force-desktop .wrap { grid-template-columns: 260px 1fr !important; }
body.force-desktop header { grid-template-columns: 250px 1fr auto !important; height: 64px !important; }
body.force-desktop nav { position: sticky !important; top: 64px !important; height: calc(100vh - 64px) !important; flex-direction: column !important; overflow-y: auto !important; border-right: 1px solid var(--border) !important; border-bottom: none !important; }
body.force-desktop main { padding: 30px !important; }
body.force-desktop .grid { display: grid !important; grid-template-columns: repeat(12, 1fr) !important; gap: 24px !important; }
body.force-desktop .row { flex-direction: row !important; }
/* ====== Yeni Dashboard ve Sepet UI ====== */
.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.mini-table th, .mini-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.mini-table tr:hover td {
  background: rgba(255,255,255,0.03);
}

.total-line{
  display:flex;
  justify-content:space-between;
  margin-top:8px;
  padding-top:8px;
  border-top:1px dashed var(--border);
  font-size:14px;
}

.pdf-history{
  list-style: none;
  padding-left: 0;
  margin: 0;
}
.pdf-history li{
  padding:6px 0;
  border-bottom:1px dashed var(--border);
  font-size:12px;
  color: var(--text-muted);
}

/* detay satırı */
.detail-row td{
  background: rgba(255,255,255,0.02);
}


/* Mobilde tablo/PDF taşarsa yana kaydır (düzeni bozmaz) */
@media (max-width: 768px){
  .card table{display:block; overflow-x:auto; white-space:nowrap;}
}


/* --- Helpers --- */
.muted { color: var(--text-muted); }

/* --- Small tags/badges --- */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1.6;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  margin-right: 6px;
  white-space: nowrap;
}
.tag.success {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(16, 185, 129, 0.35);
  color: #34d399;
}
.tag.danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: #f87171;
}

/* Dashboard mini KPI grid */
.dash-kv{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:10px;
}
.dash-kv .kv{
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 10px;
}
.dash-kv .kv span{display:block; font-size:12px; color: var(--text-muted); margin-bottom:4px;}
.dash-kv .kv strong{display:block; font-size:18px;}

/* Fatura - hızlı cari */
.recent-cari-wrap{display:flex; flex-wrap:wrap; gap:6px;}
.recent-cari-wrap button{
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  cursor:pointer;
}
.recent-cari-wrap button:hover{border-color: rgba(96,165,250,0.6);}



/* ===== Mobile UX improvements ===== */
@media (max-width: 768px){
  html, body { overscroll-behavior: none; }
  body { -webkit-tap-highlight-color: transparent; }
  button, a { touch-action: manipulation; }

  /* Header: stack neatly */
  header{
    position: sticky;
    top: 0;
    height: auto;
    padding: 10px 12px;
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .header-left{ justify-content: space-between; }
  .header-center{ width: 100%; }
  .header-right{ width: 100%; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
  .action-group{ width: 100%; justify-content: space-between; }

  /* Wrap becomes single column */
  .wrap{ grid-template-columns: 1fr !important; }

  /* Bottom nav bar for mobile */
  nav{
    position: fixed !important;
    left: 0; right: 0; bottom: 0; top: auto !important;
    height: calc(64px + var(--safe-b)) !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    border-right: none !important;
    border-top: 1px solid var(--border);
    z-index: 60;
  }
  nav button.navbtn{
    width: auto !important;
    flex: 1 0 auto;
    justify-content: center;
    text-align: center;
    padding: 10px 12px;
    border-bottom: none;
    border-right: 1px solid rgba(255,255,255,0.06);
    white-space: nowrap;
    font-size: 11px;
    flex-direction: column;
    gap: 4px;
  }

  /* Mobilde label daha küçük, ikon öne çıksın */
  .nav-ico{ font-size: 20px; width: 24px; height: 24px; }
  .nav-lbl{ font-size: 10px; line-height: 1.1; opacity: .9; }
  nav button.navbtn:hover{ padding-left: 12px; } /* disable hover shift */
  nav button.navbtn.active{
    border-right: 1px solid rgba(255,255,255,0.06);
    border-top: 3px solid var(--primary);
  }

  /* Main content spacing so bottom nav doesn't cover */
  main{
    padding: 14px !important;
    padding-bottom: calc(96px + var(--safe-b)) !important;
    overflow-x: hidden;
  }

  /* Cards + grids */
  .grid{ display: flex !important; flex-direction: column !important; gap: 14px; }
  .row{ flex-direction: column !important; gap: 12px; }
  .card{ padding: 14px; }
  .card h3{ font-size: 15px; }

  /* Tables: horizontal scroll */
  .card table{ display:block; overflow-x:auto; white-space:nowrap; }

  /* Modals */
  .modal-overlay{ padding: 12px; }
  .modal-content{ padding: 16px; max-width: 96vw; }

  /* Forms */
  input, select, textarea{ font-size: 16px; } /* prevent iOS zoom */
}

/* Force-mobile should behave like small screens */
body.force-mobile nav{
  position: fixed !important;
  left: 0; right: 0; bottom: 0; top: auto !important;
  height: calc(64px + var(--safe-b)) !important;
  flex-direction: row !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  border-right: none !important;
  border-top: 1px solid var(--border);
  z-index: 60;
}
body.force-mobile nav button.navbtn{
  width: auto !important;
  flex: 1 0 auto;
  justify-content: center;
  text-align: center;
  padding: 10px 12px;
  border-bottom: none;
  border-right: 1px solid rgba(255,255,255,0.06);
  white-space: nowrap;
  font-size: 12px;
}
body.force-mobile main{ padding-bottom: calc(96px + var(--safe-b)) !important; }

/* =========================================================
   Responsive tables -> card layout (mobile-first professional)
   Usage: add class="responsive-table" and data-label on td.
========================================================= */
@media (max-width: 768px){
  table.responsive-table thead{ display:none; }

  table.responsive-table,
  table.responsive-table tbody,
  table.responsive-table tr,
  table.responsive-table td{
    display:block;
    width:100%;
  }

  table.responsive-table{ min-width: 0 !important; }

  table.responsive-table tr{
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(148,163,184,0.18);
    border-radius: 14px;
    padding: 12px;
    margin: 12px 0;
  }

  table.responsive-table td{
    border: none;
    padding: 8px 0;
    font-size: 13px;
  }

  table.responsive-table td::before{
    content: attr(data-label);
    display:block;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 2px;
  }

  /* Buton grupları alt satıra güzel otursun */
  table.responsive-table .btn-group{ flex-wrap: wrap; gap: 8px; }
  table.responsive-table td:last-child{ padding-top: 10px; }
}

/* =========================================================
   Floating Action Button (FAB)
========================================================= */
.fab{
  position: fixed;
  right: 16px;
  bottom: calc(86px + var(--safe-b));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(59,130,246,0.95);
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 18px 30px rgba(0,0,0,0.45);
  z-index: 80;
}
.fab:active{ transform: scale(0.98); }

/* =========================================================
   Mobile modals: fullscreen app feel
========================================================= */
@media (max-width: 768px){
  .modal-overlay{ padding: 0; }
  .modal-content{
    max-width: 100vw;
    width: 100vw;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    padding: 18px;
  }
  .modal-close{ top: 12px; right: 12px; }
}



@media (max-width: 640px) {
  /* Cariler tablosunda bakiye mobilde ilk hücre içinde gösteriliyor */
  #cariler table th:nth-child(2),
  #cariler table td:nth-child(2) { display: none; }

  .mobile-bakiye { margin-top: 6px; display:flex; flex-wrap:wrap; gap:6px; align-items:center; }
  .mobile-bakiye .tag { font-size: 12px; padding: 3px 8px; }
}


/* Dashboard compact scroll table */
.table-scroll-compact{max-height:260px; overflow:auto; border:1px solid rgba(148,163,184,.15); border-radius:12px;}
@media (max-width: 768px){
  .table-scroll-compact{max-height:320px;}
}
