:root {
  --bg: #0b0f19;
  --panel: #111827;
  --panel-2: #1f2937;
  --text: #f8fafc;
  --muted: #94a3b8;
  --cyan: #22d3ee;
  --purple: #8b5cf6;
  --pink: #f472b6;
  --green: #22c55e;
  --red: #ef4444;
  --orange: #f97316;
  --yellow: #eab308;
  --border: rgba(148, 163, 184, 0.2);
  --shadow: 0 8px 30px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 70% 20%, rgba(139,92,246,0.15), transparent 45%), var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-logo { width: 56px; height: 56px; margin-bottom: 14px; }
.login-card h1 { font-size: 1.4rem; margin: 0 0 6px; }
.login-sub { color: var(--muted); margin: 0 0 24px; font-size: 0.95rem; }

.field { text-align: left; margin-bottom: 16px; }
.field label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--cyan); }
.field textarea { min-height: 80px; resize: vertical; }

.error-text { color: var(--red); font-size: 0.85rem; min-height: 20px; margin: 0 0 10px; }

.back-link { display: inline-block; margin-top: 18px; color: var(--muted); font-size: 0.9rem; }

/* App shell */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 64px 1fr;
  min-height: 100vh;
}

.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-left, .header-right { display: flex; align-items: center; gap: 12px; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  display: none;
}

.brand-mini { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-mini img { width: 28px; height: 28px; }

.user-name { color: var(--text); font-weight: 500; font-size: 0.9rem; }
.role-badge {
  background: rgba(34, 211, 238, 0.12);
  color: var(--cyan);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Side nav */
.side-nav {
  grid-row: 2 / -1;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active { background: rgba(34, 211, 238, 0.1); color: var(--cyan); }
.nav-icon { font-size: 1.1rem; }

/* Main */
.main {
  padding: 24px;
  overflow-y: auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title { font-size: 1.6rem; margin: 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: transform .1s, opacity .1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: linear-gradient(135deg, var(--cyan), var(--purple)); color: #fff; }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-danger { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.btn-success { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }

/* Cards / grid */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}

.card-title { font-size: 0.85rem; color: var(--muted); margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.card-value { font-size: 1.7rem; font-weight: 700; margin: 0; }
.card-sub { color: var(--muted); font-size: 0.85rem; margin: 6px 0 0; }

.alert-card {
  background: rgba(249, 115, 22, 0.08);
  border-color: rgba(249, 115, 22, 0.25);
}
.alert-card.danger { background: rgba(239, 68, 68, 0.08); border-color: rgba(239, 68, 68, 0.25); }
.alert-card.success { background: rgba(34, 197, 94, 0.08); border-color: rgba(34, 197, 94, 0.25); }
.alert-card.info { background: rgba(34, 211, 238, 0.08); border-color: rgba(34, 211, 238, 0.25); }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 640px;
}
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
th { background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}
.badge-active { background: rgba(34, 197, 94, 0.12); color: var(--green); }
.badge-paid { background: rgba(34, 211, 238, 0.12); color: var(--cyan); }
.badge-pending { background: rgba(249, 115, 22, 0.12); color: var(--orange); }
.badge-expired { background: rgba(239, 68, 68, 0.12); color: var(--red); }
.badge-cancelled { background: rgba(148, 163, 184, 0.12); color: var(--muted); }
.badge-fulfilled { background: rgba(34, 211, 238, 0.12); color: var(--cyan); }

.actions { display: flex; gap: 8px; flex-wrap: nowrap; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow);
}
.modal-card.wide { max-width: 720px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-title { font-size: 1.25rem; margin: 0; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.4rem; cursor: pointer; }

/* Forms in modal */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .field { margin-bottom: 0; }
.form-full { grid-column: 1 / -1; }

/* Empty state */
.empty { color: var(--muted); padding: 40px 20px; text-align: center; }

/* Dashboard lists */
.list { display: grid; gap: 10px; }
.list-item {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.list-meta { color: var(--muted); font-size: 0.85rem; }

/* Detail view */
.detail-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
}
.detail-section h3 {
  margin: 0 0 14px;
  font-size: 1rem;
  color: var(--text);
}

/* Money colors */
.money-positive { color: var(--green); }
.money-negative { color: var(--red); }
.money-neutral { color: var(--cyan); }

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.tab {
  padding: 10px 16px;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--cyan); border-color: var(--cyan); }

/* Mobile */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 56px 1fr; }
  .side-nav {
    position: fixed;
    inset: 56px auto 0 0;
    width: 220px;
    transform: translateX(-100%);
    transition: transform .2s;
    z-index: 40;
  }
  .side-nav.open { transform: translateX(0); }
  .icon-btn { display: block; }
  .main { padding: 14px; }
  .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; gap: 14px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-title { font-size: 1.4rem; }
  .card { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-card { margin: 0; border-radius: 16px 16px 0 0; max-height: 95vh; position: fixed; bottom: 0; left: 0; right: 0; width: 100%; max-width: 100%; }
}

@media (max-width: 640px) {
  .login-card { padding: 28px 20px; }
  .user-name { display: none; }
  .btn { padding: 10px 14px; font-size: 0.9rem; }
  .btn-sm { padding: 7px 10px; font-size: 0.8rem; }
  th, td { padding: 10px 12px; font-size: 0.85rem; }
  .card-value { font-size: 1.4rem; }
  .page-title { font-size: 1.3rem; }
  .header-right .btn { padding: 6px 10px; font-size: 0.8rem; }
  .nav-item { padding: 14px 16px; font-size: 1rem; }
}

@media (max-width: 480px) {
  table { font-size: 0.8rem; }
  th, td { padding: 8px 10px; }
  .btn-sm { padding: 6px 8px; font-size: 0.75rem; }
  .grid-2, .grid-3, .grid-4, .grid-5 { gap: 12px; }
  .hero h1 { font-size: 2.2rem; }
  .feature-grid { grid-template-columns: 1fr; }
}
