/* KAZI Design System — Coworking Management PWA */
:root {
  --primary: #1B5E3A; --primary-light: #2A8C5A; --primary-dark: #0F3D25;
  --secondary: #E8852E; --secondary-light: #F0A25C; --accent: #D4A857;
  --success: #10B981; --error: #EF4444; --warning: #F59E0B;
  --surface: #FFFFFF; --surface-alt: #F5F3EF; --surface-hover: #EDE9E3;
  --text: #1A1A2E; --text-muted: #6B7280; --text-light: #9CA3AF;
  --border: #E5E0D8; --radius: 8px; --radius-lg: 12px; --radius-pill: 999px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.12);
  --shadow-hover: 0 6px 24px rgba(0,0,0,0.14);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --nav-height: 64px; --topbar-height: 52px;
  --transition: 0.2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font); color: var(--text); background: var(--surface-alt);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  line-height: 1.5;
}

/* Utilitaires */
.text-muted { color: var(--text-muted) !important; }
.text-sm { font-size: 0.8rem !important; }
.text-danger { color: var(--error) !important; }
.w-full { width: 100% !important; }

/* App Shell */
#app { display: flex; flex-direction: column; height: 100%; }
#main-content { flex: 1; overflow-y: auto; position: relative; padding-bottom: var(--nav-height); }
#page-container { min-height: 100%; }

/* Loading Screen */
.loading-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; color: var(--primary); font-size: 1.5rem; font-weight: 700;
  gap: 16px;
}
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--surface-alt);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }

/* Pages */
.page {
  padding: 16px; max-width: 800px; margin: 0 auto;
  animation: fadeIn 0.25s ease;
}
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h2 { font-size: 1.4rem; font-weight: 700; color: var(--text); }

/* Cards */
.card, .stat-card, .space-card, .booking-card, .invoice-card, .plan-card, .report-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px;
  transition: box-shadow var(--transition), transform var(--transition);
}
.card:hover, .space-card:hover, .report-card:hover {
  box-shadow: var(--shadow-hover);
}

