/* =========================================
   変数定義 (Color Palette)
   ========================================= */
:root {
    /* ライトモード (デフォルト) */
    --bg-color: #f4f6f8;
    --card-bg: #ffffff;
    --text-color: #333333;
    --sub-text: #666666;
    --border-color: #e0e0e0;
    --header-bg: #ffffff;
    --primary-color: #007bff;
    /* メインの青 */
    --accent-color: #e3f2fd;
    /* 薄い青 (シフト表示の背景) */
    --danger-color: #ff4d4f;
    --icon-color: #555555;

    /* 入力エリアの高さ */
    --input-height: 44px;
}

[data-theme="dark"] {
    /* ダークモード */
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-color: #e0e0e0;
    --sub-text: #aaaaaa;
    --border-color: #333333;
    --header-bg: #1e1e1e;
    --accent-color: #1565c0;
    /* ダークモード時のシフト背景 */
    --icon-color: #e0e0e0;
}

/* =========================================
   基本リセット & 全体設定
   ========================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    padding-bottom: 100px;
    transition: background-color 0.3s, color 0.3s;
    font-size: 16px;
}

/* =========================================
   ヘッダー (Header)
   ========================================= */
header {
    position: sticky;
    top: 0;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    height: 60px;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.app-title {
    font-weight: bold;
    font-size: 1.1rem;
    white-space: nowrap;
}

.icon {
    width: 28px;
    height: 28px;
    stroke: var(--icon-color);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    cursor: pointer;
}

/* =========================================
   サイドメニュー (Sidebar)
   ========================================= */
.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background-color: var(--card-bg);
    z-index: 200;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding-top: 70px;
    border-right: 1px solid var(--border-color);
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar.open {
    left: 0;
}

.sidebar-item {
    padding: 16px 24px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    font-weight: 500;
    font-size: 1.1rem;
}

.sidebar-item:active {
    background-color: var(--bg-color);
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 150;
    display: none;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s;
}

.overlay.open {
    display: block;
    opacity: 1;
}

/* =========================================
   ページ制御 & ナビゲーション
   ========================================= */
.page {
    display: none;
    padding: 15px;
    max-width: 900px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.nav-month {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 20px;
    font-size: 1.1rem;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

button {
    padding: 0 16px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

button:active {
    background-color: var(--border-color);
}

/* =========================================
   カレンダービュー (Calendar) - 画像合わせ
   ========================================= */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background-color: var(--border-color);
    /* 枠線 */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.calendar-cell {
    background-color: var(--card-bg);
    min-height: 80px;
    /* ある程度の高さを確保 */
    padding: 6px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

/* 曜日ヘッダー */
.calendar-cell.header {
    background-color: var(--bg-color);
    font-weight: bold;
    min-height: 35px;
    justify-content: center;
    padding: 8px 0;
    color: var(--sub-text);
    font-size: 0.9rem;
}

.date-num {
    font-weight: bold;
    margin-bottom: 6px;
    font-size: 1rem;
    color: var(--text-color);
}

/* シフト時間の青いボックス */
.shift-time {
    background-color: var(--accent-color);
    color: var(--primary-color);
    font-size: 0.8rem;
    font-weight: bold;
    text-align: center;
    line-height: 1.25;
    border-radius: 6px;
    padding: 6px 0;
    width: 90%;
    max-width: 50px;
    /* 幅を制限して縦長ボックスっぽく */
}

/* =========================================
   シフト登録テーブル (Registry Table)
   ========================================= */
.table-container {
    background-color: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-bottom: 60px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 100%;
}

th,
td {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    background-color: var(--bg-color);
    font-weight: 600;
    font-size: 0.9rem;
}

td {
    font-size: 0.95rem;
}

/* =========================================
   フォーム部品
   ========================================= */
input[type="time"],
input[type="number"],
select {
    height: var(--input-height);
    padding: 0 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 16px;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    text-align: center;
}

input:disabled,
select:disabled {
    opacity: 0.3;
    background-color: var(--border-color);
}

/* トグルスイッチ */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 30px;
    vertical-align: middle;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* =========================================
   ボタン類
   ========================================= */
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    height: 50px;
    font-weight: bold;
    width: 100%;
    border-radius: 8px;
    font-size: 1.1rem;
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.3);
}

.btn-primary:active {
    transform: scale(0.98);
}

.floating-save {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    z-index: 90;
}

.btn-copy {
    width: 100%;
    margin-top: 15px;
    background-color: var(--card-bg);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    height: 48px;
    font-weight: bold;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* =========================================
   収入計算 & その他
   ========================================= */
.income-display {
    text-align: center;
    padding: 20px;
    background-color: var(--card-bg);
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.income-display .amount {
    font-size: 2.2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 10px 0;
}

.tab-menu {
    display: flex;
    margin-bottom: 20px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    border: none;
    border-radius: 0;
    height: 44px;
    background-color: var(--card-bg);
    font-weight: bold;
}

.tab-btn.active {
    background-color: var(--primary-color);
    color: white;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
}

#simple-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 200px;
    padding-top: 20px;
    border-bottom: 1px solid var(--border-color);
}

.bar-group {
    width: 6%;
}

/* =========================================
   ローディング
   ========================================= */
.loading-spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 20px 40px;
    border-radius: 12px;
    z-index: 999;
    font-weight: bold;
}

/* =========================================
   レスポンシブ微調整
   ========================================= */
@media (max-width: 768px) {
    .page {
        padding: 10px;
    }

    .calendar-cell {
        min-height: 70px;
    }

    .date-num {
        font-size: 0.9rem;
    }

    .shift-time {
        font-size: 0.75rem;
        padding: 4px 0;
    }

    th,
    td {
        font-size: 0.85rem;
        padding: 8px 4px;
    }

    .bar-group {
        width: 5%;
    }

    .bar-label {
        font-size: 0.6rem;
    }

    .income-display .amount {
        font-size: 1.8rem;
    }
}