/* ==========================================================================
   V2.0 登入遮罩與帳號控制 (Login Overlay & Auth UI)
   ========================================================================== */

/* 登入全屏遮罩 */
.login-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: var(--bg-dark-base);
  background-image:
    radial-gradient(circle at 20% 30%, var(--body-bg-a) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, var(--body-bg-b) 0%, transparent 50%);
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.login-overlay.active {
  display: flex;
  opacity: 1;
}

.login-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* 登入卡片 */
.login-card {
  background: var(--bg-card-glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass-glow);
  border-radius: var(--radius-lg);
  padding: 48px 44px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow:
    0 0 60px rgba(99, 102, 241, 0.15),
    var(--shadow-card);
  text-align: center;
  animation: loginCardEntry 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes loginCardEntry {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* 鎖頭 LOGO */
.login-logo {
  font-size: 52px;
  margin-bottom: 8px;
  animation: loginLogoPulse 2.5s ease-in-out infinite;
}

@keyframes loginLogoPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.login-title {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-heading);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.login-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

/* 登入表單欄位 */
.login-form-group {
  text-align: left;
  margin-bottom: 18px;
}

.login-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.login-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input-deep);
  border: 1.5px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 1rem;
  font-family: var(--font-family);
  outline: none;
  transition: all 0.22s ease;
}

.login-input:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
}

.login-input::placeholder {
  color: var(--text-subtle);
}

/* 記住我 Checkbox */
.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  margin-top: 2px;
}

.login-remember input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-color);
  cursor: pointer;
  flex-shrink: 0;
}

.login-remember label {
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

/* 登入按鈕 */
.login-btn {
  width: 100%;
  padding: 14px 24px;
  background: var(--gradient-accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.35);
  letter-spacing: 0.02em;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

.login-btn:active {
  transform: translateY(0);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* 登入錯誤訊息 */
.login-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 0.88rem;
  font-weight: 600;
  animation: shakeError 0.4s ease;
}

.login-error.hidden {
  display: none;
}

@keyframes shakeError {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* --------------------------------------------------------------------------
   V2.0 離線選擇彈窗 (Offline Choice Dialog)
   -------------------------------------------------------------------------- */
.offline-dialog-backdrop {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 100001;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.25s ease forwards;
}

.offline-dialog-card {
  background: var(--bg-dark-surface);
  border: 1px solid var(--border-glass-glow);
  border-radius: var(--radius-md);
  padding: 36px 40px;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 50px rgba(245, 158, 11, 0.15), var(--shadow-card);
}

.offline-dialog-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.offline-dialog-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-heading);
  margin-bottom: 10px;
}

.offline-dialog-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 24px;
}

.offline-dialog-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.offline-btn-retry,
.offline-btn-offline {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.22s ease;
}

.offline-btn-retry {
  background: var(--gradient-accent);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.offline-btn-retry:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.offline-btn-offline {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.offline-btn-offline:hover {
  background: rgba(245, 158, 11, 0.35);
  transform: translateY(-2px);
}

/* --------------------------------------------------------------------------
   V2.4 右欄雙頁籤切換 (Right Column Tabs & Attachments Panel)
   -------------------------------------------------------------------------- */
.crm-right-tabs-bar {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-card-light);
  margin-bottom: 12px;
  padding-bottom: 6px;
}

.crm-right-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
}

.crm-right-tab-btn:hover {
  color: var(--text-heading);
  background: rgba(255, 255, 255, 0.04);
}

.crm-right-tab-btn.active {
  color: var(--primary-light);
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.35);
  font-weight: 700;
}

.crm-right-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.timeline-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  margin-bottom: 12px;
  padding-bottom: 2px;
}

.attachments-grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  grid-auto-rows: min-content;
  align-content: start;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  padding-top: 2px;
}

.crm-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  border-bottom: 2px solid transparent;
  -webkit-user-select: none;
  user-select: none;
}

.crm-tab-btn:hover {
  color: var(--text-heading);
  background: rgba(255, 255, 255, 0.04);
}

.crm-tab-btn.active {
  color: var(--primary-light);
  background: var(--bg-card-glass);
  border-bottom-color: var(--primary-light);
  font-weight: 700;
}

.crm-tab-badge {
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary-light);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 10px;
}

.crm-tab-panel {
  display: flex;
  flex: 1;
}

.crm-tab-panel.hidden {
  display: none !important;
}

.attachment-input-grid {
  display: grid;
  grid-template-columns: 1fr 1.5fr auto;
  gap: 10px;
  align-items: center;
}

.attachment-card {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-height: 82px;
  min-width: 0;
  box-sizing: border-box;
  transition: all 0.2s ease;
}

.attachment-card:hover {
  border-color: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.15);
}

.attachment-card.is-draft {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.06);
}

.attachment-card-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.attachment-icon {
  font-size: 1.15rem;
  flex-shrink: 0;
  line-height: 1.25;
}

.attachment-title-link {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-heading);
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
  word-break: break-all;
  line-height: 1.4;
  max-height: 2.8em;
  transition: color 0.15s ease;
  min-width: 0;
}

.attachment-title-link:hover {
  color: #60a5fa;
  text-decoration: underline;
}

.attachment-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 26px;
  min-width: 0;
  margin-top: auto;
  padding-top: 2px;
}

.attachment-card-status {
  display: flex;
  align-items: center;
  min-width: 0;
}

.attachment-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}

