:root{
  --bg: #0b1020;
  --panel: rgba(255,255,255,0.06);
  --panel2: rgba(255,255,255,0.09);
  --text: rgba(255,255,255,0.92);
  --muted: rgba(255,255,255,0.62);
  --border: rgba(255,255,255,0.10);
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --radius: 16px;
  --accent: #7c5cff;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  background: radial-gradient(1200px 500px at 20% 10%, rgba(124,92,255,0.25), transparent 50%),
              radial-gradient(1000px 500px at 80% 10%, rgba(0,200,255,0.16), transparent 55%),
              var(--bg);
  color: var(--text);
}

a{color:inherit}

/* ========== AUTH ========== */
.auth-page{min-height:100%;display:flex;align-items:center;justify-content:center;padding:24px}
.auth-card{
  width: min(480px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 22px;
}
.auth-card h1{margin:0 0 6px 0;font-size:22px}
.auth-card .muted{color:var(--muted);font-size:13px;margin-bottom:14px}
.form-row{display:flex;flex-direction:column;gap:8px;margin:12px 0}

label{font-size:13px;color:var(--muted)}
.input, .select{
  width:100%;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.22);
  color: var(--text);
  outline:none;
}
.input:focus,.select:focus{border-color: rgba(124,92,255,0.55)}

/* ========== BUTTONS ========== */
.btn{
  display:inline-flex;align-items:center;justify-content:center;gap:10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(124,92,255,0.18);
  color: var(--text);
  cursor:pointer;
  text-decoration:none;
}
.btn:hover{background: rgba(124,92,255,0.26)}
.btn-primary{background: rgba(124,92,255,0.28)}
.btn-ghost{background: transparent}
.btn-danger{background: rgba(255,70,70,0.14)}
.btn-sm{padding: 8px 10px;border-radius:12px;font-size:12px}

.alert{
  border: 1px solid rgba(255,70,70,0.35);
  background: rgba(255,70,70,0.10);
  padding: 10px 12px;
  border-radius: 14px;
  margin: 12px 0;
}

/* ========== APP LAYOUT (MATCHES lib/view.php) ========== */
.app{
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  width: 100%;
}

/* Sidebar */
.sidebar{
  grid-column: 1;
  width: 280px;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: auto;

  padding: 18px;
  border-right: 1px solid var(--border);
  background: rgba(0,0,0,0.10);
  backdrop-filter: blur(12px);
}

.brand{display:flex;align-items:center;gap:10px;margin-bottom:18px}
.brand .logo{
  width:38px;height:38px;border-radius:14px;
  display:flex;align-items:center;justify-content:center;
  font-weight:800;
  background: linear-gradient(135deg, rgba(124,92,255,0.85), rgba(0,200,255,0.55));
  box-shadow: 0 10px 20px rgba(124,92,255,0.18);
}
.brand-title{font-weight:800}
.brand-sub{font-size:12px;color:var(--muted)}

.nav{display:flex;flex-direction:column;gap:8px;margin-top:10px}
.nav a{
  display:flex;align-items:center;gap:10px;
  padding: 12px 12px;
  border-radius: 14px;
  border:1px solid transparent;
  color: var(--muted);
  text-decoration:none;
}
.nav a.active{color:var(--text);background: var(--panel2);border-color: var(--border)}
.nav a:hover{color:var(--text);background: rgba(255,255,255,0.06)}

.sidebar-footer{margin-top:14px}

/* Main */
.main{
  grid-column: 2;
  min-width: 0;      /* IMPORTANT for tables + overflow */
  height: 100vh;
  overflow: auto;    /* Desktop scroll inside main */
  padding: 18px 18px 30px;
}

