/* ===========================
   PivoTime - Design System
   CSS Variables & Base
   =========================== */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&family=DM+Sans:wght@400;500;700&display=swap');

:root {
  /* Brand Colors */
  --brand:        #00C48C;
  --brand-dark:   #00A876;
  --brand-light:  #E6FAF5;
  --accent:       #FF6B6B;
  --accent-warm:  #FFB347;

  /* Neutral */
  --bg:           #F6F8FA;
  --surface:      #FFFFFF;
  --surface2:     #F0F2F5;
  --border:       #E4E8ED;
  --text:         #1A1D23;
  --text-sub:     #6B7280;
  --text-light:   #9CA3AF;

  /* Status */
  --status-in:    #00C48C;
  --status-out:   #6B7280;
  --status-none:  #D1D5DB;
  --status-warn:  #F59E0B;
  --status-error: #EF4444;

  /* Spacing */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  32px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  /* Shadow */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.14);

  /* Font */
  --font-main: 'DM Sans', 'Noto Sans JP', sans-serif;

  /* Nav */
  --nav-h:    64px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  overflow-x: hidden;
}

button {
  cursor: pointer;
  border: none;
  font-family: var(--font-main);
  transition: all 0.18s ease;
}

input, select, textarea {
  font-family: var(--font-main);
  font-size: 16px; /* prevent zoom on iOS */
}

/* ===== App Shell ===== */
#app {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  padding-bottom: calc(var(--nav-h) + 16px);
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
}

/* ===== Page Header ===== */
.page-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  padding: var(--space-md) var(--space-md);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

.page-back-btn {
  background: none;
  color: var(--brand);
  font-size: 15px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

/* ===== Login Screen ===== */
#screen-login {
  padding-bottom: 0;
  justify-content: center;
  align-items: center;
  background: linear-gradient(160deg, #00C48C 0%, #00897B 100%);
  min-height: 100vh;
}

.login-box {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--space-xl) var(--space-lg);
  width: calc(100% - 32px);
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.login-logo-icon {
  font-size: 48px;
  display: block;
  margin-bottom: var(--space-sm);
}

.login-logo h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.5px;
}

.login-logo p {
  font-size: 13px;
  color: var(--text-sub);
  margin-top: 4px;
}

.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--brand);
  background: var(--surface);
}

.btn-primary {
  width: 100%;
  padding: 15px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: none;
  margin-top: var(--space-sm);
  letter-spacing: 0.3px;
}

.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { background: var(--text-light); cursor: not-allowed; }

.btn-secondary {
  padding: 10px 20px;
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-md);
}

.btn-small {
  padding: 6px 12px;
  background: var(--brand-light);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--brand);
}

/* ===== Bottom Navigation ===== */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: none;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-sub);
  font-size: 10px;
  font-weight: 600;
  min-width: 56px;
  transition: color 0.2s;
}

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

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

/* ===== Home Screen ===== */
.home-hero {
  background: linear-gradient(135deg, #00C48C 0%, #00897B 100%);
  padding: var(--space-lg) var(--space-md);
  color: #fff;
}

.home-greeting {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
}

.home-date {
  font-size: 13px;
  opacity: 0.85;
}

.home-content {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-md);
}

.status-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-none { background: var(--status-none); }
.dot-in   { background: var(--status-in); box-shadow: 0 0 0 3px rgba(0,196,140,0.3); animation: pulse 2s infinite; }
.dot-out  { background: var(--status-out); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(0,196,140,0.3); }
  50%       { box-shadow: 0 0 0 6px rgba(0,196,140,0.15); }
}

.status-text {
  font-size: 16px;
  font-weight: 700;
}

.time-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-sm);
}

.time-cell {
  text-align: center;
}

.time-label {
  font-size: 11px;
  color: var(--text-sub);
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}

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

.next-shift-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.next-shift-icon {
  font-size: 32px;
}

.next-shift-info {
  flex: 1;
}

.next-shift-label {
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 600;
}

.next-shift-time {
  font-size: 16px;
  font-weight: 700;
  margin-top: 2px;
}

/* ===== Punch Screen ===== */
.punch-hero {
  background: var(--surface);
  padding: var(--space-lg) var(--space-md) var(--space-md);
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.punch-clock {
  font-size: 52px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: -2px;
  line-height: 1;
}

.punch-clock-sub {
  font-size: 13px;
  color: var(--text-sub);
  margin-top: 4px;
}

.status-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 700;
  margin-top: var(--space-sm);
}

.badge-none { background: var(--surface2); color: var(--text-sub); }
.badge-in   { background: var(--brand-light); color: var(--brand-dark); }
.badge-out  { background: #F3F4F6; color: var(--text-sub); }

.punch-content {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.punch-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}

.punch-btn {
  padding: 28px 16px;
  border-radius: var(--radius-lg);
  font-size: 18px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-md);
}

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

.punch-btn-in {
  background: var(--brand);
  color: #fff;
}

.punch-btn-in:hover  { background: var(--brand-dark); }
.punch-btn-in:active { transform: scale(0.96); }

.punch-btn-out {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
}

.punch-btn-out:hover  { background: var(--surface2); }
.punch-btn-out:active { transform: scale(0.96); }
.punch-btn-out:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.punch-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.gps-status {
  display: none;
  text-align: center;
  font-size: 14px;
  color: var(--text-sub);
  padding: var(--space-sm);
  background: var(--surface2);
  border-radius: var(--radius-md);
}

.punch-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-sm);
  text-align: center;
}

