:root {
    --blue-dark: #1a3a5c;
    --blue-main: #1e6db5;
    --blue-mid: #2e86de;
    --blue-light: #a8d4f5;
    --blue-pale: #e8f4fd;
    --white: #ffffff;
    --gray-light: #f4f7fa;
    --gray-mid: #cdd8e3;
    --gray-text: #555f6d;
    --danger: #e74c3c;
    --success: #27ae60;
    --table-column-base-width: 100px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', 'Meiryo UI', Meiryo, sans-serif;
    background: var(--gray-light);
    color: #2c3e50;
    min-height: 100vh;
}

/* ヘッダー */
.header {
    background: linear-gradient(135deg, var(--blue-dark), var(--blue-main));
    color: var(--white);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 1px;
    text-decoration: none;
    color: var(--white);
}

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

/* ===== ハンバーガーメニュー ===== */

/* ロゴ左側のラッパー（ハンバーガーボタン＋ロゴを横並び） */
.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative; /* ドロップダウンの基点 */
}

/* ハンバーガーボタン（3本線アイコン） */
.hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 5px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border-radius: 4px;
    transition: background 0.2s;
    flex-shrink: 0;
}
.hamburger-btn:hover {
    background: rgba(255,255,255,0.18);
}
.hamburger-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background: rgba(255,255,255,0.95);
    border-radius: 2px;
    transition: transform 0.25s, opacity 0.25s;
}
/* 開いているとき: 3本線を × に変形 */
.hamburger-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger-btn.open span:nth-child(2) { opacity: 0; transform: scaleX(0); }
.hamburger-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ドロップダウンメニュー本体 */
.hamburger-menu {
    position: absolute;
    top: calc(100% + 12px);
    left: 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.18);
    min-width: 230px;
    z-index: 2000;
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.18s, transform 0.18s;
    overflow: hidden;
}
.hamburger-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
/* セクション見出し */
.hamburger-menu .menu-section {
    padding: 8px 16px 4px;
    font-size: 10px;
    color: var(--gray-text);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    background: var(--gray-light);
    border-bottom: 1px solid var(--gray-mid);
}
/* メニューリンク */
.hamburger-menu a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    color: var(--blue-dark);
    text-decoration: none;
    font-size: 14px;
    border-bottom: 1px solid #eef0f3;
    transition: background 0.13s, color 0.13s;
}
.hamburger-menu a:last-child { border-bottom: none; }
.hamburger-menu a:hover {
    background: var(--blue-pale);
    color: var(--blue-main);
}
.hamburger-menu a.menu-active {
    color: var(--blue-main);
    font-weight: 600;
    background: var(--blue-pale);
    border-left: 3px solid var(--blue-main);
}

.header-user {
    font-size: 14px;
    opacity: 0.9;
}

.font-size-control {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.15);
    padding: 4px 12px;
    border-radius: 20px;
}

.font-size-control label {
    font-size: 12px;
    white-space: nowrap;
}

.font-size-control input[type=range] {
    width: 80px;
    accent-color: var(--blue-light);
}

.font-size-value {
    font-size: 12px;
    min-width: 28px;
    text-align: center;
}

/* ナビゲーション */
.nav {
    background: var(--blue-main);
    padding: 0 24px;
    display: flex;
    gap: 0;
}

.nav a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 10px 18px;
    font-size: 14px;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav a:hover,
.nav a.active {
    color: var(--white);
    border-bottom-color: var(--blue-light);
    background: rgba(255,255,255,0.1);
}

/* メインコンテンツ */
.main {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.page-title {
    font-size: 22px;
    font-weight: bold;
    color: var(--blue-dark);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--blue-light);
}

/* カード */
.card {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(30,109,181,0.1);
    padding: 24px;
    margin-bottom: 20px;
}

.card-title {
    font-size: 16px;
    font-weight: bold;
    color: var(--blue-dark);
    margin-bottom: 16px;
}

/* ボタン */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: 5px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
    line-height: 1;
}

.btn-primary {
    background: var(--blue-main);
    color: var(--white);
}

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

.btn-secondary {
    background: var(--white);
    color: var(--blue-main);
    border: 1px solid var(--blue-main);
}

.btn-secondary:hover {
    background: var(--blue-pale);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-sm {
    padding: 4px 12px;
    font-size: 13px;
}

/* フォーム */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--blue-dark);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--gray-mid);
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--white);
}

.form-control:focus {
    outline: none;
    border-color: var(--blue-mid);
    box-shadow: 0 0 0 3px rgba(46,134,222,0.15);
}

/* テーブル */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead th {
    background: var(--blue-main);
    color: var(--white);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--gray-mid);
    transition: background 0.15s;
}

tbody tr:hover {
    background: var(--blue-pale);
}

tbody td {
    padding: 9px 14px;
}

/* テーブルフィールド内の入力フィールド */
table input.form-control {
    width: 100%;
    padding: 4px 6px;
    font-size: 13px;
    box-sizing: border-box;
    border-radius: 3px;
}

table input.table-calc-cell {
    background: #fffbea;
    border-color: #f0c040;
    cursor: not-allowed;
}

/* ログイン画面 */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--blue-dark) 0%, var(--blue-mid) 100%);
}