/* Topbar */
.topbar{
  position: sticky;
  top: 0;
  z-index: 5;

  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;

  padding: 12px 12px;
  margin: -18px -18px 14px; /* compensate main padding */
  background: rgba(0,0,0,0.10);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.topbar-title{font-weight:700}
.topbar-right{display:flex;align-items:center;gap:10px}

.icon-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover{background: rgba(255,255,255,0.10)}

.pill{
  display:inline-flex;
  align-items:center;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  font-size: 12px;
  color: var(--muted);
}

/* Hamburger icon */
.hamburger{
  width: 18px;
  height: 2px;
  background: var(--text);
  display:block;
  border-radius: 999px;
  position: relative;
}
.hamburger::before,
.hamburger::after{
  content:'';
  position:absolute;
  left:0;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 999px;
}
.hamburger::before{ top: -6px; }
.hamburger::after{ top: 6px; }

/* Content container */
.content{padding-top: 6px}

/* ========== PAGE ========== */
.page-head{
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:12px;
  margin-bottom:14px;
}
.page-head h1{margin:0;font-size:22px}
.muted{color:var(--muted)}
.actions{display:flex;gap:10px;flex-wrap:wrap}

/* ========== GRID / CARDS ========== */
.grid{display:grid;gap:14px}
.grid-2{grid-template-columns: 1.2fr 0.8fr}
.grid-3{grid-template-columns: repeat(3, 1fr)}

.card{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card .card-head{padding:14px 14px 0 14px}
.card .card-title{font-weight:700}
.card .card-sub{font-size:12px;color:var(--muted);margin-top:3px}
.card .card-body{padding: 14px}

.kpis{display:grid;gap:12px;grid-template-columns: repeat(3, 1fr)}
.kpi{
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
}
.kpi .label{font-size:12px;color:var(--muted)}
.kpi .value{font-size:20px;font-weight:800;margin-top:6px}

/* ========== TABLES ========== */
.table-wrap{overflow:auto}
.table{width:100%;border-collapse:separate;border-spacing:0 10px}
.table th{
  font-size:12px;
  color:var(--muted);
  font-weight:600;
  text-align:left;
  padding:0 10px;
}
.table td{padding: 12px 10px}
.table tr.data-row td{
  background: rgba(0,0,0,0.18);
  border-top:1px solid var(--border);
  border-bottom:1px solid var(--border);
}
.table tr.data-row td:first-child{
  border-left:1px solid var(--border);
  border-top-left-radius:14px;
  border-bottom-left-radius:14px;
}
.table tr.data-row td:last-child{
  border-right:1px solid var(--border);
  border-top-right-radius:14px;
  border-bottom-right-radius:14px;
}
.badge{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(255,255,255,0.06);
  font-size:12px
}
.badge-dot{width:10px;height:10px;border-radius:50%}
.amount-neg{color: rgba(255,120,120,0.95);font-weight:700}
.amount-pos{color: rgba(130,255,170,0.95);font-weight:700}
.right{text-align:right}

/* ========== MODALS (MATCH modal() HTML) ========== */
.modal[hidden]{display:none !important;}

.modal{
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 100;
  background: rgba(0,0,0,0.55);
}

.modal-card{
  width: min(560px, 100%);
  background: rgba(15,18,35,0.95);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:14px 16px;
  border-bottom:1px solid var(--border);
}
.modal-title{font-weight:800}
.modal-body{padding:14px 16px}
.modal-footer{
  padding:14px 16px;
  border-top:1px solid var(--border);
  display:flex;
  gap:10px;
  justify-content:flex-end;
  flex-wrap:wrap;
}

/* ========== TOASTS (align with your JS) ========== */
#toastHost{
  position:fixed;
  right:16px;
  bottom:16px;
  display:flex;
  flex-direction:column;
  gap:10px;
  z-index: 200;
}
.toast{
  background: rgba(0,0,0,0.65);
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px 14px;
  box-shadow: var(--shadow);
  max-width:360px;
  transition: opacity .2s ease, transform .2s ease;
}
.toast-success{border-color: rgba(130,255,170,0.25)}
.toast-error{border-color: rgba(255,120,120,0.25)}
.toast.out{opacity:0;transform: translateY(6px)}

/* ========== RESPONSIVE ========== */
@media (max-width: 980px){
  .grid-2{grid-template-columns:1fr}
  .kpis{grid-template-columns:1fr}
}

@media (max-width: 860px){
  .app{grid-template-columns:1fr}

  .sidebar{
    position: fixed;
    left: -100%;
    top: 0;
    width: 280px;
    height: 100vh;
    z-index: 50;
    transition: left .25s ease;
  }

  body.sidebar-open .sidebar{
    left: 0;
  }

  .main{
    grid-column: 1;
    height: auto;
    min-height: 100vh;
    overflow: visible;
    padding: 14px;
  }

  .topbar{
    margin: -14px -14px 14px;
  }
}