/* Dashboard Stats Grid */
.dashboard-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.stat-card { text-align: center; cursor: default; }
.stat-card:hover { box-shadow: var(--shadow-hover); }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* Action Grid */
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.action-btn {
  padding: 24px 16px; border: 2px dashed var(--border); border-radius: var(--radius-lg);
  background: var(--surface); font-size: 1rem; cursor: pointer; text-align: center;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.action-btn:active { border-color: var(--primary); background: var(--surface-alt); transform: scale(0.97); }
.action-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Space Cards */
.spaces-grid { display: grid; gap: 12px; }
.space-card { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.space-card:active { transform: scale(0.98); }
.space-icon { font-size: 2rem; width: 48px; text-align: center; }
.space-info { flex: 1; }
.space-info h3 { font-size: 1rem; font-weight: 600; }
.space-info p { font-size: 0.8rem; color: var(--text-muted); }

/* Booking Cards */
.booking-card { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.booking-info { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.booking-date { font-weight: 600; font-size: 0.9rem; }
.booking-space { font-size: 0.8rem; color: var(--text-muted); }

/* Invoice Cards */
.invoice-card { display: flex; align-items: center; }
.invoice-info { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; }
.invoice-number { font-weight: 600; flex: 1; min-width: 100px; }
.invoice-date { font-size: 0.8rem; color: var(--text-muted); }
.invoice-amount { font-weight: 600; color: var(--primary); margin-left: auto; }

/* Plan Cards */
.plans-grid { display: grid; gap: 16px; }
.plan-card { text-align: center; }
.plan-price { font-size: 2rem; font-weight: 700; color: var(--primary); margin: 12px 0 4px; }
.plan-price small { font-size: 0.9rem; font-weight: 400; color: var(--text-muted); }
.plan-period { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 12px; }
.plan-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 16px; }

/* Login Page */
.login-page {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px; background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}
.login-brand { text-align: center; margin-bottom: 32px; color: white; animation: slideDown 0.4s ease; }
.login-brand h1 { font-size: 2.5rem; font-weight: 800; }
.login-brand p { opacity: 0.8; margin-top: 4px; }
.login-card {
  background: white; border-radius: var(--radius-lg); padding: 24px;
  width: 100%; max-width: 360px; box-shadow: var(--shadow-lg);
  animation: slideUp 0.35s ease;
}
.login-tabs { display: flex; margin-bottom: 20px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.login-tab { flex: 1; padding: 10px; border: none; background: var(--surface-alt); cursor: pointer; font-size: 0.85rem; font-weight: 500; transition: background var(--transition); }
.login-tab:hover { background: var(--surface-hover); }
.login-tab.active { background: var(--primary); color: white; }
.login-footer { text-align: center; margin-top: 16px; font-size: 0.8rem; color: var(--text-muted); }

/* Form Elements */
.form-group { margin-bottom: 16px; }
.form-group label, .form-label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-input, .form-control {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 0.95rem; font-family: var(--font); background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition); outline: none;
  height: 48px;
}
.form-input:focus, .form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27,94,58,0.12); }
.form-input.error, .form-control.error { border-color: var(--error); box-shadow: 0 0 0 3px rgba(239,68,68,0.1); }
.form-input:disabled, .form-control:disabled { opacity: 0.5; cursor: not-allowed; background: var(--surface-alt); }
textarea.form-input, textarea.form-control { height: auto; min-height: 48px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border: none; border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 600; cursor: pointer; font-family: var(--font);
  transition: all var(--transition); text-decoration: none; line-height: 1;
  min-height: 48px; user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: var(--secondary-light); }
.btn-secondary:active { filter: brightness(0.9); }
.btn-outline { background: transparent; border: 2px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: rgba(27,94,58,0.04); }
.btn-outline:active { background: var(--surface-alt); }
.btn-ghost { background: transparent; border: none; color: var(--text); }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-icon {
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px;
}
.btn-sm { padding: 8px 14px; font-size: 0.8rem; min-height: 36px; }
.btn-block { width: 100%; }

/* Badges */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  white-space: nowrap;
}
.badge-primary { background: rgba(27,94,58,0.1); color: var(--primary); }
.badge-success { background: rgba(16,185,129,0.1); color: #10B981; }
.badge-warning { background: rgba(245,158,11,0.1); color: #F59E0B; }
.badge-error { background: rgba(239,68,68,0.1); color: #EF4444; }
.badge-secondary { background: rgba(107,114,128,0.1); color: var(--text-muted); }

/* Tabs */
.tabs { display: flex; gap: 0; margin-bottom: 16px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.tab { flex: 1; padding: 10px; border: none; background: var(--surface-alt); cursor: pointer; font-size: 0.85rem; font-weight: 500; transition: background var(--transition); }
.tab:hover { background: var(--surface-hover); }
.tab.active { background: var(--primary); color: white; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease; padding: 16px;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-overlay.active .modal-content { animation: slideUp 0.25s ease; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); padding: 0;
  width: 100%; max-width: 420px; max-height: 80vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); position: relative;
  animation: slideUp 0.25s ease;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 0; position: sticky; top: 0; background: var(--surface);
  z-index: 1;
}
.modal-header h3 { font-size: 1.15rem; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 1.3rem; cursor: pointer;
  color: var(--text-muted); width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
  transition: background var(--transition);
}
.modal-close:hover { background: var(--surface-alt); }
.modal-body { padding: 16px 24px 24px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 24px; border-top: 1px solid var(--border);
}
.modal-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 16px; }

/* Toast */
.toast-container {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 300;
  display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 400px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-radius: var(--radius); color: white;
  font-weight: 500; font-size: 0.9rem; box-shadow: var(--shadow-lg);
  animation: slideDown 0.3s ease; pointer-events: auto;
}
.toast.toast-removing { animation: fadeIn 0.3s ease reverse forwards; }
.toast-icon { flex-shrink: 0; font-size: 1.1rem; }
.toast-message { flex: 1; }
.toast-close {
  flex-shrink: 0; background: none; border: none; color: rgba(255,255,255,0.8);
  cursor: pointer; font-size: 1rem; padding: 2px 4px; border-radius: 4px;
  transition: color var(--transition);
}
.toast-close:hover { color: white; }
.toast-success { background: var(--success); }
.toast-error { background: var(--error); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--primary); }

/* Admin Layout */
.admin-layout { display: flex; gap: 16px; min-height: 60vh; }
.admin-sidebar { width: 160px; flex-shrink: 0; }
.admin-nav { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 68px; }
.admin-nav-item {
  padding: 10px 12px; border: none; background: none; text-align: left;
  font-size: 0.85rem; cursor: pointer; border-radius: var(--radius);
  color: var(--text); transition: all var(--transition);
}
.admin-nav-item:hover { background: var(--surface-hover); }
.admin-nav-item.active { background: var(--primary); color: white; }
.admin-nav-item:active { background: var(--surface-hover); }
.admin-content { flex: 1; }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; text-align: left; font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:active { background: var(--surface-alt); }
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

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

/* Section Header */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

/* Profile */
.profile-logout { margin-top: 32px; }

/* Loading Spinner */
.loading-spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 40px auto;
}

