/* ============================================
   打卡助手 - 精美行動端樣式
   ============================================ */

:root {
  --primary: #4F46E5;
  --primary-light: #818CF8;
  --primary-dark: #3730A3;
  --primary-bg: #EEF2FF;
  --success: #10B981;
  --success-bg: #D1FAE5;
  --warning: #F59E0B;
  --warning-bg: #FEF3C7;
  --danger: #EF4444;
  --danger-bg: #FEE2E2;
  --info: #3B82F6;
  --info-bg: #DBEAFE;

  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-2: #475569;
  --text-3: #94A3B8;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.08);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;

  --nav-height: 64px;
  --header-height: 64px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F172A;
    --surface: #1E293B;
    --surface-2: #334155;
    --border: #334155;
    --text: #F1F5F9;
    --text-2: #94A3B8;
    --text-3: #64748B;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --primary-bg: #1E1B4B;
    --success-bg: #064E3B;
    --warning-bg: #78350F;
    --danger-bg: #7F1D1D;
    --info-bg: #1E3A5F;
  }
}

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Noto Sans CJK', 'Microsoft JhengHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  min-height: 100dvh;
}

#app {
  min-height: 100dvh;
}

/* ── Page Container ── */
.page-container {
  padding-bottom: calc(var(--nav-height) + 16px);
  min-height: 100dvh;
}

/* ── Header ── */
.page-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

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

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  flex-shrink: 0;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.greeting {
  font-size: 16px;
  font-weight: 600;
}

.user-shift {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 1px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--surface-2);
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:active {
  transform: scale(0.9);
}

/* ── Login Page ── */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #EEF2FF 0%, #F8FAFC 50%, #F0FDF4 100%);
}

@media (prefers-color-scheme: dark) {
  .login-page {
    background: linear-gradient(160deg, #1E1B4B 0%, #0F172A 50%, #064E3B 100%);
  }
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 40px 28px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 380px;
  width: 100%;
  animation: slideUp 0.5s ease;
}

.login-icon {
  font-size: 64px;
  margin-bottom: 8px;
}

.login-title {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

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

.login-features {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 32px;
  text-align: left;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-2);
}

.feature-icon {
  font-size: 20px;
  width: 28px;
  text-align: center;
}

.login-note {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 16px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  letter-spacing: 0.3px;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}

.btn-outline:active {
  background: var(--surface-2);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-google {
  width: 100%;
  background: white;
  border: 1.5px solid var(--border);
  color: var(--text);
  font-size: 16px;
  padding: 14px 20px;
  box-shadow: var(--shadow-sm);
}

.btn-google:hover {
  background: var(--surface-2);
}

.btn-small {
  padding: 10px 16px;
  font-size: 13px;
}

/* ── Dashboard Body ── */
.dashboard-body {
  padding: 16px;
}

/* Punch Section */
.punch-section {
  margin-bottom: 20px;
}

.btn-punch {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  width: 100%;
}

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

.btn-punch-primary {
  background: linear-gradient(135deg, var(--primary), #7C3AED);
  color: white;
  padding: 28px 20px;
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px rgba(79, 70, 229, 0.3);
  margin-bottom: 12px;
}

.btn-punch-primary .btn-punch-icon {
  font-size: 36px;
}

.btn-punch-primary .btn-punch-label {
  font-size: 18px;
  font-weight: 700;
}

.punch-secondary-row {
  display: flex;
  gap: 12px;
}

.btn-punch-secondary {
  flex: 1;
  background: var(--surface);
  padding: 16px 12px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.btn-punch-secondary .btn-punch-icon {
  font-size: 24px;
}

.btn-punch-secondary .btn-punch-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

/* Status Card */
.status-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 32px 20px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.status-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.status-text {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.status-sub {
  font-size: 13px;
  color: var(--text-3);
}

/* Active Punch Card */
.punch-active-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
  margin-bottom: 16px;
  animation: slideUp 0.3s ease;
}

.active-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.active-badge {
  background: var(--warning-bg);
  color: #92400E;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  .active-badge {
    color: #FDE68A;
  }
}

.active-shift {
  font-size: 13px;
  color: var(--text-3);
}

.active-time-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 20px;
}

.time-block {
  text-align: center;
  flex: 1;
}

.time-label {
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 4px;
}

.time-value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.time-arrow {
  font-size: 14px;
  color: var(--text-3);
  flex-shrink: 0;
}

/* Progress */
.progress-section {
  margin-bottom: 20px;
}

.progress-bar-container {
  height: 10px;
  background: var(--surface-2);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: 5px;
  transition: width 0.5s ease;
}

.progress-text {
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 1px;
}

.progress-quote {
  font-size: 13px;
  color: var(--text-3);
  text-align: center;
  margin-top: 4px;
  font-style: italic;
}

.active-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.active-actions .btn {
  flex: 1;
}

.extend-section {
  text-align: center;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.extend-label {
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 8px;
}

.extend-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ── Push Section ── */
.push-section {
  margin-bottom: 16px;
}

/* ── Daily Tip ── */
.daily-tip {
  background: var(--info-bg);
  color: #1E40AF;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  .daily-tip {
    color: #93C5FD;
  }
}

/* ── Dialog Card ── */
.dialog-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
  margin: 16px;
  animation: slideUp 0.3s ease;
}

.dialog-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.dialog-card h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.dialog-card p {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 24px;
}

.dialog-actions {
  display: flex;
  gap: 12px;
}

.dialog-actions .btn {
  flex: 1;
}

.input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}

