* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background 0.3s ease, color 0.3s ease;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Login Page */
.login-container {
  display: flex;
  min-height: 100vh;
}

.login-left {
  flex: 1;
  background: linear-gradient(135deg, var(--primary) 0%, #0a4d44 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
  color: white;
}

.login-branding {
  text-align: center;
  margin-bottom: 40px;
}

.login-logo { margin-bottom: 20px; }

.login-branding h1 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 16px;
  opacity: 0.9;
}

.login-features {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-feature {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  font-size: 14px;
}

.login-right {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  background: var(--page-bg);
}

.login-form-wrapper {
  width: 100%;
  max-width: 400px;
  position: relative;
}

.theme-toggle-login {
  position: absolute;
  top: -60px;
  right: 0;
}

.login-form-wrapper h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.login-description {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.login-form { display: flex; flex-direction: column; gap: 20px; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.input-wrapper input,
.form-input,
.form-select {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper input:focus,
.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-select { padding: 12px 14px; cursor: pointer; }

.password-toggle {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 16px;
}

.btn-outline:hover { background: var(--hover-bg); border-color: var(--primary); color: var(--primary); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-block { width: 100%; }

.btn-loader { display: inline-flex; animation: spin 1s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.login-error {
  padding: 12px;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
  margin-top: 16px;
}

.login-footer {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.login-footer p { font-size: 13px; color: var(--text-muted); margin-bottom: 8px; }

.login-footer code {
  font-size: 13px;
  padding: 4px 8px;
  background: var(--hover-bg);
  border-radius: 4px;
  color: var(--primary);
}

/* Theme Toggle */
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.theme-toggle-btn:hover { border-color: var(--primary); }

[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }

/* App Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease, background 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-item:hover { background: var(--hover-bg); color: var(--text-primary); }

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-icon { flex-shrink: 0; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.user-section {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.user-avatar.small { width: 36px; height: 36px; font-size: 13px; }

.user-info { display: flex; flex-direction: column; min-width: 0; }

.user-name { font-size: 14px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.user-role { font-size: 12px; color: var(--text-muted); text-transform: capitalize; }

.signout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--danger);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.signout-btn:hover { background: var(--danger-light); }

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

/* Header */
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
}

.header-title h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 240px;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 14px;
  transition: all 0.2s;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  width: 300px;
}

.notif-btn {
  position: relative;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
}

.notif-btn:hover { background: var(--hover-bg); color: var(--text-primary); }

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 600;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.header-user { display: flex; align-items: center; }

/* Page Content */
.page-content {
  padding: 24px 30px;
}

.page { display: none; }
.page.active { display: block; }

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  gap: 8px;
}

.filter-group .form-select { width: auto; min-width: 140px; }

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.clients-icon { background: #E8F5F2; color: #127769; }
.cases-icon { background: #EBF5FB; color: #2980B9; }
.active-icon { background: #FEF5E7; color: #E67E22; }
.team-icon { background: #F4ECF7; color: #8E44AD; }

.stat-info { display: flex; flex-direction: column; }

.stat-number {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

/* Card */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-header h3 { font-size: 16px; font-weight: 600; }

.card-body { padding: 0; }

/* Data Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  padding: 12px 20px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--page-bg);
}

.data-table td {
  padding: 14px 20px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: var(--hover-bg); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px !important;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-active {
  background: var(--badge-active-bg);
  color: var(--badge-active-text);
}

.badge-pending {
  background: var(--badge-pending-bg);
  color: var(--badge-pending-text);
}

.badge-closed {
  background: var(--badge-closed-bg);
  color: var(--badge-closed-text);
}

.badge-urgent { background: var(--danger-light); color: var(--danger); }
.badge-high { background: var(--warning-light); color: var(--warning); }
.badge-medium { background: var(--primary-light); color: var(--primary); }
.badge-low { background: var(--badge-closed-bg); color: var(--text-muted); }

/* Action Buttons */
.action-btns {
  display: flex;
  gap: 4px;
}

.action-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover { border-color: var(--primary); color: var(--primary); }
.action-btn.delete:hover { border-color: var(--danger); color: var(--danger); }

/* Activity Feed */
.activity-feed { padding: 16px; }

.activity-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.activity-dot.create { background: var(--success); }
.activity-dot.update { background: var(--warning); }
.activity-dot.delete { background: var(--danger); }
.activity-dot.login { background: var(--info); }
.activity-dot.upload { background: var(--primary); }

.activity-content { flex: 1; min-width: 0; }

.activity-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}

.activity-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-sm { max-width: 400px; }
.modal-lg { max-width: 700px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 18px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-body { padding: 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* Form styles */
.form-group + .form-group { margin-top: 16px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 14px;
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
}

.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Document Grid */
.documents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  padding: 20px;
}

.document-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.document-card:hover { border-color: var(--primary); background: var(--hover-bg); }

.doc-icon { font-size: 32px; }

.doc-name {
  font-size: 13px;
  text-align: center;
  color: var(--text-primary);
  word-break: break-all;
}

.doc-size {
  font-size: 11px;
  color: var(--text-muted);
}

.doc-actions { display: flex; gap: 4px; }

/* Case Detail */
.case-detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

.case-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.case-info-item { padding: 12px; background: var(--page-bg); border-radius: 8px; }

.case-info-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }

.case-info-value { font-size: 14px; font-weight: 500; color: var(--text-primary); }

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  max-width: 420px;
  animation: slideIn 0.3s ease;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
}

/* Upload Drop Zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-zone.has-file {
  border-color: var(--success);
  background: var(--success-light);
}

/* Responsive */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1024px) {
  .login-left { display: none; }
  .login-right { flex: none; width: 100%; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .mobile-menu-btn { display: flex; }
  .case-detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: 1fr; }
  .header-actions .search-wrapper { display: none; }
  .app-header { padding: 0 16px; }
  .page-content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .page-toolbar { flex-direction: column; align-items: stretch; }
  .filter-group { flex-direction: column; }
}