/* App Layout (Sidebar + Main) */
.app-layout {
  display: flex; height: 100vh; overflow: hidden;
}
.app-sidebar {
  width: 240px; background: var(--primary); color: white;
  display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto;
}
.sidebar-logo { padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-logo-text { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.5px; display: block; }
.sidebar-logo-sub { font-size: 0.7rem; opacity: 0.7; display: block; margin-top: 2px; }
.sidebar-nav { flex: 1; padding: 10px; }
.sidebar-nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: var(--radius);
  color: rgba(255,255,255,0.75); text-decoration: none; font-size: 0.85rem; font-weight: 500;
  transition: all var(--transition); cursor: pointer; border: none; background: none; width: 100%; text-align: left;
  position: relative;
}
.sidebar-nav-item:hover { background: rgba(255,255,255,0.1); color: white; }
.sidebar-nav-item:active { transform: scale(0.97); }
.sidebar-nav-item.active { background: rgba(255,255,255,0.18); color: white; font-weight: 600; }
.sidebar-nav-item.active::before {
  content: ''; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; background: white; border-radius: 0 3px 3px 0;
}
.nav-icon { font-size: 1.15rem; width: 22px; text-align: center; flex-shrink: 0; }
.nav-label { font-size: 0.85rem; }
.sidebar-footer { padding: 10px; border-top: 1px solid rgba(255,255,255,0.1); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px 14px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 0.75rem; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-username { font-size: 0.85rem; font-weight: 600; }
.app-main { flex: 1; overflow-y: auto; background: var(--surface-alt); }

/* Bottom Nav (Mobile) */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: white; border-top: 1px solid var(--border);
  padding: 6px 0; padding-bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 100; justify-content: space-around;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 6px 0; text-decoration: none;
  font-size: 1.3rem; color: var(--text-muted); cursor: pointer; transition: all var(--transition);
  position: relative; min-height: 48px; justify-content: center;
}
.bottom-nav-item:active { transform: scale(0.92); }
.bottom-nav-item .nav-label { font-size: 0.6rem; font-weight: 500; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item.active .nav-label { font-weight: 700; color: var(--primary); }

/* Checkin Page */
.checkin-stats-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.checkin-result-item:hover { background: var(--surface-alt); }

/* Reports Page */
.reports-grid { display: grid; gap: 16px; }
.report-card { cursor: default; }
.report-card-header { margin-bottom: 12px; }
.report-card-header h4 { font-size: 0.9rem; font-weight: 600; color: var(--text-muted); }
.report-card-body { min-height: 100px; }
.report-card-body svg { max-width: 100%; }

/* Admin */
.admin-settings-input { width: 220px; font-size: 0.85rem !important; }

/* Checkbox & Radio Styling */
input[type="checkbox"], input[type="radio"] {
  width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer;
}

/* Mobile: hide sidebar, show bottom nav */
@media (max-width: 767px) {
  .app-sidebar { display: none; }
  .bottom-nav { display: flex; }
  .app-main { padding-bottom: 68px; }
  .checkin-stats-grid { grid-template-columns: 1fr 1fr; }
  .login-page { padding: 16px; }
  .page { padding: 12px; }
  .btn { padding: 10px 16px; }
  .modal { margin: 12px; }
}

/* Desktop: show sidebar */
@media (min-width: 768px) {
  .dashboard-stats { grid-template-columns: repeat(4, 1fr); }
  .spaces-grid { grid-template-columns: 1fr 1fr; }
  .plans-grid { grid-template-columns: repeat(3, 1fr); }
  .action-grid { grid-template-columns: repeat(4, 1fr); }
  .page { padding: 24px; }
  .bottom-nav { display: none; }
  .reports-grid { grid-template-columns: 1fr 1fr; }
  .btn { min-height: 40px; }
}
