/* ========== 基本 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --primary: #4a90d9; --primary-dark: #3a7bc8;
    --danger: #dc3545; --success: #28a745;
    --gray-100: #f8f9fa; --gray-200: #e9ecef; --gray-300: #dee2e6;
    --gray-500: #adb5bd; --gray-600: #6c757d; --gray-700: #495057; --gray-800: #343a40;
    --holiday-bg: #ffebee; --holiday-text: #c62828;
    --saturday-bg: #e3f2fd; --saturday-text: #1565c0;
}
body { font-family: 'Hiragino Kaku Gothic ProN', 'メイリオ', sans-serif; background: var(--gray-100); color: var(--gray-800); line-height: 1.5; }

/* ========== ヘッダー ========== */
.main-header { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white; padding: 0.6rem 1rem; display: flex; justify-content: space-between; align-items: center; }
.main-header h1 { font-size: 1.1rem; }
.main-nav { display: flex; gap: 0.3rem; }
.main-nav a { color: rgba(255,255,255,0.85); text-decoration: none; padding: 0.4rem 0.8rem; border-radius: 4px; font-size: 0.85rem; }
.main-nav a:hover { background: rgba(255,255,255,0.15); }
.main-nav a.active { background: rgba(255,255,255,0.25); font-weight: 600; }

