/* --- Google Font Import --- */
@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&display=swap');

/* --- Design Tokens --- */
:root {
  --color-primary: #427A43;
  --color-background: #F2E3BB;
  --color-shade: #C0B87A;
  --color-accent: #005F02;
  --color-white: #FFFFFF;
  --color-error: #D32F2F;
  --color-text: #333333;
  --color-text-light: #666666;
  --font-main: 'Instrument Serif', serif;
  --touch-target: 44px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--color-background);
  font-family: var(--font-main);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  padding: 1rem;
}

/* --- Container --- */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
}

/* --- Hide Alpine.js flash --- */
[x-cloak] {
  display: none !important;
}

/* --- Login Overlay --- */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-background);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.login-card {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-card h1 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
  color: var(--color-primary);
}

.login-card p {
  color: var(--color-text-light);
  margin-bottom: 1.5rem;
}

.login-error {
  background: #ffebee;
  color: var(--color-error);
  padding: 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* --- Header --- */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-shade);
}

.header h1 {
  font-size: 1.5rem;
  color: var(--color-primary);
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 0.9rem;
  transition: all 0.2s ease;
  min-height: var(--touch-target);
}

.btn-logout:hover {
  background: var(--color-primary);
  color: var(--color-white);
}

/* --- Banner (Current Position) --- */
.banner {
  background: var(--color-primary);
  color: var(--color-white);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.banner-label {
  font-size: 0.85rem;
  opacity: 0.9;
  margin-bottom: 0.25rem;
}

.banner-position {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 0.25rem;
}

.banner-arabic {
  font-size: 1.25rem;
  opacity: 0.9;
}

.banner-empty {
  font-style: italic;
  opacity: 0.8;
}

/* --- Form Styles --- */
.card {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.1rem;
  color: var(--color-primary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-shade);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  color: var(--color-text-light);
  margin-bottom: 0.5rem;
}

input[type="text"],
input[type="number"],
input[type="password"] {
  width: 100%;
  min-height: var(--touch-target);
  padding: 0.75rem;
  border: 1px solid var(--color-shade);
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(66, 122, 67, 0.15);
}

/* --- Searchable Dropdown --- */
.dropdown-container {
  position: relative;
}

.dropdown-input {
  width: 100%;
  min-height: var(--touch-target);
  padding: 0.75rem;
  border: 1px solid var(--color-shade);
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.dropdown-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(66, 122, 67, 0.15);
}

.dropdown-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-white);
  border: 1px solid var(--color-shade);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 250px;
  overflow-y: auto;
  z-index: 100;
  margin-top: 0.25rem;
}

.dropdown-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.15s ease;
}

.dropdown-item:hover {
  background: var(--color-background);
}

.dropdown-item-number {
  font-weight: bold;
  color: var(--color-primary);
  min-width: 2rem;
}

.dropdown-item-name {
  flex: 1;
  margin-left: 0.5rem;
}

.dropdown-item-arabic {
  color: var(--color-text-light);
  font-size: 0.9rem;
}

.dropdown-empty {
  padding: 1rem;
  text-align: center;
  color: var(--color-text-light);
  font-style: italic;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target);
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-white);
  width: 100%;
}

.btn-primary:hover {
  background: var(--color-accent);
}

.btn-primary:disabled {
  background: var(--color-shade);
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--color-shade);
  color: var(--color-text);
}

.btn-secondary:hover {
  background: var(--color-background);
}

.btn-sm {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  min-height: 36px;
}

.btn-icon {
  background: transparent;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: var(--color-text-light);
  transition: color 0.2s ease;
  min-height: 36px;
  min-width: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  color: var(--color-primary);
}

.btn-icon.delete:hover {
  color: var(--color-error);
}

/* --- Progress Bar --- */
.progress-section {
  margin-bottom: 1.5rem;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.progress-juz {
  font-weight: bold;
  color: var(--color-primary);
}

.progress-bar {
  background: var(--color-shade);
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
}

.progress-fill {
  background: var(--color-primary);
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s ease;
}

/* --- History Table --- */
.history-section {
  margin-bottom: 1.5rem;
}

.history-title {
  font-size: 1.1rem;
  color: var(--color-primary);
  margin-bottom: 1rem;
}

.history-table {
  width: 100%;
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.history-table table {
  width: 100%;
  border-collapse: collapse;
}

.history-table th,
.history-table td {
  padding: 0.75rem 1rem;
  text-align: left;
}

.history-table th {
  background: var(--color-background);
  font-weight: bold;
  font-size: 0.85rem;
  color: var(--color-text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-table tr:nth-child(even) td {
  background: rgba(242, 227, 187, 0.3);
}

.history-table tr:hover td {
  background: rgba(242, 227, 187, 0.5);
}

.history-surah {
  font-weight: bold;
}

.history-verse {
  color: var(--color-text-light);
}

.history-date {
  font-size: 0.85rem;
  color: var(--color-text-light);
}

.history-actions {
  display: flex;
  gap: 0.25rem;
}

.history-empty {
  padding: 2rem;
  text-align: center;
  color: var(--color-text-light);
  font-style: italic;
}

/* --- Inline Edit --- */
.edit-input {
  width: 100%;
  min-height: 36px;
  padding: 0.5rem;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  font-family: var(--font-main);
  font-size: 0.9rem;
}

.edit-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* --- Pagination --- */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 1rem;
}

.pagination-btn {
  background: var(--color-white);
  border: 1px solid var(--color-shade);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  min-height: var(--touch-target);
  cursor: pointer;
  font-family: var(--font-main);
  transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--color-primary);
  color: var(--color-white);
  border-color: var(--color-primary);
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-info {
  font-size: 0.9rem;
  color: var(--color-text-light);
  padding: 0 1rem;
}

/* --- Loading State --- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--color-text-light);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-shade);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 0.5rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Toast Notifications --- */
.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: var(--color-white);
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: slideUp 0.3s ease;
}

.toast.error {
  background: var(--color-error);
}

.toast.success {
  background: var(--color-primary);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(1rem);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* --- Mobile Responsive --- */
@media (max-width: 600px) {
  body {
    padding: 0.5rem;
  }

  .container {
    padding: 0.75rem;
  }

  .header h1 {
    font-size: 1.25rem;
  }

  .banner {
    padding: 1rem;
  }

  .banner-position {
    font-size: 1.25rem;
  }

  .card {
    padding: 1rem;
  }

  .history-table th,
  .history-table td {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }

  .history-date {
    display: none;
  }

  .dropdown-list {
    max-height: 200px;
  }

  .pagination {
    flex-wrap: wrap;
  }
}

/* --- Utility Classes --- */
.text-center {
  text-align: center;
}

.text-muted {
  color: var(--color-text-light);
}

.mt-1 {
  margin-top: 0.5rem;
}

.mt-2 {
  margin-top: 1rem;
}

.mb-1 {
  margin-bottom: 0.5rem;
}

.mb-2 {
  margin-bottom: 1rem;
}