/* ==========================================================================
   1. Base Variables & Reset
   ========================================================================== */
:root {
    /* Colors */
    --primary: #0056b3;
    --primary-dark: #004494;
    --primary-light: #e7f1ff;
    --header-bg: #0f2346;
    --header-text: #ffffff;
    
    --bg-body: #f4f6f9;
    --bg-card: #ffffff;
    --text-main: #2d3748;
    --text-sub: #718096;
    --border: #e2e8f0;
    
    --danger: #e53e3e;
    --success: #38a169;
    --warning-bg: #fffaf0;
    
    /* Layout Sizes */
    --header-h: 60px;
    --sidebar-w: 260px;
    --radius: 6px;
    --z-header: 100;
    --z-sidebar: 90;
    --z-overlay: 80;
    --z-footer: 50;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    margin: 0;
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    font-size: 15px;
    line-height: 1.6;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }

/* ==========================================================================
   2. Header (Always Fixed Top)
   ========================================================================== */
.app-header {
    position: fixed;
    top: 0; left: 0; width: 100%;
    height: var(--header-h);
    background-color: var(--header-bg);
    color: var(--header-text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: var(--z-header);
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.header-left { display: flex; align-items: center; gap: 16px; }

/* Hamburger Button */
.menu-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px; height: 36px;
    background: transparent; border: none; padding: 0;
}
.menu-icon-bar {
    display: block;
    background: #fff;
    width: 24px; height: 2px;
    border-radius: 2px;
}

.app-logo {
    font-weight: bold;
    font-size: 18px;
    display: flex; align-items: center; gap: 8px;
}

.user-menu { display: flex; align-items: center; gap: 10px; }
.user-name-pc { font-size: 13px; display: none; } /* Mobile hidden */
.user-avatar {
    width: 32px; height: 32px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: bold;
}

/* ==========================================================================
   3. Sidebar & Layout
   ========================================================================== */
.app-layout {
    margin-top: var(--header-h); /* ヘッダーの高さ分下げる */
    display: flex;
    min-height: calc(100vh - var(--header-h));
}

.sidebar {
    position: fixed;
    top: var(--header-h); left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: #fff;
    z-index: var(--z-sidebar);
    border-right: 1px solid var(--border);
    transform: translateX(-100%); /* Mobile Default: Hidden */
    transition: transform 0.3s ease;
    display: flex; flex-direction: column;
}

.sidebar.is-active {
    transform: translateX(0); /* Mobile Open */
    box-shadow: 4px 0 15px rgba(0,0,0,0.1);
}

.sidebar-inner {
    flex: 1;
    overflow-y: auto;
    display: flex; flex-direction: column;
}

/* Overlay for Mobile */
.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: var(--z-overlay);
    opacity: 0; visibility: hidden;
    transition: opacity 0.3s;
}
.sidebar-overlay.is-active {
    opacity: 1; visibility: visible;
}

/* Mobile Profile Area */
.mobile-profile {
    padding: 20px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    display: flex; gap: 12px; align-items: center;
}
.profile-icon { font-size: 24px; }
.company { font-size: 13px; font-weight: bold; margin: 0; }
.role { font-size: 11px; color: var(--text-sub); margin: 2px 0 0; }

/* Nav Items */
.sidebar-nav { padding: 16px 0; }
.nav-section {
    font-size: 11px; font-weight: bold; color: #a0aec0;
    padding: 16px 20px 8px; text-transform: uppercase;
}
.nav-sub-label {
    font-size: 11px; color: #cbd5e0;
    padding: 8px 20px 4px 34px;
}
.nav-item {
    display: flex; align-items: center;
    padding: 10px 20px;
    font-size: 14px; color: var(--text-main);
    gap: 10px; border-left: 4px solid transparent;
}
.nav-item:hover { background: #f7fafc; color: var(--primary); }
.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}
.nav-item .icon { width: 20px; text-align: center; }

/* Accordion */
details summary {
    padding: 12px 20px;
    font-weight: 600; color: var(--text-sub);
    list-style: none; display: flex; justify-content: space-between; cursor: pointer;
}
details summary::after { content: '+'; }
details[open] summary::after { content: '-'; }
.nav-group { background: #fcfcfc; padding-bottom: 8px; }
.nav-group .nav-item { padding-left: 32px; font-size: 13px; }

/* ==========================================================================
   4. Main Content
   ========================================================================== */
.main-content {
    flex: 1;
    width: 100%;
    padding: 20px 16px;
    padding-bottom: 100px;
    transition: margin-left 0.3s;
}

/* Page Components */
.page-section { margin-bottom: 60px; }
.divider { border: 0; border-top: 1px dashed var(--border); margin: 40px 0; }
.page-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 20px; gap: 12px;
}
.breadcrumb { font-size: 12px; color: var(--text-sub); margin-bottom: 4px; }
.page-title { font-size: 22px; margin: 0; font-weight: 700; }