/* ========== ダッシュボード ========== */
.dashboard { padding: 1rem; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; max-width: 1200px; margin: 0 auto; }
.panel { background: white; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.panel.full-width { grid-column: 1 / -1; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 1rem; background: var(--gray-100); border-bottom: 1px solid var(--gray-200); }
.panel-header h2 { font-size: 0.95rem; color: var(--gray-700); }
.panel-content { padding: 0.8rem; max-height: 300px; overflow-y: auto; }

/* ========== 編集アイテム ========== */
.edit-item { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0.6rem; margin-bottom: 0.3rem; background: var(--gray-100); border-radius: 4px; font-size: 0.85rem; }
.edit-item:hover { background: var(--gray-200); }
.edit-item .item-info { flex: 1; overflow: hidden; }
.edit-item .item-name { font-weight: 500; }
.edit-item .item-sub { font-size: 0.75rem; color: var(--gray-600); }
.edit-item .item-actions button, .item-actions button { background: none; border: none; cursor: pointer; padding: 2px 4px; font-size: 0.85rem; opacity: 0.6; }
.edit-item .item-actions button:hover, .item-actions button:hover { opacity: 1; }

/* ========== ボタン ========== */
.btn-add { background: var(--primary); color: white; border: none; padding: 0.4rem 0.8rem; border-radius: 4px; cursor: pointer; font-size: 0.8rem; }
.btn-add:hover { background: var(--primary-dark); }
.btn-primary { background: var(--primary); color: white; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.btn-secondary { background: white; color: var(--gray-700); border: 1px solid var(--gray-300); padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.btn-cancel { background: var(--gray-200); color: var(--gray-700); border: none; padding: 0.4rem 0.8rem; border-radius: 4px; cursor: pointer; }
.btn-save { background: var(--primary); color: white; border: none; padding: 0.4rem 1rem; border-radius: 4px; cursor: pointer; }
.add-btn { width: 100%; padding: 0.5rem; background: var(--primary); color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 0.8rem; margin-top: 0.5rem; }

/* ========== モーダル ========== */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); justify-content: center; align-items: center; z-index: 1000; }
.modal.active { display: flex; }
.modal-content { background: white; border-radius: 6px; width: 90%; max-width: 400px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 1rem; border-bottom: 1px solid var(--gray-200); }
.modal-header h3 { font-size: 1rem; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--gray-500); }
form { padding: 1rem; }
.form-group { margin-bottom: 0.8rem; }
.form-group label { display: block; margin-bottom: 0.3rem; font-size: 0.85rem; color: var(--gray-700); }
.form-group .required { color: var(--danger); }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 0.5rem; border: 1px solid var(--gray-300); border-radius: 4px; font-size: 0.9rem; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); }
.form-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; }
.announce { font-size: 0.8rem; color: #e65100; margin-top: 0.3rem; }
.data-actions { display: flex; gap: 0.8rem; flex-wrap: wrap; }

/* ========== 出面表・工程表レイアウト ========== */
.demmen-layout, .koutei-layout { display: flex; height: calc(100vh - 50px); }
.site-selector { width: 260px; background: white; border-right: 1px solid var(--gray-200); display: flex; flex-direction: column; overflow: hidden; }
.selector-header { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--gray-200); background: var(--gray-100); }
.selector-header h3 { font-size: 0.9rem; }
.panel-tabs { display: flex; border-bottom: 1px solid var(--gray-200); background: var(--gray-100); }
.panel-tab { padding: 0.5rem 0.6rem; cursor: pointer; border: none; background: none; font-size: 0.8rem; border-bottom: 2px solid transparent; }
.panel-tab.active { border-bottom-color: var(--primary); font-weight: 600; }
.panel-section { display: none; padding: 0.5rem; overflow-y: auto; flex: 1; }
.panel-section.active { display: block; }
.site-list { flex: 1; overflow-y: auto; padding: 0.5rem; }
.site-item-selector { padding: 0.5rem; margin-bottom: 0.3rem; background: var(--gray-100); border-radius: 4px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; }
.site-item-selector:hover { background: var(--gray-200); }
.copy-mode-toggle { padding: 0.5rem; font-size: 0.8rem; }
.copy-indicator { padding: 0.5rem; background: #fff3cd; border-top: 1px solid #ffc107; display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; }
.copy-indicator button { background: var(--gray-700); color: white; border: none; padding: 0.2rem 0.5rem; border-radius: 3px; cursor: pointer; font-size: 0.75rem; }

/* ========== メインエリア ========== */
.demmen-main, .koutei-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.demmen-controls, .koutei-controls { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 1rem; background: white; border-bottom: 1px solid var(--gray-200); }
.month-selector { display: flex; align-items: center; gap: 0.4rem; }
.month-selector button { background: var(--gray-200); border: none; padding: 0.3rem 0.6rem; border-radius: 4px; cursor: pointer; }
.month-selector input { padding: 0.3rem 0.5rem; border: 1px solid var(--gray-300); border-radius: 4px; }
.demmen-actions, .koutei-actions { display: flex; gap: 0.5rem; }

/* ========== テーブル ========== */
.demmen-table-wrapper, .koutei-table-wrapper { flex: 1; overflow: auto; background: white; }
.demmen-table, .koutei-table { border-collapse: collapse; font-size: 0.75rem; white-space: nowrap; }
.demmen-table th, .demmen-table td, .koutei-table th, .koutei-table td { border: 1px solid var(--gray-300); padding: 0.25rem 0.3rem; text-align: center; }
.demmen-table th, .koutei-table th { background: var(--gray-100); font-weight: 600; position: sticky; top: 0; z-index: 10; }
.sticky-col { position: sticky; left: 0; background: white; z-index: 5; }
.demmen-table th.sticky-col, .koutei-table th.sticky-col { z-index: 15; }
.date-col { width: 25px; min-width: 25px; }
.day-name-col { width: 20px; min-width: 20px; }
.person-col { min-width: 70px; max-width: 100px; text-align: center; overflow: hidden; text-overflow: ellipsis; }
.partner-header { background: #f0f7ff !important; }
.count-col { width: 35px; min-width: 35px; }
.item-col { min-width: 100px; text-align: left; }
.day-col { min-width: 28px; }
.total-row { background: var(--gray-100); font-weight: 600; }
.total-row td { border-top: 2px solid var(--gray-400); }
.total-cell { text-align: center; }
.holiday, .holiday-row td { background: var(--holiday-bg) !important; color: var(--holiday-text) !important; }
.saturday, .saturday-row td { background: var(--saturday-bg) !important; color: var(--saturday-text) !important; }
.holiday-row .cell, .saturday-row .cell { background: inherit !important; }
.holiday-row .cell:hover, .saturday-row .cell:hover { opacity: 0.8; }

/* ========== セル ========== */
.cell { cursor: pointer; min-height: 24px; position: relative; font-size: 0.7rem; overflow: hidden; text-overflow: ellipsis; }
.cell:hover { background: #e8f4fc; }
.cell.selected { background: #bbdefb !important; outline: 2px solid var(--primary); outline-offset: -2px; }
.partner-site-cell { background: #fafafa; }
.count-cell { padding: 0 !important; }
.partner-count { width: 100%; height: 100%; border: none; background: transparent; text-align: center; font-size: 0.75rem; padding: 0.2rem; }
.partner-count:focus { background: white; outline: 1px solid var(--primary); }
.koutei-cell { min-width: 28px; min-height: 28px; }

/* ========== カレンダー ========== */
.calendar-main { padding: 1rem; max-width: 1200px; margin: 0 auto; }
.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.calendar-header h2 { font-size: 1.1rem; }
.calendar-controls select { padding: 0.3rem; border: 1px solid var(--gray-300); border-radius: 4px; }
.calendar-actions { display: flex; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.calendar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.8rem; margin-bottom: 1.5rem; }
.calendar-month { background: white; border-radius: 6px; padding: 0.8rem; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.calendar-month h4 { text-align: center; margin-bottom: 0.5rem; font-size: 0.9rem; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.day-header { text-align: center; font-size: 0.65rem; font-weight: 600; color: var(--gray-500); padding: 0.2rem; }
.day-header.sun { color: var(--holiday-text); }
.day-header.sat { color: var(--saturday-text); }
.day-cell { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; border-radius: 3px; cursor: pointer; position: relative; }
.day-cell:hover { background: var(--gray-200); }
.day-cell.sunday { color: var(--holiday-text); }
.day-cell.saturday { color: var(--saturday-text); }
.day-cell.national-holiday { background: #fff8e1; }
.day-cell.holiday-selected { background: var(--holiday-bg) !important; color: var(--holiday-text); font-weight: 600; }
.nh-mark { position: absolute; top: 0; right: 0; font-size: 0.45rem; color: #ff9800; }
.holiday-list-section { background: white; border-radius: 6px; padding: 1rem; }
.holiday-list-section h3 { margin-bottom: 0.8rem; font-size: 0.95rem; }
.holiday-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.holiday-item { display: flex; align-items: center; gap: 0.4rem; background: var(--gray-100); padding: 0.3rem 0.6rem; border-radius: 4px; font-size: 0.8rem; }
.holiday-item button { background: none; border: none; cursor: pointer; color: var(--gray-500); font-size: 0.9rem; }
.no-data { text-align: center; color: var(--gray-500); padding: 1rem; font-size: 0.85rem; }

/* ========== 元請けバッジ ========== */
.client-badge {
    display: inline-block;
    background: #333;
    color: white;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    margin-right: 2px;
    vertical-align: middle;
}
.form-hint { font-size: 0.75rem; color: var(--gray-500); margin-top: 0.2rem; }

/* ========== 印刷 ========== */
@media print {
    .main-header, .site-selector, .demmen-controls, .koutei-controls, .calendar-controls, .calendar-actions { display: none !important; }
    .demmen-layout, .koutei-layout { display: block; height: auto; }
    .demmen-main, .koutei-main { overflow: visible; }
    .demmen-table-wrapper, .koutei-table-wrapper { overflow: visible; height: auto; }
}

@media (max-width: 1200px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .calendar-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) {
    .demmen-layout, .koutei-layout { flex-direction: column; }
    .site-selector { width: 100%; max-height: 180px; }
    .calendar-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ========== バックアップ ========== */
.btn-success { background: var(--success); color: white; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.btn-success:hover { background: #218838; }
.btn-warning { background: #ffc107; color: #212529; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.btn-warning:hover { background: #e0a800; }

.backup-list { max-height: 400px; overflow-y: auto; }
.backup-item { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.8rem; margin-bottom: 0.4rem; background: var(--gray-100); border-radius: 4px; border-left: 3px solid var(--gray-300); }
.backup-item.latest { border-left-color: var(--success); background: #f0fff0; }
.backup-info { display: flex; align-items: center; gap: 1rem; }
.backup-date { font-weight: 500; font-size: 0.9rem; }
.backup-size { color: var(--gray-600); font-size: 0.8rem; }
.backup-badge { background: var(--success); color: white; font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: 3px; }
.backup-actions { display: flex; gap: 0.4rem; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.75rem; border-radius: 3px; cursor: pointer; border: none; }
.btn-restore { background: var(--primary); color: white; }
.btn-restore:hover { background: var(--primary-dark); }
.btn-delete { background: var(--gray-300); color: var(--gray-700); }
.btn-delete:hover { background: var(--danger); color: white; }
.data-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
