/* Daily Sales Report — simple, consistent layout */

:root {
  --bg: #f5f5f5;
  --surface: #fff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #666;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --row-alt: #fafafa;
  --total-bg: #f0f0f0;
  --error: #b91c1c;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  --radius: 4px;
  --font-size: 0.9375rem;
  --font-size-sm: 0.875rem;
  --line-height: 1.5;
}

* {
  box-sizing: border-box;
}

/* Loading overlay — full-screen cover */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading-overlay[hidden] {
  display: none;
}

.loading-content {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  background: var(--surface);
  padding: var(--space-lg) var(--space-xl);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 0.7s linear infinite;
}

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

.loading-text {
  font-size: var(--font-size);
  color: var(--text);
}

body {
  font-family: "Segoe UI", "Meiryo", sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-size);
  line-height: var(--line-height);
}

/* Header */
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  background: var(--surface);
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  margin-left: auto;
  flex-shrink: 0;
}

.logout-link {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  text-decoration: none;
}

.logout-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.lang-switcher {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.lang-label {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin: 0;
}

.lang-switcher select {
  font-size: var(--font-size-sm);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.header-link {
  margin: var(--space-xs) 0 0 0;
  font-size: var(--font-size-sm);
}

.header-link a {
  color: var(--text-muted);
  text-decoration: none;
}

.header-link a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--space-md);
}

.tab {
  padding: var(--space-md) var(--space-lg);
  border: none;
  background: transparent;
  font-size: var(--font-size);
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

/* Main content */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-lg);
}

.panel {
  display: none;
  background: var(--surface);
  padding: var(--space-lg);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.panel.active {
  display: block;
}

/* Section title — unified */
.panel h2,
.section-title,
.report-title,
.panel h3,
.chart-title {
  margin: 0 0 var(--space-md) 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.panel h2:first-child {
  margin-top: 0;
}

.hint {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  margin: 0 0 var(--space-lg) 0;
}

/* Upload form */
.business-hours-table {
  width: 100%;
  max-width: 360px;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-sm);
}
.business-hours-table th,
.business-hours-table td {
  padding: var(--space-xs) var(--space-sm);
  text-align: left;
  border: 1px solid var(--border);
}
.business-hours-table th {
  background: var(--row-alt);
  font-weight: 600;
}
.bh-time {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 5rem;
}

.store-id-input,
.store-name-input {
  width: 100%;
  max-width: 14rem;
  box-sizing: border-box;
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--font-size-sm);
}
.btn-delete-store {
  font-size: var(--font-size-sm);
  padding: var(--space-xs) var(--space-sm);
  cursor: pointer;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  max-width: 480px;
}

.upload-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm) var(--space-md);
}

.upload-group label {
  flex: 0 0 200px;
  font-weight: 500;
}

.required {
  color: var(--error);
  font-size: var(--font-size-sm);
}

.upload-group input[type="file"],
.upload-group input[type="date"] {
  flex: 1;
  min-width: 200px;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.file-name {
  flex: 1 1 100%;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.btn-primary {
  align-self: flex-start;
  padding: var(--space-sm) var(--space-lg);
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: var(--font-size);
  font-weight: 500;
  cursor: pointer;
}

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

.btn-csv {
  align-self: flex-start;
  padding: var(--space-sm) var(--space-lg);
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: var(--font-size);
  font-weight: 500;
  cursor: pointer;
}

.btn-csv:hover {
  background: var(--accent);
  color: white;
}

.error {
  color: var(--error);
  font-size: var(--font-size-sm);
  margin-top: var(--space-md);
}

/* Output panel — filters */
.output-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-lg);
}

/* 各項目を1単位で折り返し（Store, Department, Output date, Time range がバラけないように） */
.output-header-item {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: var(--space-xs);
  flex-shrink: 0;
}

/* Time range: keep label + start + ～ + end on one line (no wrap inside) */
.output-header-time-range {
  gap: var(--space-xs);
  white-space: nowrap;
}

.output-header-time-range #time-start,
.output-header-time-range #time-end {
  flex-shrink: 0;
}

.output-header label {
  font-weight: 500;
  font-size: var(--font-size);
}

/* 日付・ドロップダウンを同一スタイルに統一 */
.output-header select,
.output-header input[type="date"] {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-md) center;
  padding-right: 2rem;
}

.output-header input[type="date"] {
  background-image: none;
  padding-right: var(--space-md);
}

.output-header select::-ms-expand {
  display: none;
}

#output-date,
#daily-start-date,
#daily-end-date,
#weekly-end-date,
#department-select,
#hourly-export-select,
#daily-export-select,
#weekly-export-select,
#weekly-num-weeks {
  min-width: 160px;
}

#time-start,
#time-end {
  min-width: 100px;
}

.output-header-sep {
  margin-left: 0;
}

.output-header-item + .output-header-item .output-header-sep,
.output-header-item + .output-header-item .time-range-label {
  margin-left: 0;
}

.time-range-label {
  margin-left: 0;
}

.time-range-sep {
  color: var(--text-muted);
  padding: 0 var(--space-xs);
}

/* Blocks — same spacing between sections */
.table-wrapper,
.summary-section,
.composition-section,
.chart-section {
  margin-bottom: var(--space-xl);
}

.table-wrapper:last-child,
.summary-section:last-child,
.composition-section:last-child,
.chart-section:last-child {
  margin-bottom: 0;
}

.chart-section.hidden,
.composition-section.hidden {
  display: none;
}

/* Tables — unified style */
.report-table,
.summary-table,
.composition-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.report-table th,
.report-table td,
.summary-table th,
.summary-table td,
.composition-table th,
.composition-table td {
  padding: var(--space-sm) var(--space-md);
  text-align: right;
  border: 1px solid var(--border);
  vertical-align: top;
}

