/* Main Layout & Core Component Styles - KostKu */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');
@import url('./variables.css');

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
}

/* App Wrapper */
.app-container {
  display: flex;
  width: 100%;
  min-height: 100vh;
  position: relative;
}

/* Sidebar Navigation */
.app-sidebar {
  width: 270px;
  background-color: var(--bg-sidebar);
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  transition: transform var(--transition-normal);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand {
  padding: 24px 20px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 22px;
  box-shadow: 0 4px 14px rgba(30, 58, 138, 0.45);
}

.brand-details h1 {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.02em;
}

.brand-details p {
  font-size: 0.72rem;
  color: #60a5fa;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-nav {
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: #94a3b8;
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
}

.nav-item:hover {
  background-color: var(--bg-sidebar-hover);
  color: #ffffff;
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(37, 99, 235, 0.22), rgba(30, 58, 138, 0.12));
  color: #93c5fd;
  font-weight: 600;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.nav-item.active .nav-icon {
  color: #60a5fa;
}

.nav-icon {
  font-size: 1.15rem;
  width: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background-color: rgba(239, 68, 68, 0.2);
  color: #f87171;
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.quick-switch-mode {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.quick-switch-mode:hover {
  background: rgba(99, 102, 241, 0.2);
  color: #ffffff;
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: hidden;
}

/* Header */
.app-header {
  height: 72px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-title-box h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.header-title-box p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.kost-badge-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.kost-badge-pill span.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--primary);
  box-shadow: 0 0 6px var(--primary);
}

.header-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  background: white;
  border: 1px solid var(--border-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.header-tool-btn:hover {
  background: var(--bg-card-subtle);
  border-color: var(--text-light);
}

.header-user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
}

.header-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: white;
  font-weight: 700;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.header-user-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-main);
  max-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-user-role {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--primary);
}

.btn-logout-header {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-logout-header:hover {
  background: #fef2f2;
  border-color: var(--danger);
}

/* Page Content Body */
.page-container {
  padding: 32px;
  flex: 1;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: white;
  border: 1px solid #1e3a8a;
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #172554, #1d4ed8);
  border-color: #172554;
  box-shadow: 0 4px 14px rgba(30, 58, 138, 0.4);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--secondary);
  color: white;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-secondary:hover {
  background-color: var(--secondary-hover);
  transform: translateY(-1px);
}

.btn-outline {
  background-color: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-light);
}

.btn-outline:hover {
  background-color: var(--bg-card-subtle);
  border-color: #cbd5e1;
}

.btn-danger {
  background-color: var(--danger);
  color: white;
}

.btn-danger:hover {
  background-color: var(--danger-hover);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-icon-only {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  cursor: pointer;
}

.btn-icon-only:hover {
  background: var(--bg-card-subtle);
  color: var(--text-main);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background-color: var(--status-available-bg);
  color: var(--status-available-text);
}

.badge-danger {
  background-color: var(--status-occupied-bg);
  color: var(--status-occupied-text);
}

.badge-warning {
  background-color: var(--status-maintenance-bg);
  color: var(--status-maintenance-text);
}

.badge-info {
  background-color: var(--info-light);
  color: var(--info);
}

.badge-neutral {
  background-color: var(--bg-card-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-light);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(9, 14, 31, 0.7);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  overflow-y: auto;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

#modal-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-height: 100%;
}

.modal-card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25), 0 8px 10px -6px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-light);
  width: 100%;
  max-width: 600px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  margin: auto;
  transform: scale(0.96) translateY(8px);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

.modal-overlay.active .modal-card {
  transform: scale(1) translateY(0);
}

/* Form as direct child of modal-card must flex vertically */
.modal-card > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  margin: 0;
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background-color: var(--bg-card);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.modal-close-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-card-subtle);
}

.modal-body {
  padding: 22px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
}

.modal-body::-webkit-scrollbar {
  width: 6px;
}

.modal-body::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.modal-body::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background-color: #f8fafc;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 5;
}

@media (max-height: 680px) {
  .modal-card {
    max-height: 94vh;
  }
  .modal-header {
    padding: 12px 18px;
  }
  .modal-body {
    padding: 14px 18px;
  }
  .modal-footer {
    padding: 12px 18px;
  }
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.88rem;
  background-color: var(--bg-card);
  color: var(--text-main);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 420px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background-color: #0f172a;
  color: #ffffff;
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideInToast 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  border-left: 4px solid var(--primary);
}

.toast.toast-error {
  border-left-color: var(--danger);
}

.toast.toast-warning {
  border-left-color: var(--accent);
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-size: 0.85rem;
  font-weight: 700;
}

.toast-msg {
  font-size: 0.78rem;
  color: #cbd5e1;
}

@keyframes slideInToast {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Responsive Media Queries */
@media (max-width: 900px) {
  .app-sidebar {
    position: fixed;
    left: -270px;
  }
  .app-sidebar.mobile-open {
    transform: translateX(270px);
  }
  .page-container {
    padding: 20px;
  }
  .app-header {
    padding: 0 20px;
  }
}
