@font-face {
  font-family: 'Diwani';
  src: local('Traditional Arabic'), local('Scheherazade New'), local('Amiri');
}

:root {
  --bg-primary: #1a1105;
  --bg-secondary: #0d0a02;
  --bg-surface: #2a1f0f;
  --bg-surface-hover: #3a2f1f;
  --bg-input: #1e1508;
  --gold: #d4a843;
  --gold-light: #e8c97a;
  --gold-dark: #a67c2e;
  --teal: #1a3a3a;
  --teal-light: #2a5a5a;
  --teal-dark: #0f2b2b;
  --warm-red: #6b1a00;
  --warm-red-light: #8b2500;
  --parchment: #f5e6c8;
  --text-primary: #f5e6c8;
  --text-secondary: #c4b59a;
  --text-muted: #8a7a60;
  --border: #3a2f1f;
  --border-gold: #a67c2e;
  --shadow: rgba(0,0,0,0.6);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s ease;
  --font-primary: 'Amiri', 'Traditional Arabic', serif;
  --font-display: 'Scheherazade New', 'Amiri', 'Traditional Arabic', serif;
  --font-body: 'Amiri', 'Traditional Arabic', serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    repeating-linear-gradient(
      45deg,
      transparent 0px,
      transparent 40px,
      rgba(212, 168, 67, 0.015) 40px,
      rgba(212, 168, 67, 0.015) 41px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent 0px,
      transparent 40px,
      rgba(212, 168, 67, 0.015) 40px,
      rgba(212, 168, 67, 0.015) 41px
    );
  pointer-events: none;
  z-index: 0;
}

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

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
  border: none;
  outline: none;
  background: none;
}

button {
  cursor: pointer;
}

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--gold-dark);
  border-radius: 2px;
}

#app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.page {
  display: none;
  flex-direction: column;
  height: 100%;
  animation: fadeIn 0.3s ease;
}

.page.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.islamic-border {
  position: relative;
}

.islamic-border::before,
.islamic-border::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: repeating-linear-gradient(
    90deg,
    var(--gold) 0px,
    var(--gold) 8px,
    transparent 8px,
    transparent 12px,
    var(--gold-dark) 12px,
    var(--gold-dark) 16px,
    transparent 16px,
    transparent 20px
  );
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold-dark), var(--gold));
  color: var(--bg-primary);
  border: 1px solid var(--gold);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  box-shadow: 0 4px 20px rgba(212, 168, 67, 0.3);
}

.btn-primary:active {
  transform: scale(0.97);
}

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

.btn-secondary:hover {
  background: rgba(212, 168, 67, 0.1);
  border-color: var(--gold);
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-size: 18px;
  transition: all var(--transition);
}

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

.btn-danger {
  background: linear-gradient(135deg, var(--warm-red), var(--warm-red-light));
  color: var(--text-primary);
  border: 1px solid var(--warm-red-light);
}

.ornate-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.ornate-separator::before,
.ornate-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dark), transparent);
}

.ornate-separator span {
  color: var(--gold-dark);
  font-size: 20px;
  font-family: var(--font-display);
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
}

.input-field {
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  font-family: var(--font-body);
  transition: border-color var(--transition);
}

.input-field:focus {
  border-color: var(--gold-dark);
  box-shadow: 0 0 0 1px rgba(212, 168, 67, 0.2);
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--gold-dark);
  background: var(--bg-surface);
}

.avatar-lg {
  width: 80px;
  height: 80px;
}

.avatar-sm {
  width: 36px;
  height: 36px;
}

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

.badge-online {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-offline {
  background: rgba(100, 100, 100, 0.15);
  color: #666;
  border: 1px solid rgba(100, 100, 100, 0.3);
}

.badge-call {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

#toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-gold);
  color: var(--text-primary);
  font-size: 14px;
  animation: slideUp 0.3s ease, fadeOut 0.3s ease forwards;
  animation-delay: 0s, 2.5s;
  pointer-events: all;
  box-shadow: 0 4px 20px var(--shadow);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 40px;
}

.loading-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }
.loading-dot:nth-child(3) { }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

@media (max-width: 480px) {
  .btn { padding: 10px 20px; font-size: 14px; }
  .card { padding: 14px; }
}

@media (min-width: 768px) {
  #app { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

.setup-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
  gap: 24px;
}

.setup-header {
  text-align: center;
}

.setup-logo {
  font-size: 48px;
  margin-bottom: 8px;
  color: var(--gold);
}

.setup-title {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 700;
  color: var(--gold);
}

.setup-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.setup-form {
  width: 100%;
  max-width: 360px;
}

.avatar-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.avatar-upload-text {
  font-size: 12px;
  color: var(--gold-dark);
}

.terms-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
}

.terms-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.setup-btn {
  margin-top: 8px;
}

.setup-footer {
  text-align: center;
}

.contacts-header {
  padding: 12px 16px;
  background: var(--bg-secondary);
}

.contacts-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.contacts-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
}

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

.contact-item:active {
  background: var(--bg-surface-hover);
}

.contact-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.contact-name {
  font-weight: 700;
  font-size: 15px;
}

.contact-username {
  font-size: 12px;
  color: var(--text-muted);
  direction: ltr;
  unicode-bidi: plaintext;
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-secondary);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.6;
  position: relative;
  word-break: break-word;
}

.msg-in {
  align-self: flex-start;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top-right-radius: 4px;
}

.msg-out {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--gold-dark), var(--gold));
  color: var(--bg-primary);
  border-top-left-radius: 4px;
}

.msg-time {
  display: block;
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.7;
  text-align: left;
  direction: ltr;
}

.msg-status {
  font-size: 11px;
  margin-right: 4px;
}

.msg-image {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin-bottom: 4px;
}

.msg-file-name {
  font-size: 12px;
  opacity: 0.8;
}

.msg-file-link {
  color: inherit;
  text-decoration: underline;
}

.chat-date-separator {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 0;
  position: relative;
}

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.call-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: linear-gradient(180deg, #0d0a02 0%, #1a1105 50%, #0d0a02 100%);
}

.call-header {
  position: relative;
  padding: 8px;
  min-height: 48px;
}

.call-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.call-avatar-container {
  position: relative;
}

.call-avatar-container .avatar {
  border-width: 3px;
  box-shadow: 0 0 30px rgba(212, 168, 67, 0.2);
}

.call-waiting {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.call-active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.call-audio-indicator {
  width: 100%;
  text-align: center;
}

.audio-level-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}

.audio-level-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dark), var(--gold));
  border-radius: 2px;
  transition: width 0.1s ease;
}

.call-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px;
}

.call-control-btn {
  width: 56px;
  height: 56px;
  font-size: 22px;
  background: var(--bg-surface);
  border-color: var(--border);
}

.call-control-btn:hover {
  background: var(--bg-surface-hover);
}

.call-end-btn {
  width: 64px;
  height: 64px;
  background: var(--warm-red) !important;
  border-color: var(--warm-red-light) !important;
  color: white !important;
}

.call-end-btn:hover {
  background: var(--warm-red-light) !important;
}

.muted {
  opacity: 0.5;
}

.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--gold);
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
}