.report-table th:first-child,
.report-table td:first-child,
.summary-table th:first-child,
.summary-table td:first-child,
.composition-table th:first-child,
.composition-table td:first-child {
  text-align: left;
}

.report-table thead th,
.summary-table thead th,
.composition-table thead th {
  background: var(--row-alt);
  font-weight: 600;
  text-align: center;
}

.report-table tbody tr:hover,
.summary-table tbody tr:hover {
  background: var(--row-alt);
}

.report-table tfoot td,
.summary-table tfoot td,
.composition-table tfoot td {
  background: var(--total-bg);
  font-weight: 600;
}

.table-wrapper {
  overflow-x: auto;
}

.report-table th:first-child,
.report-table td:first-child {
  min-width: 7rem;
}

.report-table thead th:first-child,
.summary-table thead th:first-child,
.composition-table thead th:first-child {
  text-align: center;
}

.report-table tr.total-row td {
  font-weight: 600;
  background: var(--total-bg);
}

/* Department tables (weekly/daily): fixed layout, equal column widths */
.report-table.daily-table {
  table-layout: fixed;
}

.report-table.daily-table th:first-child,
.report-table.daily-table td:first-child {
  width: 14%;
  min-width: 6rem;
  box-sizing: border-box;
}

.report-table.daily-table th:last-child,
.report-table.daily-table td:last-child {
  width: 10%;
  min-width: 4.5rem;
  box-sizing: border-box;
}

.summary-table {
  max-width: 480px;
}

/* Composition table — column widths */
.composition-table {
  table-layout: fixed;
}

.composition-table th,
.composition-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.composition-table th:first-child,
.composition-table td:first-child {
  width: 14%;
}

.composition-table th:last-child,
.composition-table td:last-child {
  width: 14%;
}

.composition-table th:not(:first-child):not(:last-child),
.composition-table td:not(:first-child):not(:last-child) {
  width: 12%;
}

/* Charts */
.chart-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
}

.chart-wrapper:last-child {
  margin-bottom: 0;
}

.chart-title {
  margin-bottom: var(--space-md);
  text-align: center;
}

.chart-wrapper canvas {
  max-width: 100%;
  height: auto !important;
}

.composition-chart-wrapper {
  max-width: 900px;
  margin-top: var(--space-lg);
}

.composition-section h3,
.summary-section h3 {
  margin-bottom: var(--space-md);
}

.empty-message {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  font-style: italic;
  margin: var(--space-lg) 0 0 0;
}

/* Responsive — tablet and below */
@media (max-width: 768px) {
  main {
    padding: var(--space-md);
  }

  .panel {
    padding: var(--space-md);
  }

  header h1 {
    font-size: 1rem;
    line-height: 1.3;
  }

  .tabs {
    padding: 0 var(--space-sm);
    gap: 0;
  }

  .tab {
    padding: var(--space-md) var(--space-sm);
    font-size: var(--font-size-sm);
    min-height: 44px;
    flex: 1;
    min-width: 0;
  }

  .upload-group label {
    flex: 1 1 100%;
  }

  .upload-group input[type="file"] {
    min-width: 100%;
  }

  .btn-primary {
    min-height: 44px;
    padding: var(--space-md) var(--space-lg);
    width: 100%;
    max-width: 320px;
  }

  .output-header {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-md);
  }

  .output-header-sep {
    margin-left: 0;
  }

  .time-range-label {
    margin-left: 0;
  }

  .output-header select,
  .output-header input[type="date"] {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    min-height: 44px;
    font-size: 16px; /* avoids zoom on focus in iOS */
  }

  .output-header .time-range-sep {
    display: none;
  }

  .output-header select + span + select {
    margin-top: 0;
  }

  .report-table,
  .summary-table,
  .composition-table {
    font-size: 0.8125rem;
  }

  .report-table th,
  .report-table td,
  .summary-table th,
  .summary-table td,
  .composition-table th,
  .composition-table td {
    padding: var(--space-xs) var(--space-sm);
  }

  .chart-wrapper {
    padding: var(--space-md);
  }

  .chart-wrapper canvas {
    max-height: 220px;
  }
}

/* Mobile — small phones */
@media (max-width: 480px) {
  body {
    font-size: 0.9375rem;
  }

  main {
    padding: var(--space-sm);
  }

  .panel {
    padding: var(--space-sm);
  }

  header {
    padding: var(--space-sm) var(--space-md);
  }

  header h1 {
    font-size: 0.9375rem;
  }

  .tab {
    padding: var(--space-sm) var(--space-xs);
    font-size: 0.8125rem;
  }

  .panel h2,
  .section-title,
  .report-title,
  .panel h3,
  .chart-title {
    font-size: 0.9375rem;
  }

  .hint {
    font-size: 0.8125rem;
  }

  .table-wrapper {
    margin-left: calc(-1 * var(--space-sm));
    margin-right: calc(-1 * var(--space-sm));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrapper table {
    min-width: 600px;
  }

  .summary-section,
  .composition-section,
  .chart-section {
    margin-bottom: var(--space-lg);
  }

  .chart-wrapper canvas {
    max-height: 200px;
  }

  .output-header select,
  .output-header input[type="date"] {
    min-height: 44px;
    font-size: 16px;
    width: 100%;
    max-width: 100%;
  }
}

/* Touch-friendly: ensure minimum tap target size */
@media (hover: none) and (pointer: coarse) {
  .tab {
    min-height: 44px;
  }

  .btn-primary {
    min-height: 44px;
  }

  select,
  input[type="file"],
  input[type="date"] {
    min-height: 44px;
  }
}
