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

:root {
  --primary: #a85454;
  --primary-dark: #8b3a3a;
  --primary-light: #fdeae8;
  --bg: #faf8f6;
  --success: #2d6a4f;
  --success-bg: #d8f3dc;
  --danger: #c0392b;
  --danger-bg: #fde8e8;
  --warning: #e85d04;
  --warning-bg: #fff3cd;
  --called-bg: #fef5f3;
  --border: #e8e3df;
  --gray-500: #666;
  --gray-700: #333;
  --gray-900: #212529;
  --radius: 20px;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 15px;
  min-height: 100vh;
  overflow: hidden;
}

body.page-fila,
body.page-painel {
  background: var(--bg);
  display: block;
  padding: 0;
  overflow: auto;
}

/* ======================== */
/* RECEPTION - CONTAINER    */
/* ======================== */

.container {
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-width: 500px;
  width: 100%;
  max-height: 95vh;
  overflow-y: auto;
  padding: 30px;
  animation: slideIn 0.5s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-30px); }
  to { opacity: 1; transform: translateY(0); }
}

.container::-webkit-scrollbar { width: 6px; }
.container::-webkit-scrollbar-track { background: #f1efed; border-radius: 10px; }
.container::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }
.container::-webkit-scrollbar-thumb:hover { background: var(--primary-dark); }

/* Logo */
.logo {
  text-align: center;
  margin-bottom: 20px;
  padding: 10px;
}

.logo img {
  max-width: 220px;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 2px 8px rgba(168, 84, 84, 0.15));
}

/* Welcome */
.welcome {
  background: linear-gradient(135deg, #fef5f3 0%, #fdeae8 100%);
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 20px;
  text-align: center;
  border-left: 4px solid var(--primary);
}

.welcome p {
  color: #5a3232;
  line-height: 1.5;
  font-size: 14px;
}

.welcome strong {
  color: var(--primary-dark);
}

/* ======================== */
/* FORM                     */
/* ======================== */

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

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--gray-700);
  font-weight: 600;
  font-size: 13px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  transition: all 0.3s;
  background: #ffffff;
  font-family: inherit;
  color: var(--gray-700);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(168, 84, 84, 0.1);
}

.form-group .hint {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ======================== */
/* BUTTONS                  */
/* ======================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  font-family: inherit;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(168, 84, 84, 0.3);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn-success {
  background: linear-gradient(135deg, #2d6a4f, #1b5e20);
}

.btn-success:hover:not(:disabled) {
  box-shadow: 0 10px 20px rgba(45, 106, 79, 0.3);
}

.btn-danger {
  background: linear-gradient(135deg, #c0392b, #9d0208);
}

.btn-danger:hover:not(:disabled) {
  box-shadow: 0 10px 20px rgba(192, 57, 43, 0.3);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  width: auto;
  border-radius: 8px;
}

/* ======================== */
/* ALERTS                   */
/* ======================== */

.alert {
  padding: 12px 15px;
  border-radius: 10px;
  margin-bottom: 15px;
  font-size: 14px;
  display: none;
}

.alert.show { display: block; }

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #b7e4c7;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f5c6cb;
}

.alert-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #ffc107;
}

.alert-info {
  background: var(--called-bg);
  color: var(--primary);
  border: 1px solid var(--primary-light);
}

/* ======================== */
/* SUCCESS MESSAGE          */
/* ======================== */

.success-message {
  text-align: center;
  padding: 20px 0;
  display: none;
}

.success-message.show { display: block; }

.success-icon {
  font-size: 60px;
  margin-bottom: 15px;
}

.success-message h2 {
  color: var(--primary);
  margin-bottom: 12px;
  font-size: 22px;
}

.success-message p {
  color: var(--gray-500);
  line-height: 1.5;
  margin-bottom: 8px;
  font-size: 14px;
}

.queue-number {
  font-size: 42px;
  font-weight: bold;
  color: var(--primary);
  margin: 15px 0;
  text-shadow: 0 2px 4px rgba(168, 84, 84, 0.2);
}

.success-link {
  display: inline-block;
  margin-top: 15px;
  padding: 12px 28px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  text-decoration: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.success-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(168, 84, 84, 0.3);
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top: 3px solid white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ======================== */
/* FILA STATUS PAGE         */
/* ======================== */

.header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 1.5rem 2rem;
  text-align: center;
  box-shadow: 0 4px 20px rgba(168, 84, 84, 0.3);
}

