/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', Arial, sans-serif; background: #f4f6fb; color: #222; min-height: 100vh; }
a { text-decoration: none; color: inherit; }

/* ===== HEADER ===== */
.main-header {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-bottom: 2px solid #e0e0e0;
  padding: 10px 24px; flex-wrap: wrap; gap: 10px;
  position: sticky; top: 0; z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.logo-box { width: 54px; height: 54px; border: 2px solid #ccc; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.logo-box img { width: 100%; height: 100%; object-fit: contain; }
.logo-fallback { font-size: 13px; font-weight: 700; color: #888; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.school-logo-center { display: flex; flex-direction: column; gap: 2px; }
.school-logo-text { font-size: 18px; font-weight: 600; color: #333; }
.school-name-text { font-size: 22px; font-weight: 700; color: #111; }
.header-right { display: flex; align-items: center; gap: 10px; }
.header-btn { padding: 7px 18px; border-radius: 6px; font-size: 14px; font-weight: 600;
  background: #f0f0f0; border: 1px solid #ccc; cursor: pointer; transition: background 0.2s; }
.header-btn:hover { background: #e0e0e0; }
.login-btn { background: #2563eb; color: #fff; border-color: #2563eb; }
.login-btn:hover { background: #1d4ed8; }

/* ===== LAYOUT ===== */
.main-layout { display: flex; min-height: calc(100vh - 76px); }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 270px; min-width: 220px; background: #fff;
  border-right: 1px solid #e0e0e0; padding: 18px 14px;
  display: flex; flex-direction: column; gap: 16px; flex-shrink: 0;
}
.warning-box {
  background: #fff8e1; border: 1px solid #ffe082; border-radius: 8px;
  padding: 10px 12px; font-size: 12.5px; color: #7a5800; line-height: 1.5;
}
.warn-icon { margin-right: 4px; }
.qr-box {
  border: 2px solid #bbb; border-radius: 8px; min-height: 160px;
  display: flex; align-items: center; justify-content: center;
}
.qr-placeholder {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 28px; font-weight: 700; color: #555;
}
.status-box {
  text-align: center; font-size: 13px; color: #444;
  padding: 8px; background: #f5f5f5; border-radius: 6px;
}
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.status-dot.connected { background: #22c55e; }
.status-dot.disconnected { background: #ef4444; }
.howto-box { background: #eff6ff; border-radius: 8px; padding: 12px; }
.howto-title { font-weight: 700; font-size: 13.5px; color: #1e40af; margin-bottom: 10px; }
.howto-list { padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; counter-reset: howto; }
.howto-list li { font-size: 12.5px; color: #333; display: flex; gap: 8px; align-items: flex-start; counter-increment: howto; }
.howto-list li::before {
  content: counter(howto); background: #2563eb; color: #fff;
  min-width: 20px; height: 20px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0;
}

/* ===== CONTENT AREA ===== */
.content-area { flex: 1; padding: 20px 24px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* ===== TAB NAV ===== */
.tab-nav {
  display: flex; gap: 0; background: #fff; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08); overflow-x: auto; flex-wrap: nowrap;
}
.tab-link {
  flex: 1; min-width: 130px; padding: 13px 10px; text-align: center;
  font-size: 13.5px; font-weight: 600; color: #555; border-bottom: 3px solid transparent;
  transition: all 0.2s; white-space: nowrap; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.tab-link:hover { color: #2563eb; background: #f0f5ff; }
.tab-link.active { color: #2563eb; border-bottom-color: #2563eb; background: #eff6ff; }
.tab-icon { font-size: 15px; }

/* ===== SECTIONS ===== */
.section-title { font-size: 14px; font-weight: 700; color: #333; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.upload-section, .send-mode-section, .template-section, .students-section {
  background: #fff; border-radius: 10px; padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

/* ===== DROP ZONE ===== */
.drop-zone {
  border: 2px dashed #93c5fd; border-radius: 10px; background: #f8fbff;
  min-height: 130px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  padding: 24px; cursor: pointer; transition: background 0.2s;
}
.drop-zone:hover, .drop-zone.dragover { background: #dbeafe; }
.drop-icon { font-size: 28px; }
.drop-zone p { font-size: 14px; color: #555; }
.drop-sub { font-size: 12px; color: #999; }
.template-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.template-hint { font-size: 12px; color: #888; }

/* ===== SEND MODE CARDS ===== */
.send-mode-cards { display: flex; gap: 12px; flex-wrap: wrap; }
.mode-card {
  flex: 1; min-width: 120px; border: 2px solid #e0e0e0; border-radius: 10px;
  padding: 16px 12px; text-align: center; cursor: pointer; transition: all 0.2s; background: #fff;
}
.mode-card:hover { border-color: #93c5fd; background: #f0f8ff; }
.mode-card.active { border-color: #2563eb; background: #eff6ff; }
.mode-icon { font-size: 22px; margin-bottom: 6px; }
.mode-name { font-size: 13.5px; font-weight: 700; color: #222; }
.mode-sub { font-size: 11.5px; color: #888; }

/* ===== MESSAGE TEMPLATE ===== */
.template-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.template-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.select-input { padding: 6px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px; background: #fff; }
.template-textarea {
  width: 100%; min-height: 150px; border: 1px solid #ddd; border-radius: 8px;
  padding: 12px; font-size: 13px; color: #333; background: #fafafa;
  resize: vertical; line-height: 1.6; font-family: inherit;
}
.template-note { font-size: 11.5px; color: #999; margin-top: 6px; }

/* ===== STUDENTS SECTION ===== */
.no-students { text-align: center; padding: 40px 20px; }
.no-students-icon { font-size: 40px; color: #ccc; margin-bottom: 10px; }
.no-students p { font-size: 14px; color: #888; }
.no-students-sub { font-size: 12px; color: #bbb; margin-top: 4px; }
.students-table-wrap { overflow-x: auto; }
.students-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.students-table th { background: #f0f5ff; color: #2563eb; font-weight: 700; padding: 10px 12px; text-align: left; border-bottom: 2px solid #dbeafe; }
.students-table td { padding: 9px 12px; border-bottom: 1px solid #f0f0f0; color: #333; }
.students-table tr:hover td { background: #f8fbff; }
.badge { padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-sent { background: #dcfce7; color: #166534; }
.badge-failed { background: #fee2e2; color: #991b1b; }

/* ===== SEND BAR ===== */
.send-bar { background: #fff; border-radius: 10px; padding: 14px 20px; box-shadow: 0 1px 4px rgba(0,0,0,0.07); text-align: center; }
.btn-send {
  background: #2563eb; color: #fff; font-size: 15px; font-weight: 700;
  padding: 13px 48px; border-radius: 8px; border: none; cursor: pointer;
  width: 100%; max-width: 400px; transition: background 0.2s;
}
.btn-send:hover:not(:disabled) { background: #1d4ed8; }
.btn-send:disabled { background: #b0c4f0; cursor: not-allowed; }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border-radius: 7px; font-size: 13.5px; font-weight: 600; cursor: pointer; border: none; transition: all 0.2s; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-outline { background: #fff; color: #2563eb; border: 1.5px solid #2563eb; }
.btn-outline:hover { background: #eff6ff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  z-index: 999; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: #fff; border-radius: 14px; width: 100%; max-width: 400px;
  padding: 28px 28px 24px; box-shadow: 0 8px 32px rgba(0,0,0,0.2); animation: fadeUp 0.25s;
}
@keyframes fadeUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.modal-logo {
  width: 44px; height: 44px; background: linear-gradient(135deg,#4f46e5,#2563eb);
  border-radius: 10px; color: #fff; font-weight: 800; font-size: 16px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.modal-title { font-size: 18px; font-weight: 800; color: #1e1e2e; }
.modal-sub { font-size: 12px; color: #888; }
.modal-tabs { display: flex; border-bottom: 2px solid #e0e0e0; margin-bottom: 18px; }
.modal-tab {
  flex: 1; padding: 10px; background: none; border: none; font-size: 14px;
  font-weight: 700; color: #aaa; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all 0.2s;
}
.modal-tab.active { color: #2563eb; border-bottom-color: #2563eb; }
.modal-form { display: flex; flex-direction: column; gap: 12px; }
.form-input {
  width: 100%; padding: 11px 14px; border: 1.5px solid #ddd; border-radius: 8px;
  font-size: 14px; color: #333; background: #fafafa; transition: border 0.2s;
  outline: none;
}
.form-input:focus { border-color: #2563eb; background: #fff; }
.modal-link { text-align: center; font-size: 13px; color: #666; }
.modal-link a { color: #2563eb; font-weight: 600; }
.modal-close-area { position: fixed; inset: 0; z-index: -1; }

/* ===== PROFILE PAGE ===== */
.profile-panel {
  position: fixed; right: 0; top: 76px; width: 300px; height: calc(100vh - 76px);
  background: #fff; border-left: 1px solid #e0e0e0; box-shadow: -4px 0 16px rgba(0,0,0,0.1);
  padding: 20px 18px; display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto; z-index: 200;
}
.profile-top { display: flex; align-items: center; justify-content: space-between; }
.profile-actions { display: flex; gap: 8px; }
.profile-logo-circle {
  width: 70px; height: 70px; border-radius: 50%; border: 2px solid #2563eb;
  display: flex; align-items: center; justify-content: center; margin: 0 auto 4px;
  background: #eff6ff; font-size: 13px; color: #2563eb; font-weight: 700; cursor: pointer;
  overflow: hidden;
}
.profile-logo-circle img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile-field label { font-size: 12px; color: #888; font-weight: 600; display: block; margin-bottom: 3px; }
.profile-field .field-val { font-size: 14px; color: #222; padding: 8px 10px; background: #f5f5f5; border-radius: 6px; }
.profile-field input { width: 100%; padding: 8px 10px; border: 1.5px solid #ddd; border-radius: 6px; font-size: 14px; }
.subuser-box { background: #f8fbff; border: 1px solid #dbeafe; border-radius: 8px; padding: 12px; }
.subuser-title { font-size: 13.5px; font-weight: 700; color: #1e40af; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; }
.unlimited-badge { background: #fef9c3; color: #854d0e; font-size: 11px; padding: 2px 8px; border-radius: 20px; }
.btn-logout { background: #fff; color: #ef4444; border: 1.5px solid #ef4444; width: 100%; justify-content: center; margin-top: 8px; }
.btn-logout:hover { background: #fee2e2; }

/* ===== MANUAL SEND ===== */
.recipients-box { display: flex; flex-direction: column; gap: 10px; }
.recipient-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.recipient-row input { flex: 1; min-width: 120px; padding: 9px 12px; border: 1.5px solid #ddd; border-radius: 7px; font-size: 13.5px; }
.recipient-row input:focus { border-color: #2563eb; outline: none; }
.btn-remove { background: none; border: none; color: #ef4444; font-size: 18px; cursor: pointer; padding: 4px 6px; }
.message-area { width: 100%; min-height: 120px; border: 1.5px solid #ddd; border-radius: 8px; padding: 12px; font-size: 14px; resize: vertical; font-family: inherit; }
.message-area:focus { outline: none; border-color: #2563eb; }
.char-count { text-align: right; font-size: 12px; color: #aaa; margin-top: 4px; }
.btn-send-manual { background: #f97316; color: #fff; width: 100%; justify-content: center; padding: 14px; font-size: 15px; border-radius: 8px; margin-top: 8px; }
.btn-send-manual:hover { background: #ea6b00; }

/* ===== ATTENDANCE ===== */
.attendance-info { background: #eff6ff; border-radius: 8px; padding: 10px 14px; font-size: 13px; color: #1e40af; margin-bottom: 4px; }
.btn-send-attendance { background: #2563eb; color: #fff; width: 100%; justify-content: center; padding: 13px; font-size: 15px; border-radius: 8px; }
.btn-send-attendance:disabled { background: #b0c4f0; cursor: not-allowed; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .main-layout { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid #e0e0e0; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .qr-box { min-height: 100px; width: 100px; flex-shrink: 0; }
  .howto-box { flex: 1; min-width: 200px; }
  .warning-box { flex: 1; min-width: 180px; }
  .status-box { min-width: 160px; }
}
@media (max-width: 600px) {
  .main-header { padding: 8px 12px; }
  .school-name-text { font-size: 16px; }
  .school-logo-text { font-size: 14px; }
  .content-area { padding: 12px; }
  .tab-nav { gap: 0; }
  .tab-link { font-size: 12px; min-width: 80px; padding: 10px 6px; }
  .send-mode-cards { flex-direction: column; }
  .template-header { flex-direction: column; align-items: flex-start; }
  .profile-panel { width: 100%; top: auto; bottom: 0; height: 80vh; border-radius: 16px 16px 0 0; }
  .modal-box { padding: 20px 16px; }
  .sidebar { padding: 10px; }
  .qr-box { display: none; }
}
@media (min-width: 601px) and (max-width: 900px) {
  .sidebar { gap: 10px; }
}