.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
  min-height: 80px;
}

.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* ── History ── */
.history-body {
  padding: 16px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.history-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.history-index {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 2px 8px;
  border-radius: 4px;
}

.history-date {
  font-size: 13px;
  font-weight: 600;
}

.history-shift {
  font-size: 12px;
  color: var(--text-3);
  margin-left: auto;
}

.history-status {
  font-size: 13px;
  line-height: 1.5;
  padding: 4px 0;
  white-space: pre-line;
}

.history-status.active {
  color: var(--warning);
}

.history-status.done {
  color: var(--success);
}

.history-status.overwritten {
  color: var(--text-3);
}

.btn-delete {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.btn-delete:active {
  opacity: 1;
  background: var(--danger-bg);
}

/* Stats */
.stats-section {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-top: 16px;
  box-shadow: var(--shadow-sm);
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.stat-item + .stat-item {
  border-top: 1px solid var(--border);
}

.stat-label {
  font-size: 14px;
  color: var(--text-2);
}

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

/* ── Settings ── */
.settings-body {
  padding: 16px;
}

.settings-section {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}

.setting-item {
  margin-bottom: 12px;
}

.setting-label {
  font-size: 14px;
  font-weight: 600;
}

.setting-desc {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
  line-height: 1.5;
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
  min-width: calc(50% - 4px);
  justify-content: center;
  user-select: none;
}

.radio-item:active {
  transform: scale(0.97);
}

.radio-item.checked {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

.detect-result {
  margin-top: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
}

.detect-result.success {
  background: var(--success-bg);
  color: #065F46;
}

.detect-result.info {
  background: var(--info-bg);
  color: #1E40AF;
}

@media (prefers-color-scheme: dark) {
  .detect-result.success { color: #6EE7B7; }
  .detect-result.info { color: #93C5FD; }
}

/* ── Messages ── */
.messages-body {
  padding: 16px;
}

.message-compose {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.message-compose .btn {
  width: 100%;
  margin-top: 12px;
}

.message-info {
  margin-bottom: 16px;
}

.info-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--info-bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 13px;
  color: #1E40AF;
  line-height: 1.5;
}

.info-icon {
  font-size: 24px;
  flex-shrink: 0;
}

@media (prefers-color-scheme: dark) {
  .info-card { color: #93C5FD; }
}

/* Admin Messages */
.admin-messages-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.message-card.replied {
  border-left: 3px solid var(--success);
}

.msg-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.msg-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.msg-avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}

.msg-user-name {
  font-size: 14px;
  font-weight: 600;
}

.msg-user-email {
  font-size: 11px;
  color: var(--text-3);
}

.msg-time {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}

.msg-content {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-line;
}

.msg-reply {
  margin-top: 12px;
  padding: 12px;
  background: var(--success-bg);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
}

.reply-label {
  font-size: 12px;
  font-weight: 600;
  color: #065F46;
  margin-bottom: 4px;
}

@media (prefers-color-scheme: dark) {
  .reply-label { color: #6EE7B7; }
}

.msg-reply-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.msg-reply-form .textarea {
  flex: 1;
  min-height: 40px;
  font-size: 13px;
  padding: 10px 12px;
}

.msg-reply-form .btn {
  flex-shrink: 0;
}

/* ── Admin ── */
.admin-body {
  padding: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 20px 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-number {
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}

.time-controls {
  margin-top: 12px;
}

/* ── Bottom Navigation ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 100;
  box-shadow: 0 -1px 8px rgba(0,0,0,0.04);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-3);
  padding: 6px 12px;
  border-radius: 12px;
  transition: all 0.2s;
  position: relative;
}

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

.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 3px 3px;
}

.nav-icon {
  font-size: 22px;
  line-height: 1;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
}

/* ── Loading Spinner ── */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 20px;
  color: var(--text-3);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

/* ── Empty / Error States ── */
.empty-state, .error-state {
  text-align: center;
  padding: 64px 20px;
  font-size: 16px;
  color: var(--text-3);
}

.error-state {
  color: var(--danger);
}

/* ── Toast ── */
#toast-container {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 1000;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  color: var(--text);
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  pointer-events: auto;
  transform: translateY(-20px);
  opacity: 0;
  transition: all 0.3s ease;
  border: 1px solid var(--border);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-success {
  border-left: 4px solid var(--success);
}

.toast-error {
  border-left: 4px solid var(--danger);
}

.toast-info {
  border-left: 4px solid var(--info);
}

/* ── Animations ── */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* ── Safe Area for notched devices ── */
@supports (padding-top: env(safe-area-inset-top)) {
  .page-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }
}