.page-painel .header {
  background: #f8f4f4;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 1rem 2rem;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.header-logo {
  height: 56px;
  width: auto;
  border-radius: 8px;
  flex-shrink: 0;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.header .subtitle {
  font-size: 1.05rem;
  opacity: 0.9;
  margin-top: 0.25rem;
}

.container-fila,
.container-page {
  max-width: 500px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.container-wide {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* Card */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
  padding: 2rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--gray-700);
}

/* Badge */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-waiting { background: var(--warning-bg); color: var(--warning); }
.badge-called { background: var(--called-bg); color: var(--primary); }
.badge-completed { background: var(--success-bg); color: var(--success); }
.badge-cancelled { background: #f1efed; color: var(--gray-500); }

/* Position Display */
.position-display {
  text-align: center;
  padding: 1.5rem 0;
}

.position-number {
  font-size: 5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  text-shadow: 0 2px 4px rgba(168, 84, 84, 0.2);
}

.position-label {
  font-size: 1rem;
  color: var(--gray-500);
  margin-top: 0.5rem;
}

.called-alert {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 2rem;
  border-radius: var(--radius);
  text-align: center;
  animation: pulse 1.5s infinite;
  display: none;
  margin-bottom: 1.5rem;
}

.called-alert.show { display: block; }

.called-alert h2 {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

/* ======================== */
/* PANEL PAGE               */
/* ======================== */

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.exam-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
  overflow: hidden;
}

.exam-card-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.exam-card-header h3 { font-size: 1rem; }

.exam-card-header .count {
  background: rgba(255,255,255,0.2);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.85rem;
}

.exam-card-body {
  padding: 1rem 1.25rem;
}

.exam-card-body .call-btn {
  margin-bottom: 1rem;
}

.patient-list { list-style: none; }

.patient-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid #f1efed;
  gap: 0.5rem;
}

.patient-item:last-child { border-bottom: none; }

.patient-info { flex: 1; min-width: 0; }

.patient-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.patient-phone {
  font-size: 0.8rem;
  color: var(--gray-500);
}

.patient-wait-time {
  font-size: 0.75rem;
  color: var(--warning, #f59e0b);
  margin-top: 0.15rem;
}

/* Historico */
.historico-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.historico-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: var(--gray-100);
  color: var(--gray-600);
  font-weight: 600;
  border-bottom: 2px solid var(--gray-200);
}

.historico-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

.historico-table tr:last-child td { border-bottom: none; }
.historico-table tr:hover td { background: var(--gray-50, #fafafa); }

.filtro-btn {
  background: var(--gray-100);
  color: var(--gray-600);
  border: 1px solid var(--gray-200);
}

.filtro-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.filtro-btn:hover:not(.active) {
  background: var(--gray-200);
}

.patient-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}

.empty-queue {
  text-align: center;
  color: var(--gray-500);
  padding: 2rem 0;
  font-size: 0.9rem;
}

/* Admin Section */
.admin-section { margin-top: 2rem; }

.admin-toggle {
  cursor: pointer;
  color: var(--gray-500);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  user-select: none;
}

.admin-content { display: none; }
.admin-content.show { display: block; }

.admin-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.admin-form input {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}

.admin-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(168, 84, 84, 0.1);
}

.exam-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f1efed;
}

/* ======================== */
/* RESPONSIVE               */
/* ======================== */

@media (max-width: 600px) {
  body { padding: 10px; }

  .container {
    padding: 25px 20px;
    max-height: 98vh;
  }

  .logo { margin-bottom: 15px; padding: 8px; }
  .logo img { max-width: 180px; }

  .welcome { padding: 12px; margin-bottom: 15px; }
  .welcome p { font-size: 13px; }

  .form-group { margin-bottom: 15px; }
  .form-group input,
  .form-group select { padding: 11px; font-size: 14px; }

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

  .success-icon { font-size: 50px; }
  .success-message h2 { font-size: 20px; }
  .queue-number { font-size: 36px; }

  .header { padding: 1rem; }
  .header h1 { font-size: 1.2rem; }
  .header-logo { height: 40px; }

  .panel-grid { grid-template-columns: 1fr; }
  .position-number { font-size: 4rem; }
}

@media (max-height: 700px) {
  .container { padding: 20px; }
  .logo { margin-bottom: 12px; padding: 6px; }
  .logo img { max-width: 160px; }
  .welcome { padding: 10px; margin-bottom: 12px; }
  .welcome p { font-size: 12px; }
  .form-group { margin-bottom: 12px; }
  .form-group label { font-size: 12px; margin-bottom: 4px; }
  .form-group input,
  .form-group select { padding: 10px; font-size: 13px; }
  .btn { padding: 11px; font-size: 14px; }
}
