/* CSS Variables */
:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-tertiary: #1a1a1a;
  --bg-card: #1e1e1e;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #d4a574;
  --accent-light: #e6c9a8;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --border: #2a2a2a;
  --nav-height: 80px;
  --header-height: 60px;
  --safe-area-top: env(safe-area-inset-top);
  --safe-area-bottom: env(safe-area-inset-bottom);
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
}

/* Header */
.app-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-title {
  font-size: 24px;
  font-weight: 700;
}

.header-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}

.header-btn:active {
  transform: scale(0.95);
  background: var(--accent-light);
}

.header-btn svg {
  width: 20px;
  height: 20px;
  color: var(--bg-primary);
}

/* Main Content */
.app-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
  flex-direction: column;
}

.view.active {
  display: flex;
}

/* Search Bar */
.search-bar {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.search-bar svg {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-bar input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

/* Conversation List */
.conversation-list,
.call-list,
.contact-list {
  flex: 1;
  padding: 8px 0;
}

.conversation-item,
.call-item,
.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.conversation-item:active,
.call-item:active,
.contact-item:active {
  background: var(--bg-secondary);
}

.avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.conversation-info,
.call-info,
.contact-info {
  flex: 1;
  min-width: 0;
}

.conversation-name,
.call-name,
.contact-name {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-preview {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-meta,
.call-meta {
  text-align: right;
  flex-shrink: 0;
}

.conversation-time,
.call-time {
  font-size: 12px;
  color: var(--text-muted);
}

.unread-badge {
  background: var(--accent);
  color: var(--bg-primary);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 4px;
  display: inline-block;
}

/* Call specific */
.call-type {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.call-type svg {
  width: 14px;
  height: 14px;
}

.call-type.incoming svg {
  color: var(--success);
}

.call-type.outgoing svg {
  color: var(--accent);
}

.call-type.missed svg {
  color: var(--danger);
}

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

/* Contact specific */
.contact-phone {
  font-size: 14px;
  color: var(--text-secondary);
}

.contact-status {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.contact-status.hot {
  background: rgba(248, 113, 113, 0.2);
  color: var(--danger);
}

.contact-status.new {
  background: rgba(212, 165, 116, 0.2);
  color: var(--accent);
}

/* Empty State */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state p {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 8px;
}

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

/* Dashboard */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  padding-bottom: 8px;
}

.dashboard-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.logout-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--bg-secondary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.logout-btn:active {
  background: var(--bg-tertiary);
}

.logout-btn svg {
  width: 20px;
  height: 20px;
  color: var(--text-secondary);
}

.dashboard-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.recent-activity {
  padding: 0 16px 16px;
}

.recent-activity h3 {
  font-size: 18px;
  margin-bottom: 12px;
}

.activity-list {
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
}

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

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

.activity-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.activity-icon svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.activity-text {
  flex: 1;
  font-size: 14px;
}

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

/* Bottom Navigation */
.app-nav {
  height: var(--nav-height);
  padding-bottom: var(--safe-area-bottom);
  display: flex;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s;
  padding: 8px 0;
}

.nav-item svg {
  width: 24px;
  height: 24px;
}

.nav-item span {
  font-size: 11px;
  font-weight: 500;
}

.nav-item.active {
  color: var(--accent);
}

/* Detail Overlays */
.conversation-detail,
.contact-detail {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
}

.conversation-detail.active,
.contact-detail.active {
  transform: translateX(0);
}

.detail-header {
  height: var(--header-height);
  padding: 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-btn,
.call-btn,
.edit-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.2s;
}

.back-btn:active,
.edit-btn:active {
  background: var(--bg-secondary);
}

.call-btn {
  background: var(--success);
  color: var(--bg-primary);
}

.call-btn:active {
  background: #22c55e;
}

.back-btn svg,
.call-btn svg,
.edit-btn svg {
  width: 24px;
  height: 24px;
}

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

.detail-info h2 {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-info small {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
}

.message.received {
  background: var(--bg-tertiary);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.message.sent {
  background: var(--accent);
  color: var(--bg-primary);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

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

/* Message Input */
.message-input {
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.message-input input {
  flex: 1;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 24px;
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
}

.message-input input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}

.send-btn:active {
  transform: scale(0.95);
  background: var(--accent-light);
}

.send-btn svg {
  width: 20px;
  height: 20px;
  color: var(--bg-primary);
}

/* Contact Content */
.contact-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

.contact-section {
  margin-bottom: 24px;
}

.contact-section h3 {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.contact-field {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.contact-field:last-child {
  border-bottom: none;
}

.contact-field-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.contact-field-value {
  font-size: 16px;
}

.contact-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.contact-action-btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.2s, background 0.2s;
}

.contact-action-btn:active {
  transform: scale(0.98);
}

.contact-action-btn.primary {
  background: var(--accent);
  color: var(--bg-primary);
}

.contact-action-btn.secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.contact-action-btn svg {
  width: 20px;
  height: 20px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 20px + var(--safe-area-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Loading Spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Login Screen */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
}

.login-screen.hidden {
  display: none;
}

.login-container {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.login-logo {
  margin-bottom: 24px;
}

.logo-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  margin: 0 auto;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

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

.pin-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: all 0.15s;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.pin-dot.error {
  border-color: var(--danger);
  background: var(--danger);
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.pin-error {
  height: 20px;
  font-size: 13px;
  color: var(--danger);
  margin-bottom: 24px;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 280px;
  margin: 0 auto;
}

.pin-btn {
  width: 72px;
  height: 72px;
  border: none;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 28px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s, background 0.2s;
  margin: 0 auto;
}

.pin-btn:active {
  transform: scale(0.95);
  background: var(--bg-tertiary);
}

.pin-btn.empty {
  background: transparent;
  cursor: default;
}

.pin-btn.empty:active {
  transform: none;
}

.pin-btn.delete {
  background: transparent;
}

.pin-btn.delete svg {
  width: 28px;
  height: 28px;
}

.pin-btn.delete:active {
  background: var(--bg-secondary);
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 4px;
}

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

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