:root {
  --primary: #0f5c4c;
  --accent: #ac8a17;
  --bg: #f7f5f0;
  --card: #ffffff;
  --text: #2b2b2b;
  --muted: #6b7280;
  --border: rgba(15, 92, 76, 0.18);
  --shadow: 0 12px 30px rgba(0,0,0,.08);
}

/* ===== RESET / BASE ===== */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden; /* prevent horizontal scrollbar */
}
body{
  font-family: system-ui, Segoe UI, Roboto, Arial;
  background: var(--bg);
  color: var(--text);
}
a{ color:inherit; text-decoration:none; }

/* ===== LAYOUT ===== */
.container{
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px;
}
.grid{
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

/* ===== TOPBAR ===== */
.topbar{
  background: var(--primary);
  color: #fff;
}
.topbar .inner{
  max-width:1100px;
  margin:0 auto;
  padding:14px 18px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  flex-wrap: wrap;
}
.brand{
  font-weight:950;
  letter-spacing:.3px;
}
.badge{
  padding:6px 10px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.35);
  font-weight:900;
  font-size:12px;
}

/* ===== BUTTONS ===== */
.btn{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:10px 14px;
  border-radius:12px;
  font-weight:900;
  border:1px solid transparent;
  cursor:pointer;
  transition:.2s ease;
}
.btn:hover{ transform: translateY(-2px); }
.btn-primary{ background:var(--accent); color:#111; }
.btn-ghost{ background:transparent; border-color:rgba(255,255,255,.35); color:#fff; }
.btn-light{ background:#fff; border-color:var(--border); }
.btn-danger{ background:#b42318; color:#fff; }

/* ===== CARDS ===== */
.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:18px;
  padding:16px;
  box-shadow:var(--shadow);
}
.headerline{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}
.muted{
  color:var(--muted);
  font-size:13px;
}

/* ===== FORMS ===== */
label{
  font-weight:900;
  font-size:13px;
}
input, select, textarea{
  width:100%;
  padding:12px;
  border-radius:14px;
  border:1px solid var(--border);
  background:#fff;
}
textarea{
  min-height:110px;
  resize:vertical;
}

/* ===== STATS CARDS ===== */
.stats-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
  gap:16px;
  margin-bottom:12px;     /* reduce empty space */
  align-items:stretch;    /* equal height */
}
.stat-card{
  border:1px solid var(--border);
  border-radius:18px;
  padding:18px;
  background:linear-gradient(135deg,#fff,#f9f9f9);
  box-shadow:var(--shadow);
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  min-height:140px;       /* equal height */
}
.stat-title{
  font-size:13px;
  font-weight:900;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.3px;
}
.stat-value{
  font-size:34px;
  font-weight:950;
  line-height:1;
  margin-top:6px;
}
.stat-sub{
  margin-top:8px;
  color:var(--muted);
  font-size:13px;
}

/* ===== STATUS OVERVIEW CHART ===== */
.chart-card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:18px;
  padding:16px;
  box-shadow:var(--shadow);
  margin-bottom:12px;
}
.chart-title{
  font-weight:950;
  font-size:14px;
  margin-bottom:10px;
}
.bars{ display:grid; gap:10px; }
.bar-row{
  display:grid;
  grid-template-columns:110px 1fr 60px;
  gap:10px;
  align-items:center;
}
.bar-label{
  color:var(--muted);
  font-weight:950;
  font-size:12px;
  text-transform:uppercase;
}
.bar-track{
  height:12px;
  border-radius:999px;
  background:rgba(0,0,0,.06);
  overflow:hidden;
  border:1px solid var(--border);
}
.bar-fill{ height:100%; border-radius:999px; width:0%; }
.bar-fill.new{ background:#0f5c4c; }
.bar-fill.follow{ background:#f59e0b; }
.bar-fill.closed{ background:#b42318; }
.bar-num{ font-weight:950; text-align:right; }

/* =====================================================
   TABLE – NO HORIZONTAL SCROLL (AUTO FIT)
   ===================================================== */
.table-wrap{
  width:100%;
  overflow:hidden;              /* no scrollbar */
  border-radius:18px;
  border:1px solid var(--border);
  box-shadow:var(--shadow);
}

table{
  width:100%;
  border-collapse:collapse;
  background:#fff;
  table-layout:auto;            /* allow browser to fit */
  min-width:0;
}

th, td{
  padding:12px;
  border-bottom:1px solid var(--border);
  vertical-align:top;

  white-space:normal;
  overflow-wrap:anywhere;
  word-break:break-word;
}

th{
  background:#fbfaf7;
  font-weight:950;
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.4px;
}

tbody tr:hover{ background:rgba(0,0,0,.03); }

/* Name cell */
.name-cell{ display:flex; gap:10px; align-items:center; }
.avatar{
  width:36px; height:36px; border-radius:999px;
  display:flex; align-items:center; justify-content:center;
  font-weight:950;
  background:rgba(172,138,23,.18);
  border:1px solid var(--border);
}

/* Status badge */
.status-badge{
  padding:6px 10px;
  border-radius:999px;
  font-weight:900;
  font-size:12px;
  border:1px solid var(--border);
  display:inline-flex;
}
.status-badge[data-status="New"]{ background:rgba(15,92,76,.14); }
.status-badge[data-status="Follow-up"]{ background:rgba(245,158,11,.18); }
.status-badge[data-status="Closed"]{ background:rgba(180,35,24,.16); }

/* Actions */
.actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;               /* important */
  align-items:center;
}
.actions a{ white-space:nowrap; }

/* ===== DARK MODE ===== */
.dark{
  --bg:#0b1220;
  --card:#0f1b2e;
  --text:#e5e7eb;
  --muted:#9ca3af;
  --border:rgba(255,255,255,.12);
  --shadow: 0 12px 30px rgba(0,0,0,.35);
}
.dark body{ background:var(--bg); color:var(--text); }
.dark .topbar{ background:#0b3d33; }
.dark table{ background:var(--card); }
.dark th{ background:rgba(255,255,255,.06); }
.dark input, .dark select, .dark textarea{
  background:#0b1628; color:var(--text); border:1px solid var(--border);
}
.dark .btn-light{ background:#0b1628; color:var(--text); border-color:var(--border); }
.dark tbody tr:hover{ background:rgba(255,255,255,.04); }
.dark .bar-track{ background:rgba(255,255,255,.06); }


@media(max-width:900px){
  /* hide heavy columns only on small screens */
  
  .topbar .inner{
    flex-direction:column;
    align-items:flex-start;
  }
}


/* =====================================================
   MOBILE: Professional Card View (replaces table)
   ===================================================== */
@media (max-width: 980px){

  /* prevent weird header wrapping */
  th{ white-space: normal; }

  /* turn table into cards */
  .table-wrap{
    overflow: visible;
    border: 0;
    box-shadow: none;
    background: transparent;
  }

  table{
    background: transparent;
    border-collapse: separate;
    border-spacing: 0 14px;
  }

  thead{ display:none; }

  tbody, tr, td{ display:block; width:100%; }

  tbody tr{
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    overflow:hidden;
  }

  tbody tr td{
    display:flex;
    gap:12px;
    align-items:flex-start;
    justify-content:space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }
  tbody tr td:last-child{ border-bottom:0; }

  /* left label */
  tbody tr td::before{
    content: "";
    flex: 0 0 120px;
    min-width:120px;
    font-weight:950;
    font-size:12px;
    text-transform:uppercase;
    letter-spacing:.35px;
    color: var(--muted);
    padding-top:2px;
  }

  tbody tr td:nth-child(1)::before{ content:"#"; }
  tbody tr td:nth-child(2)::before{ content:"Name / Phone"; }
  tbody tr td:nth-child(3)::before{ content:"Product"; }
  tbody tr td:nth-child(4)::before{ content:"Status"; }
  tbody tr td:nth-child(5)::before{ content:"Address"; }
  tbody tr td:nth-child(6)::before{ content:"Comment"; }
  tbody tr td:nth-child(7)::before{ content:"Appointment"; }
  tbody tr td:nth-child(8)::before{ content:"Created"; }
  tbody tr td:nth-child(9)::before{ content:"Actions"; }

  /* content area */
  tbody tr td > *{
    max-width: calc(100% - 120px);
  }

  /* name block nicer */
  .name-cell{ align-items:flex-start; }
  .name-cell > div{ min-width:0; }
  .name-cell .muted{ word-break: break-word; }

  /* status line: badge + select wrap */
  td:nth-child(4) select{
    width: 170px;
    max-width: 100%;
  }

  /* actions become full-width buttons */
  td:nth-child(9) .actions{
    width:100%;
    display:flex;
    flex-direction:column;
    gap:10px;
    align-items:stretch;
  }
  td:nth-child(9) .actions a{
    width:100%;
    justify-content:center;
  }

  /* topbar stack */
  .topbar .inner{
    flex-direction:column;
    align-items:flex-start;
    gap:10px;
  }
}



/* =====================================================
   MOBILE: SHOW ALL DATABASE FIELDS (FINAL)
   ===================================================== */
@media (max-width: 980px){
  thead{ display:none; }
  .table-wrap{ overflow: visible; border:0; box-shadow:none; }
  table{ background:transparent; border-collapse:separate; border-spacing:0 14px; }
  tbody, tr, td{ display:block; width:100%; }

  tbody tr{
    background:var(--card);
    border:1px solid var(--border);
    border-radius:18px;
    box-shadow:var(--shadow);
    overflow:hidden;
  }

  tbody tr td{
    display:flex;
    justify-content:space-between;
    gap:12px;
    padding:12px 14px;
    border-bottom:1px solid var(--border);
  }
  tbody tr td:last-child{ border-bottom:0; }

  tbody tr td::before{
    flex:0 0 120px;
    min-width:120px;
    font-weight:950;
    font-size:12px;
    text-transform:uppercase;
    letter-spacing:.35px;
    color:var(--muted);
    content:"";
  }

  tbody tr td:nth-child(1)::before{content:"#";}
  tbody tr td:nth-child(2)::before{content:"Name / Phone";}
  tbody tr td:nth-child(3)::before{content:"Product";}
  tbody tr td:nth-child(4)::before{content:"Status";}
  tbody tr td:nth-child(5)::before{content:"Address";}
  tbody tr td:nth-child(6)::before{content:"Comment";}
  tbody tr td:nth-child(7)::before{content:"Appointment";}
  tbody tr td:nth-child(8)::before{content:"Created";}
  tbody tr td:nth-child(9)::before{content:"Actions";}

  td:nth-child(9) .actions{
    width:100%;
    display:flex;
    flex-direction:column;
    gap:10px;
  }
  td:nth-child(9) .actions a{
    width:100%;
    justify-content:center;
  }
}
