/* ===== リセット・基本 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', 'Noto Sans JP', 'Hiragino Sans', Meiryo, sans-serif;
  font-size: 14px;
  background: #f0f2f5;
  color: #333;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== ヘッダー ===== */
.header {
  background: #1a3a5c;
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.header-title { font-size: 17px; font-weight: 700; flex: 1; letter-spacing: 0.02em; }
.header-sub   { font-size: 11px; opacity: 0.55; }
@media (max-width: 480px) { .header-sub { display: none; } }

/* ===== BLE接続バー ===== */
.ble-bar {
  background: #fff;
  border-bottom: 2px solid #e8e8e8;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.ble-info {
  display: flex; align-items: center; gap: 10px;
  flex: 1; min-width: 0; flex-wrap: wrap;
}
.ble-label  { color: #888; font-size: 12px; white-space: nowrap; }
.ble-device { font-weight: bold; font-size: 14px; }
.ble-device.empty { color: #bbb; }
.status-dot  { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; flex-shrink: 0; }
.status-dot.connected    { background: #52c41a; }
.status-dot.disconnected { background: #bbb; }
.status-text { font-size: 13px; white-space: nowrap; }
.ble-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ===== ボタン ===== */
.btn {
  padding: 8px 14px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  min-height: 38px;
  white-space: nowrap;
  touch-action: manipulation;
  transition: opacity 0.1s;
}
.btn:active  { opacity: 0.7; }
.btn.primary { background: #1a3a5c; color: #fff; border-color: #1a3a5c; }
.btn.danger  { background: #ff4d4f; color: #fff; border-color: #ff4d4f; }
.btn:disabled { opacity: 0.35; cursor: default; }

@media (max-width: 600px) {
  .ble-bar { flex-direction: column; align-items: stretch; }
  .ble-info { justify-content: space-between; }
  .ble-actions .btn { flex: 1; text-align: center; }
}

/* ===== 4タブバー ===== */
.main-tab-bar {
  background: #fff;
  border-bottom: 2px solid #e0e6ef;
  display: flex;
  position: sticky;
  top: 52px;
  z-index: 90;
  overflow-x: auto;
  scrollbar-width: none;
}
.main-tab-bar::-webkit-scrollbar { display: none; }
.main-tab {
  flex: 1;
  min-width: 0;
  padding: 14px 8px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: #777;
  border-bottom: 3px solid transparent;
  text-align: center;
  font-weight: 500;
  min-height: 48px;
  touch-action: manipulation;
  transition: color 0.15s;
  white-space: nowrap;
}
.main-tab:active { background: #f5f8ff; }
.main-tab.active {
  color: #1a3a5c;
  border-bottom-color: #1a3a5c;
  font-weight: bold;
}
.tab-icon {
  width: 18px; height: 18px;
  display: block;
  margin: 0 auto 3px;
  flex-shrink: 0;
}
.tab-full  { display: inline; }
.tab-short { display: none; }
@media (max-width: 480px) {
  .main-tab { font-size: 12px; padding: 10px 4px; line-height: 1.3; }
  .tab-full  { display: none; }
  .tab-short { display: inline; }
}
.main-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
@media (min-width: 600px) {
  .main-tab {
    flex-direction: row;
    gap: 6px;
  }
  .tab-icon { margin: 0; }
}

/* ===== タブコンテンツ ===== */
.tab-content { display: none; }
.tab-content.active { display: block; }
.content { padding: 12px; max-width: 960px; margin: 0 auto; }
@media (min-width: 768px) { .content { padding: 16px; } }

/* ===== アコーディオン ===== */
.accordion {
  background: #fff;
  border: 1px solid #e0e6ef;
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
}
.accordion-header {
  display: flex;
  align-items: center;
  padding: 13px 16px;
  cursor: pointer;
  user-select: none;
  min-height: 50px;
  gap: 10px;
  touch-action: manipulation;
}
.accordion-header:active { background: #f5f8ff; }
.accordion-title  { font-weight: bold; font-size: 14px; color: #1a3a5c; flex: 1; }
.accordion-status { font-size: 12px; color: #52c41a; }
.accordion-status.none { color: #bbb; }
.accordion-arrow  {
  font-size: 12px; color: #bbb;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.accordion.open .accordion-arrow { transform: rotate(180deg); }
.accordion-body {
  display: none;
  border-top: 1px solid #e8e8e8;
}
.accordion.open .accordion-body { display: block; }

/* アコーディオン内アクションバー */
.acc-action-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #f7f9fc;
  border-bottom: 1px solid #e8e8e8;
  flex-wrap: wrap;
}
.btn-action {
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid;
  min-height: 40px;
  touch-action: manipulation;
  white-space: nowrap;
  transition: opacity 0.1s;
}
.btn-action:active  { opacity: 0.7; }
.btn-action:disabled { opacity: 0.4; cursor: default; }
.btn-read  { background: #fff;      border-color: #1a3a5c; color: #1a3a5c; }
.btn-write { background: #1a3a5c;   border-color: #1a3a5c; color: #fff; }
.acc-status      { font-size: 12px; color: #888; flex: 1; text-align: right; }
.acc-status.ok   { color: #52c41a; }
.acc-status.err  { color: #ff4d4f; }
@media (max-width: 480px) {
  .btn-action { flex: 1; text-align: center; }
  .acc-status { flex-basis: 100%; text-align: left; }
}

/* ===== フォームテーブル ===== */
.form-table { width: 100%; border-collapse: collapse; }
.form-table th {
  background: #fafafa;
  padding: 10px 14px;
  text-align: left;
  font-weight: normal;
  color: #555;
  border-bottom: 1px solid #f0f0f0;
  width: 45%;
  font-size: 13px;
  vertical-align: middle;
}
.form-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
.form-table tr:last-child th,
.form-table tr:last-child td { border-bottom: none; }
.form-table tr:hover td,
.form-table tr:hover th { background: #fafbff; }

@media (max-width: 600px) {
  .form-table, .form-table tbody, .form-table tr,
  .form-table th, .form-table td { display: block; width: 100%; }
  .form-table th {
    background: #f7f9fc; padding: 8px 14px 4px;
    color: #888; font-size: 12px; border-bottom: none;
  }
  .form-table td { padding: 4px 14px 12px; }
  .form-table tr { border-bottom: 1px solid #f0f0f0; }
  .form-table tr:last-child { border-bottom: none; }
}

/* 入力部品 */
.current-val {
  display: inline-block; padding: 4px 10px;
  background: #f0f0f0; border-radius: 4px;
  color: #666; font-size: 13px; min-width: 60px; text-align: right;
}
.arrow { color: #bbb; margin: 0 8px; }
.unit  { color: #999; font-size: 12px; margin-left: 4px; }
.note  { color: #aaa; font-size: 11px; margin-left: 6px; }
.readonly-val {
  display: inline-block; padding: 4px 10px;
  background: #f5f5f5; border-radius: 4px; font-size: 13px;
}

input[type=number], input[type=text],
input[type=password], input[type=datetime-local], select {
  padding: 8px 10px;
  border: 1px solid #d9d9d9;
  border-radius: 5px;
  font-size: 14px;
  background: #fff;
  min-height: 40px;
  touch-action: manipulation;
}
input[type=number]  { width: 100px; }
input[type=text], input[type=password] { width: 100%; max-width: 260px; }
select { min-width: 130px; }
input:focus, select:focus {
  outline: none; border-color: #1a3a5c;
  box-shadow: 0 0 0 2px rgba(26,58,92,0.12);
}
.input-changed { border-color: #fa8c16 !important; background: #fff8f0 !important; }
.input-error   { border-color: #ff4d4f !important; background: #fff2f0 !important; }

.time-input { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.time-input input[type=number] { width: 64px; text-align: center; }

/* ビットフィールド */
.bitfield-section-label {
  padding: 8px 14px 4px;
  font-size: 13px; font-weight: bold; color: #555;
  background: #fafafa; border-top: 1px solid #f0f0f0;
}
.bit-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px; padding: 10px 14px 12px;
  background: #fff;
}
@media (min-width: 600px) { .bit-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .bit-grid { grid-template-columns: repeat(4, 1fr); } }
.bit-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 7px 8px; border-radius: 4px; cursor: pointer;
}
.bit-item:hover { background: #f5f8ff; }
.bit-item.reserved { color: #bbb; cursor: default; }
.bit-item input[type=checkbox] {
  width: 18px; height: 18px;
  accent-color: #1a3a5c;
  flex-shrink: 0; min-height: 0;
  cursor: pointer;
}
.bit-item.reserved input[type=checkbox] { cursor: default; }

/* ===== モニタカード ===== */
.monitor-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px; padding: 12px;
}
@media (min-width: 600px) { .monitor-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .monitor-grid { grid-template-columns: repeat(4, 1fr); } }
.monitor-card {
  background: #f7f9fc; border: 1px solid #e0e6ef;
  border-radius: 8px; padding: 12px; text-align: center;
}
.monitor-card-title { font-size: 11px; color: #888; margin-bottom: 6px; }
.monitor-value { font-size: 22px; font-weight: 600; color: #1a3a5c; font-family: 'Inter', sans-serif; font-variant-numeric: tabular-nums; }
.monitor-unit  { font-size: 12px; color: #999; margin-left: 2px; }
.monitor-empty { padding: 24px; text-align: center; color: #bbb; font-size: 13px; }
.monitor-table { width: 100%; border-collapse: collapse; }
.monitor-table td {
  padding: 9px 14px; border-bottom: 1px solid #f0f0f0;
  font-size: 13px; vertical-align: middle;
}
.monitor-table th {
  padding: 9px 14px; border-bottom: 1px solid #e8e8e8;
  font-size: 12px; font-weight: normal; color: #888;
  background: #fafafa; text-align: left;
}
.monitor-table td:first-child { color: #666; }
.monitor-table td:last-child  { text-align: right; font-weight: 500; }
.monitor-table tr:last-child td { border-bottom: none; }
.val-num  { color: #1a3a5c; }
.val-unit { color: #999; font-size: 11px; }

/* ===== M100設定 ===== */
.status-badge {
  font-size: 12px; padding: 3px 10px; border-radius: 10px;
}
.status-badge.connected    { background: #f6ffed; color: #389e0d; border: 1px solid #b7eb8f; }
.status-badge.disconnected { background: #fafafa; color: #999;    border: 1px solid #ddd; }
.acc-footer {
  display: flex; gap: 10px; padding: 10px 14px;
  border-top: 1px solid #eee; background: #fafafa; flex-wrap: wrap; align-items: center;
}

/* ===== 蓄電池パックタブ ===== */
.pack-tab {
  padding: 6px 14px; border: 1px solid #d9d9d9; border-radius: 4px;
  background: #fff; cursor: pointer; font-size: 13px; min-height: 34px;
}
.pack-tab.active { background: #1a3a5c; color: #fff; border-color: #1a3a5c; }
.bat-pack-panel { padding: 0; }

/* ===== 通信ログ ===== */
.log-area {
  background: #fff; border: 1px solid #e8e8e8;
  border-radius: 8px; margin: 0 12px 16px;
}
@media (min-width: 768px) { .log-area { margin: 0 16px 16px; } }
.log-header {
  display: flex; align-items: center; padding: 10px 14px;
  cursor: pointer; user-select: none; min-height: 46px; gap: 8px;
}
.log-header-title { flex: 1; font-weight: bold; font-size: 13px; color: #555; }
.log-body {
  height: 130px; overflow-y: auto; padding: 8px 12px;
  font-size: 11px; font-family: 'JetBrains Mono', 'Consolas', 'SF Mono', monospace;
  background: #fafafa; border-radius: 0 0 8px 8px;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid #eee;
}
.log-tx   { color: #1a3a5c; }
.log-rx   { color: #389e0d; }
.log-err  { color: #cf1322; }
.log-time { color: #bbb; margin-right: 6px; }
