/* ==========================================================================
   style.css — Full organized theme + improved professional sidebar/nav + modal fixes
   Replace your existing CSS with this file. Clear browser cache after replacing.
   ========================================================================== */

/* ==========================================================================
   THEME VARIABLES
   ========================================================================== */
:root{
  --sidebar-width: 260px;

  --crimson: #C81E2D;        /* primary (buttons, accents) */
  --brand:   #ff4d4f;        /* complementary brand */
  --maroon:  #6b0f1a;        /* headings / strong text */
  --rosy:    #e85b67;        /* soft accent */
  --blush:   #ffecec;        /* very light surface */

  --light:   #fff6f6;
  --border:  #f2d7d9;
  --ink:     #211417;
  --muted:   #7b6266;
  --line:    #f5e6e7;

  --glass:   rgba(255,255,255,.78);
  --glass-stroke: rgba(33,20,23,.06);
  --shadow-1: 0 6px 18px rgba(0,0,0,.06);
  --shadow-2: 0 16px 40px rgba(200,30,45,.07);
  --e:       cubic-bezier(.2,.8,.2,1);

  --card-odd:  linear-gradient(180deg,#fff7f7 0%, #ffffff 100%);
  --card-even: linear-gradient(180deg,#fff1f2 0%, #fff6f6 100%);
  --grad-hover: linear-gradient(145deg, rgba(200,30,45,.08) 0%, rgba(232,91,103,.03) 55%, rgba(255,242,242,.95) 100%);

  --mesh:
    radial-gradient(1200px 700px at 85% 8%, rgba(255,84,92,.06), transparent 62%),
    radial-gradient(900px 600px at 10% 82%, rgba(255,138,141,.03), transparent 64%),
    linear-gradient(180deg,#fff,#fff);
}

/* ==========================================================================
   RESET & BASE
   ========================================================================== */
* { box-sizing: border-box; }
html, body {
  height:100%;
  margin:0;
  padding:0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color:var(--ink);
  background:var(--mesh);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  -webkit-font-feature-settings: "rlig" 1;
}
img { max-width:100%; height:auto; display:block; }
a { color:var(--crimson); text-decoration:none; }
button { font-family:inherit; cursor:pointer; }

/* ==========================================================================
   HEADER
   ========================================================================== */
.header {
  position:fixed;
  top:0; left:0; right:0;
  height:64px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 20px;
  background:var(--glass);
  backdrop-filter: blur(6px);
  border-bottom:1px solid var(--glass-stroke);
  gap:12px;
  z-index:1050; /* below modal */
}

/* brand */
.brand { display:flex; align-items:center; gap:12px; min-width:0; }
.brand .logo {
  width:44px; height:44px; border-radius:10px;
  background:var(--card-odd);
  display:flex; align-items:center; justify-content:center;
  font-weight:800; font-size:18px; color:var(--crimson);
  box-shadow:var(--shadow-2);
}
.brand .title {
  font-weight:800;
  font-size:18px;
  color:var(--crimson) !important;
  margin:0;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width:260px;
}

/* header right controls */
.header-controls { display:flex; align-items:center; gap:8px; }
.header-controls .user-pill {
  display:flex; align-items:center; gap:10px; padding:6px 10px; border-radius:999px;
  background:rgba(0,0,0,0.025); border:1px solid rgba(0,0,0,0.03);
}
.menu-label {
  display:none;
  font-size:22px;
  padding:8px;
  border-radius:8px;
  cursor:pointer;
  background:transparent;
  border:none;
  color:var(--maroon);
}

/* ==========================================================================
   SIDEBAR / NAV (improved professional design)
   ========================================================================== */
.sidebar {
  position:fixed;
  top:64px;               /* header height */
  left:0;
  width:var(--sidebar-width);
  bottom:0;
  padding:18px 14px;
  background: linear-gradient(180deg, var(--light), #fff);
  border-right:1px solid var(--line);
  overflow:auto;
  z-index:1000;
}

/* nav list styling */
.sidebar .nav {
  list-style:none;
  margin:0;
  padding:6px 6px;
  display:flex;
  flex-direction:column;
  gap:6px;
}
.sidebar .nav li { display:block; }
.sidebar .nav a {
  display:flex;
  align-items:center;
  gap:12px;
  padding:10px 12px;
  border-radius:10px;
  color:var(--maroon);
  font-weight:600;
  text-decoration:none;
  transition: all .18s var(--e);
  box-shadow: none;
  position:relative;
  overflow:hidden;
}
.sidebar .nav a .icon {
  width:36px; height:36px; border-radius:8px; display:inline-flex; align-items:center; justify-content:center;
  background:transparent;
  color:var(--crimson);
  font-weight:700;
  box-shadow: none;
  flex-shrink:0;
}

/* hover and active */
.sidebar .nav a:hover {
  transform: translateX(4px);
  background: var(--grad-hover);
  color:var(--crimson);
  box-shadow: var(--shadow-1);
}
.sidebar .nav a.active {
  background: linear-gradient(90deg, rgba(200,30,45,.06), rgba(232,91,103,.02));
  color:var(--crimson);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.2);
}

/* optional right badge (count) */
.sidebar .nav a .nav-badge {
  margin-left:auto;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:28px;
  padding:4px 8px;
  border-radius:999px;
  background:#fff0f1;
  color:var(--crimson);
  font-size:0.82rem;
  border:1px solid rgba(200,30,45,.06);
}

/* collapse groups */
.sidebar .group-title {
  font-size:12px;
  text-transform:uppercase;
  color:var(--muted);
  margin:12px 8px 6px;
  letter-spacing:0.06em;
}

/* compact / mini icons for narrow width */
.sidebar.mini { width:72px; padding:12px; }
.sidebar.mini .brand { display:none; }
.sidebar.mini .nav a { justify-content:center; padding:10px; }
.sidebar.mini .nav a .label { display:none; }
.sidebar.mini .nav a .nav-badge { display:none; }

/* ==========================================================================
   LAYOUT: content wrapper (push right by sidebar + below header)
   ========================================================================== */
.content-wrap {
  margin-top:64px; /* header */
  margin-left:var(--sidebar-width); /* sidebar */
  padding:24px;
  min-height: calc(100vh - 64px);
  transition: margin-left .28s var(--e), padding .2s ease;
}
.content-wrap.fullwidth { margin-left:0; }

/* small helper for page headings */
.page-title { font-size:1.25rem; font-weight:700; color:var(--maroon); margin:0 0 12px 0; }

/* ==========================================================================
   CORE COMPONENTS: card / buttons / kpis / tables
   ========================================================================== */
.card {
  background:var(--card-odd);
  border:1px solid var(--border);
  border-radius:12px;
  padding:18px;
  box-shadow:var(--shadow-1);
}
.top-bar { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:18px; }

/* button system */
.btn {
  display:inline-flex; align-items:center; gap:8px;
  background: linear-gradient(90deg,var(--crimson),var(--brand));
  color:#fff; border:none;
  padding:8px 12px; border-radius:10px; cursor:pointer; font-weight:700;
  box-shadow:0 6px 18px rgba(200,30,45,.06);
}
.btn.ghost { background:transparent; color:var(--maroon); border:1px solid var(--border); padding:8px 10px; }
.btn.primary { background: linear-gradient(90deg,var(--crimson),var(--brand)); color:#fff; padding:10px 14px; border-radius:10px; }
.btn.small { padding:6px 10px; font-size:14px; border-radius:8px; }
.btn.danger { background:#b00015; color:#fff; }

/* KPI */
.kpi-row { display:flex; gap:16px; margin-bottom:18px; flex-wrap:wrap; }
.kpi { flex:0 0 220px; padding:14px; border-radius:12px; background:var(--card-even); border:1px solid var(--border); }
.kpi .muted { color:var(--muted); font-size:13px; }
.kpi .value { font-size:22px; font-weight:800; color:var(--maroon); }

/* TABLES */
.table-wrap { overflow:auto; margin-top:12px; }
table { width:100%; border-collapse:collapse; font-size:14px; min-width:640px; }
thead th {
  background: linear-gradient(90deg, rgba(200,30,45,.04), rgba(232,91,103,.02));
  padding:12px; text-align:left; position:sticky; top:0; z-index:2; font-weight:700;
}
tbody td { padding:12px; border-bottom:1px solid var(--line); vertical-align:middle; }
.table-actions { display:flex; gap:8px; align-items:center; }

/* small text */
.muted { color:var(--muted); font-size:13px; }
.small { font-size:13px; color:var(--muted); }

/* ==========================================================================
   ATTACHMENT MODAL FIXES & PREVIEW
   - Use Bootstrap modal; these rules make sure it's above header/sidebar.
   ========================================================================== */

/* Ensure modal/backdrop above header and sidebar */
.modal-backdrop {
  z-index:2080 !important;
}
.modal {
  z-index:2090 !important;
}

/* Attachments modal sizing */
#attachmentsModal .modal-dialog {
  max-width:1100px;
  width:100%;
}
#attachmentsModal .modal-content {
  border-radius:12px;
  overflow:hidden;
}
#attachmentsModal .modal-body { padding:16px; }

/* Attachment items layout */
.attachment-row { display:flex; flex-wrap:wrap; gap:1rem; }
.attachment-item {
  background:#fff;
  border:1px solid rgba(0,0,0,.06);
  border-radius:8px;
  padding:12px;
  flex:1 1 320px;
  display:flex;
  flex-direction:column;
  min-width:260px;
}
.attachment-item .preview {
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  border-radius:6px;
  background:#f8f9fa;
  padding:6px;
  min-height:140px;
  max-height:60vh;
}
.attachment-item img { max-width:100%; max-height:60vh; object-fit:contain; display:block; }
.attachment-item object, .attachment-item iframe { width:100%; height:60vh; border:0; }
.attachment-item .meta { margin-top:8px; display:flex; gap:8px; align-items:center; justify-content:space-between; }
.attachment-title { font-weight:600; font-size:0.95rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.attachment-actions { display:flex; gap:8px; }

/* stack attachments on small screens */
@media (max-width:768px) {
  .attachment-item { flex: 1 1 100%; min-width:100%; }
  #attachmentsModal .modal-dialog { max-width:95%; margin:1rem; }
}

/* ==========================================================================
   FORMS & CONTROLS
   ========================================================================== */
.form-control,
input.form-control,
select.form-control,
textarea.form-control {
  width:100%;
  padding:10px 12px;
  border-radius:10px;
  border:1px solid var(--border);
  background: linear-gradient(180deg,#fff,#fffaf9);
  font-size:15px;
  color:var(--ink);
  transition: box-shadow .12s ease, border-color .12s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,.03);
  outline: none;
}
.form-control:focus { border-color: rgba(200,30,45,.24); box-shadow: 0 10px 30px rgba(200,30,45,.06); }
.form-control::placeholder { color: #b59a9a; opacity:1; }
select.form-control { appearance:none; padding-right:36px; background-position: calc(100% - 18px) calc(1em + 2px); background-size: 6px 6px; }

/* ==========================================================================
   RESPONSIVE: collapse sidebar and make header compact on small screens
   ========================================================================== */
@media (max-width:1000px) {
  .sidebar { transform: translateX(-100%); left:0; position:fixed; transition: transform .22s ease-in-out; }
  .sidebar.open { transform: translateX(0); box-shadow:0 24px 60px rgba(33,20,23,.12); }
  .menu-label { display:inline-flex; color:var(--maroon); background:transparent; border:none; }
  .content-wrap { margin-left:0; padding:16px; }
  .kpi { flex:1 1 48%; }
}
@media (max-width:600px) {
  .kpi { flex:1 1 100%; }
  .brand .title { font-size:15px; max-width:140px; }
  .brand .logo { width:40px; height:40px; }
  .header { padding:10px; height:56px; }
}

/* ==========================================================================
   UTILITIES & POLISH
   ========================================================================== */
.hidden { display:none !important; }
.center { display:flex; align-items:center; justify-content:center; }
.form-control[readonly], .form-control[disabled] { background:#fbfbfb; color:#9b8b8b; cursor:not-allowed; }

/* table polish */
.card { background:#fff; padding:18px; border-radius:10px; box-shadow: var(--shadow-1); }
.table-wrap { overflow-x:auto; margin-top:10px; }
th, td { padding:12px 10px; border-bottom:1px solid #eee; text-align:left; vertical-align:middle; }
th { background:#fafafa; font-weight:700; }
.btn.small { padding:6px 8px; font-size:0.88rem; border-radius:6px; }
.badge { padding:4px 8px; border-radius:999px; font-size:0.82rem; background:#eee; }

/* ==========================================================================
   DEBUG: quick overrides if modal still behind elements (temporary)
   - Use via DevTools to find necessary z-index to override rogue CSS
   ========================================================================== */
/*
.modal-backdrop { z-index:5000 !important; }
.modal { z-index:5010 !important; }
*/
/* SweetAlert2 custom styling */
.swal2-popup {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    border-radius: 12px;
    padding: 2rem 2rem 1.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    max-width: 500px;
}
.swal2-title {
    font-size: 1.6rem;
    font-weight: 600;
    color: #C81E2D;
    margin-bottom: 1rem;
}
.swal2-input, .swal2-textarea, .swal2-select {
    font-size: 1rem;
    padding: 0.7rem;
    border-radius: 6px;
    border: 1px solid #ccc;
    width: 100%;
    box-sizing: border-box;
    margin: 6px 0;
}
.swal2-input:focus, .swal2-textarea:focus, .swal2-select:focus {
    border-color: #C81E2D;
    box-shadow: 0 0 5px rgba(200,30,45,0.5);
    outline: none;
}
.swal2-confirm {
    background-color: #C81E2D !important;
    color: #fff !important;
    font-weight: 600;
    border-radius: 8px;
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
}
.swal2-cancel {
    background-color: #6b0f1a !important;
    color: #fff !important;
    font-weight: 500;
    border-radius: 8px;
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
}