.login-box {
    background: var(--white);
    border-radius: 12px;
    padding: 40px 36px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo h1 {
    font-size: 28px;
    color: var(--blue-main);
    font-weight: bold;
    letter-spacing: 2px;
}

.login-logo p {
    color: var(--gray-text);
    font-size: 13px;
    margin-top: 4px;
}

/* アプリカード */
.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.app-card {
    background: var(--white);
    border: 1px solid var(--gray-mid);
    border-radius: 8px;
    padding: 20px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
    display: block;
    position: relative;
}

.app-card:hover {
    border-color: var(--blue-mid);
    box-shadow: 0 4px 16px rgba(30,109,181,0.15);
    transform: translateY(-2px);
}

.app-card-icon {
    width: 44px;
    height: 44px;
    background: var(--blue-pale);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin-bottom: 12px;
}

.app-card-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--blue-dark);
    margin-bottom: 4px;
}

.app-card-meta {
    font-size: 12px;
    color: var(--gray-text);
}

.app-card-new {
    border: 2px dashed var(--blue-light);
    background: var(--blue-pale);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    color: var(--blue-main);
    font-weight: 600;
}

.app-card-new:hover {
    background: var(--white);
    border-color: var(--blue-main);
}

/* ビルダー */
.builder-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 20px;
    align-items: start;
}

.field-palette {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(30,109,181,0.1);
    padding: 16px;
    position: sticky;
    top: 76px;
}

.field-palette h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--blue-dark);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.palette-item {
    background: var(--blue-pale);
    border: 1px solid var(--blue-light);
    border-radius: 5px;
    padding: 8px 12px;
    margin-bottom: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--blue-dark);
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
    transition: all 0.15s;
}

.palette-item:hover {
    background: var(--blue-light);
    box-shadow: 0 2px 6px rgba(30, 109, 181, 0.2);
}

.palette-item:active {
    background: var(--blue-main);
    color: var(--white);
}

.field-canvas {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(30,109,181,0.1);
    padding: 20px;
    min-height: 400px;
}

.field-canvas h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--blue-dark);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--gray-mid);
}

.field-drop-zone {
    min-height: 300px;
    border: 2px dashed var(--gray-mid);
    border-radius: 6px;
    padding: 12px;
    transition: border-color 0.2s, background 0.2s;
    /* グリッドレイアウトはJS/PHPから inline style で設定するため、
       ここではgridの基本設定のみ（列数はinline styleで上書きされる） */
    display: grid;
    grid-template-columns: 1fr; /* デフォルト1列（JSが更新する） */
    align-content: start;       /* アイテムを上詰めにする */
    width: 100%;  /* 親コンテナの幅に合わせる */
    box-sizing: border-box;  /* パディング含めた幅計算 */
}

.field-drop-zone.drag-over {
    border-color: var(--blue-mid);
    background: var(--blue-pale);
}

.field-drop-zone-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--gray-text);
    font-size: 14px;
}

.field-item {
    background: var(--blue-pale);
    border: 1px solid var(--blue-light);
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: grab;
    position: relative;
}

.field-item:active {
    cursor: grabbing;
}

.field-item-drag {
    color: var(--gray-text);
    font-size: 16px;
}

.field-item-info {
    flex: 1;
}

.field-item-label {
    font-weight: 600;
    font-size: 14px;
    color: var(--blue-dark);
}

.field-item-type {
    font-size: 11px;
    color: var(--gray-text);
    margin-top: 2px;
}

.field-item-actions {
    display: flex;
    gap: 6px;
}

/* →↓ サイズ拡張ボタン */
.btn-span {
    background: var(--blue-pale);
    border: 1px solid var(--blue-light);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 13px;
    cursor: pointer;
    color: var(--blue-dark);
    line-height: 1.4;
    transition: background 0.15s;
}
.btn-span:hover {
    background: var(--blue-light);
}
/* リセットボタン（✕）は赤みがかった色 */
.btn-span-reset {
    background: #fdecea;
    border-color: #f5c6cb;
    color: var(--danger);
}
.btn-span-reset:hover {
    background: #f5c6cb;
}

/* アラート */
.alert {
    padding: 10px 16px;
    border-radius: 5px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-danger {
    background: #fdecea;
    color: var(--danger);
    border: 1px solid #f5c6cb;
}

.alert-success {
    background: #d4edda;
    color: var(--success);
    border: 1px solid #c3e6cb;
}

/* バッジ */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.badge-blue {
    background: var(--blue-pale);
    color: var(--blue-main);
}

/* 一般ユーザーバッジ（グレー） */
.badge-gray {
    background: #eef0f3;
    color: #666;
}

/* ページネーション */
.pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-top: 20px;
}

.pagination a,
.pagination span {
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid var(--gray-mid);
    font-size: 13px;
    text-decoration: none;
    color: var(--blue-main);
}

.pagination .current {
    background: var(--blue-main);
    color: var(--white);
    border-color: var(--blue-main);
}

/* モーダル */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--white);
    border-radius: 10px;
    padding: 28px;
    width: 480px;
    max-width: 95vw;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-title {
    font-size: 17px;
    font-weight: bold;
    color: var(--blue-dark);
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ユーティリティ */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-right { text-align: right; }
.text-sm { font-size: 13px; }
.text-gray { color: var(--gray-text); }
.text-blue { color: var(--blue-main); }
.w-full { width: 100%; }
.required::after { content: ' *'; color: var(--danger); }
