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

:root {
  --navy:    #1a237e;
  --blue:    #1565c0;
  --blue-lt: #e3f2fd;
  --green:   #2e7d32;
  --green-lt:#e8f5e9;
  --orange:  #e65100;
  --orange-lt:#fff3e0;
  --gray:    #757575;
  --gray-lt: #f5f5f5;
  --red:     #c62828;
  --white:   #ffffff;
  --shadow:  0 2px 8px rgba(0,0,0,.12);
}

body {
  font-family: 'Hiragino Sans', 'Meiryo', sans-serif;
  background: #eceff1;
  color: #212121;
  min-height: 100vh;
}

/* ── Navbar ───────────────────────────────────────────────── */
.navbar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 100;
}
.navbar-brand { font-size: 1.2rem; font-weight: 700; letter-spacing: .05em; }
.navbar-links { display: flex; gap: 8px; }
.nav-link {
  color: rgba(255,255,255,.8);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: .9rem;
  transition: background .2s;
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.2);
  color: #fff;
}

/* ── Timecard Layout ──────────────────────────────────────── */
.timecard-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: calc(100vh - 56px);
}

/* Action pane (left) */
.action-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--white);
  gap: 16px;
}

.clock-display {
  font-size: 4rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: .05em;
  font-variant-numeric: tabular-nums;
}
.date-display {
  font-size: 1.1rem;
  color: var(--gray);
}

.selected-employee {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--navy);
  text-align: center;
}
.hint-text { font-size: 1rem; color: var(--gray); font-weight: 400; }