/* Common UI Elements */
.btn {
    display: inline-flex; justify-content: center; align-items: center;
    height: 44px; padding: 0 20px;
    border-radius: var(--radius); border: 1px solid transparent;
    font-size: 14px; font-weight: 600; transition: all 0.2s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text-main); }
.btn-danger-outline { background: #fff; border-color: #fed7d7; color: var(--danger); }
.btn-text { background: transparent; color: var(--text-sub); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-shadow { box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.plus { margin-right: 4px; font-weight: bold; }
.full-width { width: 100%; }

.card {
    background: #fff; border: 1px solid var(--border);
    border-radius: var(--radius); margin-bottom: 20px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05); overflow: hidden;
}
.card-title {
    font-size: 16px; margin: 16px 20px 12px;
    border-bottom: 2px solid #f0f0f0; padding-bottom: 8px; display: inline-block;
}

/* Search Card */
.search-header {
    padding: 16px; font-weight: 600; color: var(--primary);
    cursor: pointer; background: #fff;
}
.search-body { padding: 0 16px 20px; }
.search-form { display: flex; flex-direction: column; gap: 16px; }

/* Form Elements */
.form-item { margin-bottom: 20px; }
label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 700; color: #4a5568; }
.required::after { content: " *"; color: var(--danger); }
.form-control {
    width: 100%; height: 46px; padding: 8px 12px;
    border: 1px solid var(--border); border-radius: var(--radius);
    font-size: 16px; background: #fff; color: var(--text-main);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,86,179,0.1); }
.bg-read { background: #edf2f7; cursor: not-allowed; }
.select-wrap { position: relative; }
.select-wrap::after { content: "▼"; font-size: 10px; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: #718096; pointer-events: none; }
.input-group { display: flex; gap: 8px; }

/* Table Mobile */
.table-container { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { display: none; }
.data-table tbody tr { display: block; padding: 16px; border-bottom: 1px solid var(--border); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table td { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border: none; }
.data-table td::before { content: attr(data-label); font-size: 12px; color: var(--text-sub); font-weight: 600; }
.main-text { display: block; width: 100%; margin-top: 4px; font-size: 16px; }
.data-table td[data-label="操作"] { border-top: 1px dashed #eee; margin-top: 12px; padding-top: 12px; }
.data-table td[data-label="操作"]::before { display: none; }
.font-mono { font-family: monospace; }
.text-right { text-align: right; }

/* Badges */
.badge { padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 700; display: inline-block; }
.badge-sent { background: var(--primary-light); color: var(--primary); }
.badge-draft { background: #edf2f7; color: #4a5568; }

/* Detail Page Utils */
.alert { padding: 16px; background: #ebf8ff; color: #2c5282; border-radius: var(--radius); border-left: 4px solid #4299e1; margin-bottom: 20px; }
.detail-header-card { background: #fff; padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; }
.detail-meta { display: flex; justify-content: space-between; margin-bottom: 8px; }
.detail-actions { display: flex; gap: 8px; overflow-x: auto; }
.detail-actions button { flex: 1; white-space: nowrap; }

.tabs-wrapper { overflow-x: auto; margin-bottom: 20px; }
.tabs { display: flex; gap: 16px; border-bottom: 1px solid var(--border); min-width: max-content; }
.tab { background: none; border: none; padding: 12px 4px; font-size: 14px; font-weight: 600; color: var(--text-sub); border-bottom: 3px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.info-list { margin: 0; padding: 20px; font-size: 14px; }
.info-row { display: flex; border-bottom: 1px solid #f0f0f0; padding: 8px 0; }
.info-row dt { width: 100px; color: var(--text-sub); }
.info-row dd { flex: 1; margin: 0; font-weight: 600; }

.card-header-color { background: var(--header-bg); padding: 12px 20px; color: #fff; }
.card-body { padding: 20px; }

.sticky-footer {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: rgba(255,255,255,0.95); backdrop-filter: blur(5px);
    border-top: 1px solid var(--border); padding: 12px 16px;
    display: flex; justify-content: space-between; align-items: center; z-index: var(--z-footer);
}
.footer-actions { display: flex; gap: 8px; }

/* ==========================================================================
   5. Desktop Overrides (min-width: 1024px)
   ========================================================================== */
@media (min-width: 1024px) {
    .app-header { padding: 0 32px; }
    .menu-btn { display: none; } /* PCではハンバーガー消去 */
    .user-name-pc { display: inline-block; color: #fff; font-weight: 500; }
    
    /* Sidebar: Always Visible on PC */
    .sidebar {
        transform: none; /* 常時表示 */
        box-shadow: none;
    }
    .mobile-profile { display: none; }
    
    /* Main Content: Push right by sidebar width */
    .main-content {
        margin-left: var(--sidebar-w);
        padding: 32px;
        max-width: 1200px;
    }
    
    /* Search Bar Horizontal */
    .search-card details summary { display: none; }
    .search-card details { display: block; }
    .search-body { padding: 24px; }
    .search-form { flex-direction: row; align-items: flex-end; }
    .form-item { margin-bottom: 0; flex: 1; }
    .form-actions { flex: 0 0 auto; display: flex; gap: 12px; }
    
    /* Table Desktop */
    .data-table { display: table; }
    .data-table thead { display: table-header-group; background: #f8fafc; }
    .data-table th { padding: 12px 16px; text-align: left; color: #718096; font-size: 12px; border-bottom: 2px solid var(--border); }
    .data-table tbody tr { display: table-row; }
    .data-table tbody tr:hover { background: #f0f9ff; }
    .data-table td { display: table-cell; padding: 14px 16px; border-bottom: 1px solid var(--border); }
    .data-table td::before { display: none; }
    .data-table td[data-label="操作"] { border-top: none; padding: 14px 16px; }

    /* Layout Utilities */
    .form-layout { display: flex; gap: 24px; align-items: flex-start; }
    .form-card { flex: 1; margin-bottom: 0; }
    .sticky-footer { left: var(--sidebar-w); padding: 20px 32px; justify-content: flex-end; gap: 24px; }
}
/* ==========================================================================
   6. Utilities & Missing Classes (added for mock pages)
   ========================================================================== */
.text-muted { color: var(--text-sub); font-weight: 500; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.small { font-size: 12px; color: var(--text-sub); }
.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 6px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    background: #edf2f7;
    color: #4a5568;
    margin-left: 6px;
}

/* More Status Badges */
.badge-ordered { background: #ebf8ff; color: #2c5282; }
.badge-open { background: #edf2f7; color: #4a5568; }
.badge-paid { background: #f0fff4; color: var(--success); }
.badge-delayed { background: var(--warning-bg); color: #b7791f; border: 1px solid #fbd38d; }
.badge-out { background: #fff1f2; color: var(--danger); border: 1px solid #fed7d7; }

/* Simple dashboard grid */
.dashboard-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1024px) {
  .dashboard-grid { grid-template-columns: repeat(4, 1fr); }
}
.kpi-card { padding: 16px 20px; }
.kpi-title { font-size: 12px; color: var(--text-sub); margin: 0 0 8px; font-weight: 700; }
.kpi-value { font-size: 22px; margin: 0; font-weight: 800; }
.kpi-sub { margin: 6px 0 0; font-size: 12px; color: var(--text-sub); }

/* Auth pages */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}
.auth-card { max-width: 560px; width: 100%; }
.auth-title { font-size: 20px; margin: 0 0 12px; font-weight: 800; }
.auth-sub { margin: 0 0 16px; color: var(--text-sub); font-size: 13px; }


/* Alert variants */
.alert-info { background: #ebf8ff; color: #2c5282; border-left-color: #4299e1; }
.alert-warn { background: var(--warning-bg); color: #b7791f; border-left-color: #ecc94b; }
.alert-error { background: #fff5f5; color: #c53030; border-left-color: #fc8181; }
.alert-success { background: #f0fff4; color: #2f855a; border-left-color: #68d391; }

/* ==========================================================================
   99. Fixes to match current HTML structure
   ========================================================================== */

/* app-body がCSS上の app-layout 相当になるように補完 */
.app-body {
  margin-top: var(--header-h);
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

/* mainがはみ出るのを止める（flexの定番） */
.main-content {
  min-width: 0;
}

/* header: 現在HTMLに合わせて .logo / .avatar を効かせる */
.logo {
  font-weight: 800;
  letter-spacing: .02em;
  font-size: 18px;
  color: #fff;
}

.tenant-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.tenant-name { font-size: 12px; opacity: .95; }
.tenant-role { font-size: 11px; opacity: .8; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: rgba(255,255,255,.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 12px;
  color: #fff;
}

/* sidebar header blocks */
.sidebar__header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar__brand a {
  font-weight: 800;
  display: inline-block;
  margin-bottom: 6px;
  color: var(--text-main);
}

.sidebar__tenant-name { font-weight: 700; }
.sidebar__tenant-type { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

/* sidebar footer */
.sidebar__footer { padding: 12px 16px; border-top: 1px solid var(--border); }

/* nav: 現状の active / nav-item を揃える */
.sidebar__nav .nav-item.active,
.sidebar__nav .nav-item.is-active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 700;
}

/* ===== Desktop: sidebar 開閉ボタンを有効化 ===== */
@media (min-width: 1024px) {
  /* PCでもハンバーガーを出す（開閉したい要望対応） */
  .menu-btn { display: flex; }

  /* main幅制御：max-width固定を外して“はみ出し”を防ぐ */
  .main-content {
    max-width: none;
    width: auto;
  }

  /* デフォルトはサイドバー表示 */
  .sidebar { transform: translateX(0); }
  .main-content { margin-left: var(--sidebar-w); }

  /* 閉じた時（JSで付与する .is-collapsed を使う） */
  .sidebar.is-collapsed { transform: translateX(-100%); }
  .main-content.is-collapsed { margin-left: 0; }

  /* PCではオーバーレイ不要 */
  .sidebar-overlay { display: none; }
}