.punch-detail-cell {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-sm);
  box-shadow: var(--shadow-sm);
}

.punch-detail-label {
  font-size: 11px;
  color: var(--text-sub);
  font-weight: 600;
  margin-bottom: 4px;
}

.punch-detail-value {
  font-size: 20px;
  font-weight: 700;
}

/* ===== Shift Calendar ===== */
.shift-content {
  padding: var(--space-md);
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.cal-nav-btn {
  background: var(--surface2);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 8px 16px;
  font-size: 18px;
}

.cal-month-title {
  font-size: 17px;
  font-weight: 700;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-header {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-sub);
  padding: 8px 0;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  font-size: 13px;
  font-weight: 500;
}

.cal-day:not(.empty):hover { background: var(--surface2); }
.cal-day.cal-today { background: var(--brand-light); color: var(--brand-dark); font-weight: 700; }
.cal-day.cal-has-shift.shift-confirmed { background: var(--brand); color: #fff; }
.cal-day.cal-has-shift.shift-draft { background: var(--brand-light); color: var(--brand-dark); }
.cal-day.empty { cursor: default; }

.cal-day-num { font-size: 13px; line-height: 1; }
.cal-shift-badge { font-size: 9px; margin-top: 2px; opacity: 0.9; }

/* ===== Payslip ===== */
.payslip-content {
  padding: var(--space-md);
}

.payslip-ytd {
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 600;
  margin-bottom: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--surface);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--brand);
}

.payslip-ytd.ytd-warning {
  border-left-color: var(--accent);
  color: var(--accent);
}

.payslip-item {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.payslip-item:hover { background: var(--surface2); }

.payslip-month { font-size: 15px; font-weight: 700; flex: 1; }
.payslip-net   { font-size: 17px; font-weight: 700; color: var(--brand-dark); }
.payslip-arrow { font-size: 20px; color: var(--text-light); }

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-lg) var(--space-md);
  width: 100%;
  max-width: 430px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  background: var(--surface2);
  color: var(--text-sub);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Payslip Detail */
.payslip-section {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin: var(--space-sm) 0;
}

.payslip-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}

.payslip-row:last-child { border-bottom: none; }
.payslip-row.total  { font-weight: 700; }
.payslip-row.deduction span:last-child { color: var(--accent); }

.payslip-net-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-top: var(--space-md);
  font-weight: 700;
  font-size: 16px;
}

.net-amount { font-size: 24px; }

.alert-103 {
  background: #FFF3CD;
  border: 1px solid var(--accent-warm);
  color: #856404;
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  font-size: 13px;
  margin-top: var(--space-sm);
  font-weight: 600;
}

/* ===== History ===== */
.history-content {
  padding: var(--space-md);
}

.history-item {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-sm);
}

.history-item.needs-correction {
  border-left: 3px solid var(--accent);
}

.history-date  { font-size: 14px; font-weight: 700; }
.history-times { font-size: 13px; color: var(--text-sub); display: flex; gap: 8px; }
.history-hours { font-size: 16px; font-weight: 700; text-align: right; }

/* ===== Correction ===== */
.correction-content {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.correction-item {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
}

.correction-date   { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.correction-status { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 100px; display: inline-block; margin-bottom: 4px; }
.correction-reason { font-size: 13px; color: var(--text-sub); }

.status-pending  { background: #FFF3CD; color: #856404; }
.status-approved { background: var(--brand-light); color: var(--brand-dark); }
.status-rejected { background: #FFE4E4; color: var(--accent); }

/* ===== My Page ===== */
.mypage-content {
  padding: var(--space-md);
}

.profile-card {
  background: linear-gradient(135deg, #00C48C 0%, #00897B 100%);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  color: #fff;
  margin-bottom: var(--space-md);
  text-align: center;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  background: rgba(255,255,255,0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin: 0 auto var(--space-sm);
}

.profile-name  { font-size: 20px; font-weight: 700; }
.profile-email { font-size: 13px; opacity: 0.85; margin-top: 2px; }

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.info-cell {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
}

.info-cell-label { font-size: 11px; color: var(--text-sub); font-weight: 700; text-transform: uppercase; margin-bottom: 4px; }
.info-cell-value { font-size: 15px; font-weight: 700; }

.section-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-sm);
}

.lang-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.lang-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.lang-btn.active {
  border-color: var(--brand);
  background: var(--brand-light);
  color: var(--brand-dark);
}

.lang-flag  { font-size: 20px; }
.lang-label { flex: 1; text-align: left; font-size: 13px; }
.lang-check { font-size: 14px; color: var(--brand); font-weight: 700; }

.danger-btn {
  width: 100%;
  padding: 14px;
  background: var(--surface);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  margin-top: var(--space-md);
}

.danger-btn:hover { background: #FFE4E4; }

/* ===== Shift Request Form ===== */
#shift-request-section {
  margin-top: var(--space-lg);
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
}

.shift-request-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: var(--space-md);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  z-index: 300;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: var(--brand); }
.toast-error   { background: var(--status-error); }
.toast-info    { background: var(--text); }

/* ===== Loading ===== */
#global-loading {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 400;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
  gap: var(--space-sm);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: var(--space-xl) auto;
}

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

/* ===== Empty / Error States ===== */
.empty-state, .error-state {
  text-align: center;
  padding: var(--space-xl);
  font-size: 15px;
  color: var(--text-sub);
}

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

/* ===== Utility ===== */
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.text-center { text-align: center; }