/* Status badge */
.status-badge-wrap { text-align: center; }
.status-badge {
  display: inline-block;
  padding: 6px 24px;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 700;
  background: var(--gray-lt);
  color: var(--gray);
}
.status-badge.working   { background: var(--green-lt); color: var(--green); }
.status-badge.on-break  { background: var(--orange-lt); color: var(--orange); }
.status-badge.clocked-out { background: #eeeeee; color: #9e9e9e; }

.time-info {
  font-size: 1rem;
  color: var(--gray);
  text-align: center;
}

/* Action buttons */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  max-width: 480px;
}
.btn-action {
  height: 120px;
  border: none;
  border-radius: 16px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: .1em;
  cursor: pointer;
  transition: transform .1s, opacity .2s, box-shadow .2s;
  box-shadow: var(--shadow);
}
.btn-action:active { transform: scale(.96); }
.btn-action:disabled {
  opacity: .35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.btn-clockin  { background: #1565c0; color: #fff; }
.btn-break    { background: #f57c00; color: #fff; }
.btn-return   { background: #2e7d32; color: #fff; }
.btn-clockout { background: #c62828; color: #fff; }

.action-message {
  min-height: 28px;
  font-size: .95rem;
  color: var(--red);
  font-weight: 600;
  text-align: center;
}

/* Employee list pane (right) */
.employee-list-pane {
  background: #fafafa;
  border-left: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.list-header {
  background: var(--navy);
  color: #fff;
  padding: 14px 16px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .05em;
}
.employee-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.emp-card {
  padding: 14px 16px;
  border-radius: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border .15s, background .15s;
}
.emp-card:hover { border-color: var(--blue); }
.emp-card.selected { border-color: var(--navy); box-shadow: 0 0 0 2px var(--navy); }

/* Status colors */
.emp-card.status-default  { background: #ffffff; }
.emp-card.status-working  { background: var(--green-lt); border-color: #a5d6a7; }
.emp-card.status-break    { background: var(--orange-lt); border-color: #ffcc80; }
.emp-card.status-done     { background: #eeeeee; color: #9e9e9e; }

.emp-name  { font-size: 1.05rem; font-weight: 700; }
.emp-status-text { font-size: .78rem; margin-top: 2px; }
.status-working  .emp-status-text { color: var(--green); }
.status-break    .emp-status-text { color: var(--orange); }
.status-done     .emp-status-text { color: #9e9e9e; }
.status-default  .emp-status-text { color: #9e9e9e; }

.loading-text { color: var(--gray); padding: 16px; text-align: center; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-box {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  min-width: 300px;
  max-width: 92vw;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-box h3 { margin-bottom: 16px; color: var(--navy); }
.modal-wide { min-width: 440px; }
.modal-buttons { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.btn-modal { padding: 10px 24px; border-radius: 8px; border: none; font-size: 1rem; cursor: pointer; font-weight: 600; }
.btn-yes  { background: var(--blue); color: #fff; }
.btn-no   { background: #e0e0e0; color: #333; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; color: #555; }
.form-input, .form-select {
  width: 100%; padding: 9px 12px;
  border: 1px solid #ccc; border-radius: 8px;
  font-size: .95rem; font-family: inherit;
}
.form-input:focus, .form-select:focus {
  outline: 2px solid var(--blue); border-color: transparent;
}
.form-row { display: flex; gap: 12px; }
.form-row .half { flex: 1; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  background: var(--blue); color: #fff;
  border: none; border-radius: 8px;
  padding: 9px 20px; cursor: pointer;
  font-size: .9rem; font-weight: 600;
  transition: background .2s;
}
.btn-primary:hover { background: var(--navy); }
.btn-secondary {
  background: #e0e0e0; color: #333;
  border: none; border-radius: 8px;
  padding: 9px 20px; cursor: pointer;
  font-size: .9rem; font-weight: 600;
}
.btn-danger {
  background: var(--red); color: #fff;
  border: none; border-radius: 8px;
  padding: 9px 20px; cursor: pointer;
  font-size: .9rem; font-weight: 600;
}
.btn-sm { padding: 5px 12px; font-size: .82rem; }
.btn-full { width: 100%; padding: 12px; font-size: 1rem; }

/* ── Login ────────────────────────────────────────────────── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 56px);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 36px;
  width: 360px; box-shadow: var(--shadow);
}
.login-title { text-align: center; margin-bottom: 24px; color: var(--navy); }
.login-error {
  background: #ffebee; color: var(--red);
  padding: 8px 12px; border-radius: 6px;
  margin-bottom: 12px; font-size: .9rem;
}

/* ── Admin Layout ─────────────────────────────────────────── */
main { padding-bottom: 40px; }
.admin-layout { max-width: 1200px; margin: 24px auto; padding: 0 20px; }

.tab-bar {
  display: flex; gap: 4px;
  border-bottom: 2px solid #cfd8dc;
  margin-bottom: 24px;
}
.tab-btn {
  padding: 10px 22px;
  border: none; background: transparent;
  font-size: .95rem; cursor: pointer; color: var(--gray);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color .2s, border-color .2s;
  text-decoration: none;
  font-family: inherit; font-weight: 600;
}
.tab-btn:hover  { color: var(--blue); }
.tab-btn.active { color: var(--navy); border-bottom-color: var(--navy); }
.tab-logout { margin-left: auto; color: #b71c1c; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  margin-bottom: 20px;
}
.section-header h2 { color: var(--navy); font-size: 1.2rem; }
.payroll-selectors { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.payroll-selectors .form-select { width: auto; }

/* ── Data table ───────────────────────────────────────────── */
.data-table {
  width: 100%; border-collapse: collapse;
  background: #fff; border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow);
}
.data-table th {
  background: var(--navy); color: #fff;
  padding: 10px 12px; text-align: left; font-size: .85rem;
}
.data-table td { padding: 10px 12px; font-size: .9rem; border-bottom: 1px solid #eee; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--blue-lt); }
.data-table .actions { display: flex; gap: 6px; }
.btn-table {
  padding: 4px 10px; border: none; border-radius: 4px;
  cursor: pointer; font-size: .8rem; font-weight: 600;
}
.btn-edit   { background: #e3f2fd; color: var(--blue); }
.btn-hide   { background: #fff9c4; color: #f57f17; }
.btn-show   { background: #e8f5e9; color: var(--green); }
.btn-del    { background: #ffebee; color: var(--red); }

/* ── Payroll sheet ────────────────────────────────────────── */
.payroll-sheet {
  background: #fff; border-radius: 10px;
  padding: 24px; box-shadow: var(--shadow);
}
.payroll-title { font-size: 1.2rem; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.payroll-subtitle { color: var(--gray); font-size: .9rem; margin-bottom: 20px; }

.payroll-table {
  width: 100%; border-collapse: collapse; font-size: .85rem; margin-bottom: 24px;
}
.payroll-table th {
  background: #eceff1; color: #37474f;
  padding: 8px 10px; text-align: center;
  border: 1px solid #cfd8dc; font-size: .78rem;
  white-space: nowrap;
}
.payroll-table td {
  padding: 7px 10px; border: 1px solid #e0e0e0;
  text-align: center; font-size: .83rem;
}
.payroll-table .col-date    { text-align: left; font-weight: 600; }
.payroll-table .col-time    { font-variant-numeric: tabular-nums; }
.payroll-table tr.workday   { background: #fff; }
.payroll-table tr.offday    { background: #fafafa; color: #bdbdbd; }
.payroll-table tr.total-row {
  background: #e8eaf6; font-weight: 700;
  border-top: 2px solid #9fa8da;
}

.payroll-summary {
  background: #f8f9fa; border-radius: 8px; padding: 20px;
  border: 1px solid #e0e0e0;
}
.payroll-summary h3 { font-size: 1rem; color: var(--navy); margin-bottom: 12px; }
.pay-formula { font-size: .9rem; color: #555; margin-bottom: 6px; }
.pay-formula span { font-weight: 700; color: #212121; }
.pay-divider { border: none; border-top: 1px dashed #ccc; margin: 10px 0; }
.pay-total { font-size: 1.3rem; font-weight: 700; color: var(--navy); margin-top: 8px; }

.payroll-adjust { margin-top: 20px; }
.payroll-adjust h4 { font-size: .9rem; color: var(--gray); margin-bottom: 10px; }
.adjust-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.adjust-row .form-group { margin-bottom: 0; flex: 1; min-width: 120px; }

/* Records table */
.records-table {
  width: 100%; border-collapse: collapse;
  background: #fff; border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow); font-size: .88rem;
}
.records-table th {
  background: var(--navy); color: #fff;
  padding: 9px 12px; font-size: .8rem;
}
.records-table td { padding: 8px 12px; border-bottom: 1px solid #eee; }
.records-table tr.off-day td { color: #bdbdbd; background: #fafafa; }
.records-table tr:hover td   { background: var(--blue-lt); }
.break-row {
  display: flex; gap: 6px;
  align-items: center; margin-bottom: 4px;
}
.break-row input { width: 90px; }
.break-row .btn-del-break {
  background: none; border: none; cursor: pointer; color: var(--red); font-size: 1rem;
}

/* ── Time select ──────────────────────────────────────────── */
.time-sel-wrap { display: inline-flex; align-items: center; gap: 2px; }
.time-sel-h { width: 60px !important; padding: 6px 4px !important; text-align: center; }
.time-sel-m { width: 60px !important; padding: 6px 4px !important; text-align: center; }
.time-colon { font-weight: 700; padding: 0 2px; }

/* ── Pay calc table ───────────────────────────────────────── */
.pay-calc-table {
  width: 100%; border-collapse: collapse; font-size: .9rem;
}
.pay-calc-table th {
  background: none; color: #555; text-align: left;
  padding: 5px 8px; font-size: .82rem; border: none;
  white-space: nowrap;
}
.pay-calc-table td { padding: 5px 8px; border: none; }
.pay-calc-table .pay-num { text-align: right; font-weight: 700; font-size: .95rem; }
.pay-calc-table .deduction { color: #c62828; }
.pay-calc-table .total-pay-row { border-top: 2px solid #1a237e; }
.pay-calc-table .total-pay-row th { color: var(--navy); font-size: 1rem; }
.pay-calc-table .total-num { font-size: 1.2rem; color: var(--navy); }
.no-clockout { color: #e65100; }
.print-header { margin-bottom: 12px; }

/* ── Print (A4) ───────────────────────────────────────────── */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm 12mm;
  }

  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  body { background: #fff; font-size: 9pt; }

  .navbar, .tab-bar, .section-header,
  .no-print, .payroll-adjust, .btn-secondary,
  .btn-primary, .btn-danger { display: none !important; }

  main { padding: 0; }
  .admin-layout { margin: 0; padding: 0; max-width: 100%; }

  #tab-employees, #tab-records { display: none !important; }
  #tab-payroll { display: block !important; }

  .payroll-sheet {
    box-shadow: none; border: none; padding: 0;
  }
  .payroll-title { font-size: 12pt; margin-bottom: 6px; }

  /* Compact table for A4 */
  .payroll-table { font-size: 7.5pt; margin-bottom: 8mm; }
  .payroll-table th { padding: 3px 4px; font-size: 7pt; background: #eceff1 !important; }
  .payroll-table td { padding: 2px 4px; }
  .payroll-table tr.offday td { color: #999; }

  .payroll-summary { border: 1px solid #ccc; padding: 6mm; margin-top: 4mm; }
  .pay-calc-table { font-size: 9pt; }
  .pay-calc-table .pay-num { font-size: 10pt; }
  .pay-calc-table .total-num { font-size: 12pt; }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 700px) {
  .timecard-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
  }
  .employee-list-pane {
    border-left: none; border-top: 1px solid #e0e0e0;
    max-height: 40vh;
  }
  .action-pane { min-height: 60vh; }
  .btn-action { height: 90px; font-size: 1.3rem; }
  .clock-display { font-size: 2.8rem; }
}
