/* NP Mail - Mobile-first PWA */

:root {
  --brown: #7B3F00;
  --brown-light: #a0622a;
  --brown-dark: #5a2e00;
  --bg: #f5f5f0;
  --white: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #999;
  --border: #e5e5e0;
  --border-light: #f0f0eb;
  --priority-high: #ef4444;
  --priority-sredni: #f59e0b;
  --priority-normalny: #94a3b8;
  --client-staly: #10b981;
  --ghost-bg: #f0e6ff;
  --cso-bg: #e6f4ff;
  --ceo-bg: #fff4e6;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  padding-top: var(--safe-top);
}

.hidden { display: none !important; }
.view { min-height: 100dvh; }

/* --- AUTH --- */

#view-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: linear-gradient(135deg, var(--brown-dark) 0%, var(--brown) 50%, var(--brown-light) 100%);
}

.auth-box {
  text-align: center;
  padding: 40px 32px;
  color: white;
}

.auth-logo {
  width: 80px;
  height: 80px;
  background: rgba(255,255,255,0.15);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, serif;
  font-size: 32px;
  font-weight: bold;
  color: white;
  margin: 0 auto 20px;
  backdrop-filter: blur(10px);
}

.auth-box h1 {
  font-family: Georgia, serif;
  font-size: 28px;
  font-weight: normal;
  margin-bottom: 4px;
}

.auth-subtitle {
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  margin-bottom: 40px;
}

.btn-faceid {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 16px 32px;
  border-radius: 14px;
  font-size: 17px;
  cursor: pointer;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  backdrop-filter: blur(10px);
  transition: background 0.2s;
}
.btn-faceid:active { background: rgba(255,255,255,0.25); }

.auth-status {
  margin-top: 20px;
  font-size: 14px;
  min-height: 20px;
}
.auth-status.error { color: #fca5a5; }
.auth-status.success { color: #86efac; }
.auth-status.info { color: rgba(255,255,255,0.8); }

.auth-box input[type="text"] {
  width: 100%;
  max-width: 280px;
  padding: 14px 16px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 16px;
  margin-bottom: 16px;
  text-align: center;
}
.auth-box input::placeholder { color: rgba(255,255,255,0.5); }

.btn-primary {
  background: white;
  color: var(--brown);
  border: none;
  padding: 14px 32px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  max-width: 280px;
}

/* --- TOPBAR --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-title {
  font-size: 20px;
  font-weight: 700;
}

.btn-icon {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--brown);
  border-radius: 8px;
}
.btn-icon:active { background: var(--border-light); }

.btn-refresh.spinning svg {
  animation: spin 0.5s ease;
}
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

.btn-back, .btn-reply, .btn-send {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 15px;
  border-radius: 8px;
}
.btn-back { color: var(--brown); }
.btn-reply { color: var(--brown); }
.btn-send {
  color: white;
  background: var(--brown);
  font-weight: 600;
  border-radius: 10px;
}
.btn-send:disabled { opacity: 0.5; }

/* --- ACCOUNT TABS --- */

.account-tabs {
  display: flex;
  padding: 8px 16px;
  gap: 8px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.tab.active {
  background: var(--brown);
  color: white;
  border-color: var(--brown);
}

/* --- EMAIL LIST --- */

.email-list {
  padding-bottom: calc(70px + var(--safe-bottom));
}

.email-item {
  display: flex;
  gap: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  background: var(--white);
  transition: background 0.15s;
}
.email-item:active { background: var(--bg); }
.email-item.unread { background: #fefcf8; }
.email-item.unread .email-from { font-weight: 700; }
.email-item.unread .email-subject { font-weight: 600; }

.email-priority {
  width: 4px;
  border-radius: 2px;
  margin-right: 12px;
  flex-shrink: 0;
}
.priority-wysoki { background: var(--priority-high); }
.priority-sredni, .priority-normalny { background: transparent; }

.email-content { flex: 1; min-width: 0; }

.email-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}

.email-from {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
}

.email-time {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.email-subject {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.email-snippet {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-badges {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-client { background: #dcfce7; color: #166534; }
.badge-account {
  background: var(--border-light);
  color: var(--text-muted);
  font-size: 10px;
}

/* --- EMAIL DETAIL --- */

.email-detail {
  padding: 16px;
  padding-bottom: 0;
}

.email-full-header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.email-full-from { font-size: 17px; font-weight: 600; }
.email-full-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.email-full-to { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.email-full-subject { font-size: 18px; font-weight: 600; margin-top: 8px; }

.email-full-body {
  font-size: 15px;
  line-height: 1.6;
  overflow-wrap: break-word;
}
.email-full-body img { max-width: 100%; height: auto; }

/* --- AI PANEL --- */

.ai-panel {
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

.ai-section h3 {
  font-size: 15px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.ai-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.btn-ai {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--white);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ai:disabled { opacity: 0.5; }
.btn-ghost { color: #7c3aed; }
.btn-ghost:active { background: var(--ghost-bg); }
.btn-cso { color: #0284c7; }
.btn-cso:active { background: var(--cso-bg); }
.btn-ceo { color: #d97706; }
.btn-ceo:active { background: var(--ceo-bg); }

.ai-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
}
.btn-ghost .ai-icon { background: #7c3aed; }
.btn-cso .ai-icon { background: #0284c7; }
.btn-ceo .ai-icon { background: #d97706; }

.ai-response {
  border-radius: 12px;
  padding: 16px;
  margin-top: 8px;
}
.ai-ghost { background: var(--ghost-bg); }
.ai-cso { background: var(--cso-bg); }
.ai-ceo { background: var(--ceo-bg); }

.ai-response-header {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  opacity: 0.7;
}

.ai-response-body {
  font-size: 15px;
  line-height: 1.6;
}

.ai-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn-secondary {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  font-size: 13px;
  cursor: pointer;
}

/* --- COMPOSE --- */

.compose-form {
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

.compose-field {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-light);
  padding: 8px 0;
}
.compose-field label {
  width: 48px;
  font-size: 14px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.compose-field input, .compose-field select {
  flex: 1;
  border: none;
  font-size: 15px;
  padding: 8px 4px;
  background: transparent;
  outline: none;
}
.compose-field select {
  color: var(--brown);
  font-weight: 500;
}

#compose-body {
  width: 100%;
  border: none;
  font-size: 15px;
  line-height: 1.6;
  padding: 16px 0;
  outline: none;
  resize: none;
  min-height: 200px;
  font-family: inherit;
}

/* --- BOTTOM NAV --- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 8px 0;
  padding-bottom: calc(8px + var(--safe-bottom));
  z-index: 200;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  transition: color 0.2s;
}
.nav-item.active { color: var(--brown); }
.nav-item:active { opacity: 0.7; }

/* --- UTILS --- */

.loading {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-secondary);
  font-size: 15px;
}

.error {
  text-align: center;
  padding: 20px 16px;
  color: var(--priority-high);
  font-size: 14px;
}

.empty {
  text-align: center;
  padding: 60px 16px;
  color: var(--text-muted);
  font-size: 15px;
}

.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  transition: transform 0.3s ease;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast-success { background: #166534; color: white; }
.toast-error { background: #991b1b; color: white; }

/* --- PRINT HIDE --- */
@media print { .bottom-nav, .topbar { display: none; } }
