
:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --text: #282522;
  --muted: #746d65;
  --border: #ddd7cf;
  --accent: #59483a;
  --accent-soft: #eee7df;
  --danger: #a54b43;
  --shadow: 0 6px 22px rgba(40, 37, 34, .06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 20px clamp(16px, 4vw, 44px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header h1 { margin: 0; font-size: clamp(22px, 3vw, 32px); }
.app-header p { margin: 5px 0 0; color: var(--muted); }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px clamp(16px, 4vw, 44px);
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 10px 14px;
}
.tab.active {
  color: var(--text);
  background: var(--accent-soft);
}

main { padding: 24px clamp(12px, 4vw, 44px) 48px; }
.panel { display: none; }
.panel.active { display: block; }

button, .button {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  padding: 9px 14px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.2;
}
button:hover, .button:hover { opacity: .9; }
button.secondary, .button.secondary {
  background: white;
  color: var(--accent);
  border-color: var(--border);
}
button.danger {
  background: white;
  color: var(--danger);
  border-color: #e4c4bf;
}
.file-button { display: inline-flex; align-items: center; }

input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  padding: 8px 10px;
  font-size: 15px;
}
input:focus {
  outline: 2px solid #c9b9aa;
  outline-offset: 1px;
}
label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

.toolbar, .report-controls {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 18px;
}
.toolbar-actions, .form-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.product-form {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr .7fr auto auto;
  align-items: end;
  gap: 12px;
}
.checkbox-field { padding-bottom: 7px; }
.checkbox-field label { color: var(--text); margin: 0; white-space: nowrap; }
.checkbox-field input { width: auto; min-height: auto; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}
th:first-child, td:first-child,
th:nth-child(4), td:nth-child(4) { text-align: left; }
thead th {
  position: sticky;
  top: 0;
  background: #f3efe9;
  color: #5a5149;
  font-size: 13px;
  font-weight: 600;
}
tbody tr:last-child td { border-bottom: none; }
td input[type="number"] { width: 86px; margin-left: auto; text-align: right; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 16px 0;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { margin-top: 6px; font-size: 22px; font-weight: 700; }

.hint { color: var(--muted); font-size: 13px; }

.report-controls > div {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
}
.report-controls label { grid-column: 1 / -1; }

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.analytics-grid .card { margin: 0; }

.ranking-row {
  display: grid;
  grid-template-columns: minmax(110px, 1.4fr) 2fr auto;
  gap: 10px;
  align-items: center;
  margin: 10px 0;
  font-size: 14px;
}
.ranking-bar, .bar-track {
  height: 10px;
  background: #ede7e1;
  border-radius: 999px;
  overflow: hidden;
}
.ranking-fill, .bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.weekday-row {
  display: grid;
  grid-template-columns: 30px 1fr 70px;
  align-items: center;
  gap: 10px;
  margin: 11px 0;
}
.weekday-row .num { text-align: right; }

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #282522;
  color: white;
  border-radius: 10px;
  padding: 12px 16px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .product-form { grid-template-columns: 1fr 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .analytics-grid { grid-template-columns: 1fr; }
  .toolbar, .report-controls { align-items: stretch; flex-direction: column; }
}
@media (max-width: 560px) {
  .product-form { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .header-actions { width: 100%; }
}

.storage-status {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.storage-status.error {
  color: var(--danger);
  font-weight: 600;
}

.hidden { display: none !important; }
.role-hidden { display: none !important; }
.login-overlay {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: -6px 0 4px; color: var(--muted); }
.login-error { min-height: 20px; color: var(--danger); font-size: 13px; }
.header-side { display: grid; gap: 8px; justify-items: end; }
.user-badge { font-size: 12px; color: var(--muted); }
@media (max-width: 900px) { .header-side { justify-items: start; } }

/* v5.3: free meal count; warn only when allocation exceeds production */
tr.over-allocated td { background: #fff4f1; }
tr.over-allocated .meal-input { border-color: #d77a6f; }


/* v5.4: 従業員IDは日別入力専用 */
.role-hidden {
  display: none !important;
}
body.staff-mode .tabs [data-admin-only],
body.staff-mode main > section[data-admin-only],
body.staff-mode [data-admin-only] {
  display: none !important;
}
body.staff-mode .tabs {
  justify-content: flex-start;
}


/* v5.5: 日別入力をスマホ片手操作向けに再設計 */
.daily-search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.search-input-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#productSearch { font-size: 16px; min-height: 46px; }
.search-clear { min-height: 46px; }
.search-result-count { margin-top: 7px; color: var(--muted); font-size: 12px; }
.search-empty { padding: 28px 14px; text-align: center; color: var(--muted); }
.search-hidden { display: none !important; }

.daily-collapsible {
  margin: 10px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.daily-collapsible > summary {
  cursor: pointer;
  padding: 13px 14px;
  font-weight: 650;
  color: var(--text);
  user-select: none;
}
.daily-collapsible[open] > summary { border-bottom: 1px solid var(--border); }
.daily-collapsible .compact-toolbar { padding: 14px; margin: 0; }
.daily-summary .kpi-grid { padding: 0 14px 14px; margin: 14px 0 0; }
.daily-help .hint { margin: 0; padding: 14px; }
.mobile-product-price, .mobile-input-label, .mobile-details-cell, .mobile-details-head { display: none; }

@media (max-width: 700px) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .app-header { padding: 12px 14px; gap: 8px; }
  .app-header h1 { font-size: 19px; }
  .app-header p { font-size: 12px; }
  .header-side { width: 100%; display: flex; align-items: center; justify-content: space-between; }
  .header-actions { margin-left: auto; }
  .header-actions [data-admin-only] { display: none !important; }
  .tabs { padding: 8px 10px; position: sticky; top: 0; z-index: 15; }
  .tab { padding: 9px 12px; }
  main { padding: 10px 10px 32px; }

  .daily-search-card {
    position: sticky;
    top: 52px;
    z-index: 12;
    margin: 0 0 10px;
    border-radius: 12px;
    padding: 10px;
  }
  .daily-search-card > label { margin-bottom: 5px; }
  .search-result-count { margin-top: 5px; }
  .daily-operations, .daily-summary, .daily-help { margin: 8px 0; }

  .daily-table-wrap {
    overflow: visible;
    background: transparent;
    border: 0;
    border-radius: 0;
  }
  .daily-table { min-width: 0; width: 100%; display: block; }
  .daily-table thead { display: none; }
  .daily-table tbody { display: grid; gap: 10px; }
  .daily-table tr.daily-product-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
  }
  .daily-table tr.daily-product-row.over-allocated { border-color: #d77a6f; }
  .daily-table tr.daily-product-row td {
    display: block;
    border: 0;
    padding: 0;
    text-align: left;
    white-space: normal;
  }
  .daily-table .product-cell {
    grid-column: 1 / -1;
    display: flex !important;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 2px !important;
  }
  .product-name { font-size: 17px; font-weight: 750; line-height: 1.35; }
  .mobile-product-price { display: block; color: var(--muted); font-size: 14px; flex: 0 0 auto; }
  .daily-table .price-cell, .daily-table .computed-cell { display: none !important; }
  .daily-table .daily-input-cell { min-width: 0; }
  .mobile-input-label {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    color: var(--muted);
  }
  .daily-table td input.daily-number-input {
    width: 100%;
    min-width: 0;
    min-height: 52px;
    margin: 0;
    padding: 8px 6px;
    text-align: center;
    font-size: 21px;
    font-weight: 700;
    border-radius: 10px;
  }
  .mobile-details-cell { display: block !important; grid-column: 1 / -1; }
  .product-detail-fold {
    margin-top: 2px;
    border-top: 1px solid var(--border);
    padding-top: 7px;
  }
  .product-detail-fold > summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 13px;
    padding: 5px 0;
    user-select: none;
  }
  .mobile-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
    margin-top: 6px;
  }
  .mobile-stat-grid > div {
    background: var(--bg);
    border-radius: 9px;
    padding: 8px;
    display: grid;
    gap: 3px;
  }
  .mobile-stat-grid span { color: var(--muted); font-size: 11px; }
  .mobile-stat-grid strong { font-size: 14px; }
  .allocation-warning { margin-top: 8px; color: var(--danger); font-size: 12px; font-weight: 650; }

  .daily-summary .kpi-grid { grid-template-columns: 1fr 1fr; gap: 7px; }
  .daily-summary .kpi { padding: 10px; }
  .daily-summary .kpi .value { font-size: 17px; }
  .compact-toolbar .toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .compact-toolbar .toolbar-actions button { width: 100%; min-height: 44px; }
}

@media (max-width: 390px) {
  .daily-table tr.daily-product-row { padding: 10px; gap: 6px; }
  .daily-table td input.daily-number-input { font-size: 19px; min-height: 50px; }
  .search-clear { padding-inline: 10px; }
}


/* v5.6: 日別入力の項目別一括クリア */
.bulk-clear-section {
  margin: 0 14px 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #faf8f5;
}
.bulk-clear-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 9px;
}
.bulk-clear-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.bulk-clear-buttons button {
  width: 100%;
  min-height: 42px;
  padding-inline: 8px;
}
.danger-soft {
  color: var(--danger) !important;
  border-color: #e4c4bf !important;
  background: #fff !important;
}
.bulk-clear-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
@media (max-width: 560px) {
  .bulk-clear-section { margin: 0 10px 10px; padding: 10px; }
  .bulk-clear-buttons { grid-template-columns: 1fr; gap: 7px; }
  .bulk-clear-buttons button { min-height: 46px; text-align: left; }
}
