:root {
  --red: #E71D36;
  --red-dark: #D6142E;
  --red-light: #FEE2E5;
  --blue: #123F9E;
  --blue-dark: #0E2F75;
  --blue-light: #EFF6FF;
  --bg: #F8F9FB;
  --card-bg: #FFFFFF;
  --sidebar-bg: #FAFAFA;
  --border: #E5E7EB;
  --border-dark: #D1D5DB;
  --text-primary: #111827;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --green: #059669;
  --green-light: #ECFDF5;
  --orange: #D97706;
  --orange-light: #FFFBEB;
  --yellow: #FBBF24;
  --purple: #7C3AED;
  --purple-light: #F5F3FF;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --font: 'Inter', 'Segoe UI', Roboto, sans-serif;
}

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: var(--font);
  cursor: pointer;
}

input, select, textarea {
  font-family: var(--font);
}

img {
  max-width: 100%;
  height: auto;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-left: var(--sidebar-width);
  transition: margin-left 0.3s ease;
}

.app-content {
  flex: 1;
  padding: 32px;
  max-width: 1400px;
  width: 100%;
}

.topbar {
  height: var(--topbar-height);
  background: var(--card-bg);
  border-bottom: 2px solid var(--red);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  min-width: 0;
}

.topbar-menu-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.topbar-menu-btn:hover {
  background: var(--bg);
  color: var(--text-primary);
}

.topbar-breadcrumb {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.topbar-notifications {
  position: relative;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.topbar-notifications:hover {
  background: var(--bg);
  color: var(--text-primary);
}

.notif-count {
  position: absolute;
  top: 2px;
  right: 2px;
  background: var(--red);
  color: white;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topbar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.topbar-user-role {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.viewing-as-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #FEF3C7;
  border: 1px solid #FCD34D;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  color: #92400E;
}

.viewing-as-exit {
  background: #92400E;
  color: white;
  border: none;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.notification-panel {
  position: fixed;
  top: var(--topbar-height);
  right: 16px;
  width: 380px;
  max-height: 480px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}

.notif-panel-actions button {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
}

.notif-panel-list {
  overflow-y: auto;
  flex: 1;
}

.notif-item {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.notif-item:hover {
  background: var(--bg);
}

.notif-item.unread {
  background: var(--blue-light);
}

.notif-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
  flex-shrink: 0;
  margin-top: 5px;
}

.notif-item.read .notif-item-dot {
  background: var(--border);
}

.notif-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.notif-item-body {
  font-size: 12px;
  color: var(--text-secondary);
}

.notif-item-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.notif-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  margin-left: auto;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-start;
}

.notif-delete:hover {
  color: var(--red);
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
  letter-spacing: -0.3px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header-left {}

.page-header-right {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 300px;
}

.page-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.2s;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-card-accent {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--blue);
}

.stat-card-accent.red { background: var(--red); }
.stat-card-accent.green { background: var(--green); }
.stat-card-accent.orange { background: var(--orange); }
.stat-card-accent.purple { background: var(--purple); }

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}

.stat-change.up {
  background: var(--green-light);
  color: var(--green);
}

.stat-change.down {
  background: var(--red-light);
  color: var(--red);
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

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

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-body {
  padding: 24px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
  font-family: var(--font);
  text-decoration: none;
  line-height: 1.4;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn-primary:hover {
  background: var(--red-dark);
  box-shadow: 0 2px 8px rgba(231,29,54,0.3);
}

.btn-secondary {
  background: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
  border-color: var(--border-dark);
}

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

.btn-blue:hover {
  background: var(--blue-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg);
  color: var(--text-primary);
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

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

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text-primary);
  font-family: var(--font);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.form-control:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(18,63,158,0.1);
}

.form-control::placeholder {
  color: var(--text-muted);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.badge-p1 { background: var(--red); color: white; }
.badge-p2 { background: #F59E0B; color: #000; }
.badge-p3 { background: var(--blue); color: white; }

.badge-new { background: #E5E7EB; color: var(--text-primary); }
.badge-inprogress { background: #FEF3C7; color: #92400E; }
.badge-review { background: var(--purple-light); color: var(--purple); }
.badge-blocked { background: var(--red-light); color: var(--red); }
.badge-closed { background: var(--green-light); color: var(--green); }

.badge-admin { background: var(--red-light); color: var(--red); }
.badge-super-admin { background: #FEF3C7; color: #92400E; }
.badge-manager { background: var(--blue-light); color: var(--blue); }
.badge-user { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); }

.badge-daily { background: var(--blue-light); color: var(--blue); }
.badge-monthly { background: var(--green-light); color: var(--green); }
.badge-long-term { background: var(--purple-light); color: var(--purple); }

.progress-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue) 0%, var(--red) 100%);
  border-radius: 4px;
  transition: width 0.6s ease;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 12px;
}

.progress-label-title {
  color: var(--text-secondary);
}

.progress-label-pct {
  font-weight: 700;
  color: var(--text-primary);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 11px;
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: 17px;
}

.search-bar {
  position: relative;
}

.search-bar svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-bar input {
  padding-left: 38px;
}

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.filter-chip {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.filter-chip:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.filter-chip.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.filter-chip.active-red {
  background: var(--red);
  border-color: var(--red);
  color: white;
}

.empty-state {
  text-align: center;
  padding: 64px 32px;
  color: var(--text-secondary);
}

.empty-state svg {
  margin: 0 auto 16px;
  color: var(--border);
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-state-desc {
  font-size: 14px;
  color: var(--text-secondary);
}

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

.toast {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  min-width: 280px;
  max-width: 360px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  pointer-events: all;
  animation: toast-in 0.25s ease;
}

.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--blue); }
.toast.warning { border-left: 4px solid var(--orange); }

.toast-title {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.toast-body {
  color: var(--text-secondary);
  font-size: 12px;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 24px;
  overflow-y: auto;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 680px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s ease;
  position: relative;
}

.modal-lg {
  max-width: 900px;
}

.modal-sm {
  max-width: 460px;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(-20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
  color: var(--text-primary);
  background: var(--bg);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  gap: 10px;
}

.modal-footer-right {
  display: flex;
  gap: 10px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 12px;
  margin-top: 24px;
}

.vote-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  border: 2px solid var(--border);
  background: var(--card-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.vote-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-light);
}

.vote-btn.voted {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.vote-btn.voted:hover {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}

.vote-count {
  background: rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
}

.vote-btn:not(.voted) .vote-count {
  background: var(--bg);
  color: var(--text-primary);
}

.days-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.days-badge.ok {
  background: var(--green-light);
  color: var(--green);
}

.days-badge.warning {
  background: var(--orange-light);
  color: var(--orange);
}

.days-badge.overdue {
  background: var(--red-light);
  color: var(--red);
}

.rank-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
}

.rank-badge.rank-1 { background: #FEF3C7; color: #92400E; }
.rank-badge.rank-2 { background: #F3F4F6; color: #374151; }
.rank-badge.rank-3 { background: #FEF3C7; color: #92400E; }
.rank-badge.rank-other { background: var(--bg); color: var(--text-muted); font-size: 11px; }

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  gap: 4px;
}

.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
  font-family: var(--font);
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
  font-weight: 600;
}

.chart-container {
  position: relative;
  width: 100%;
}

.voter-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.voter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

@media (max-width: 1024px) {
  .app-main {
    margin-left: 0;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .form-grid-3 {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .app-content {
    padding: 20px 16px;
  }
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .form-grid-2, .form-grid-3 {
    grid-template-columns: 1fr;
  }
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }
}
