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

:root {
    --early: #3b82f6;   /* 早番: 青 */
    --late: #8b5cf6;     /* 遅番: 紫 */
    --mid: #eab308;      /* 中番: 黄 */
    --off: #ef4444;      /* 休み: 赤 */
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #1e293b;
    --text-sub: #64748b;
    --border: #e2e8f0;
    --primary: #3b82f6;
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    background: var(--bg);
    color: var(--text);
    padding-bottom: 70px;
    -webkit-tap-highlight-color: transparent;
}

.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 16px;
}

/* 明日のシフト */
.tomorrow-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-sub);
    margin-bottom: 12px;
}

.tomorrow-shift {
    text-align: center;
    padding: 16px;
    border-radius: 8px;
    background: #f1f5f9;
}

.tomorrow-date { font-size: 14px; color: var(--text-sub); margin-bottom: 4px; }
.tomorrow-type { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.tomorrow-time { font-size: 16px; color: var(--text-sub); }

.shift-早番 { background: #eff6ff; }
.shift-早番 .tomorrow-type { color: var(--early); }
.shift-遅番 { background: #f5f3ff; }
.shift-遅番 .tomorrow-type { color: var(--late); }
.shift-中番 { background: #fefce8; }
.shift-中番 .tomorrow-type { color: #a16207; }
.shift-休み { background: #fef2f2; }
.shift-休み .tomorrow-type { color: var(--off); }

.no-data {
    text-align: center;
    padding: 24px;
    color: var(--text-sub);
}
.no-data p { margin-bottom: 16px; }

/* カレンダー */
.calendar-section {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.month-title {
    font-size: 18px;
    font-weight: 700;
}

.nav-arrow {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f1f5f9;
    text-decoration: none;
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0;
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
}

.weekday-header {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-sub);
    padding: 4px 0;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.weekday-header.sat { color: var(--early); }
.weekday-header.sun { color: var(--off); }

.day-cell {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 3px 1px;
    cursor: pointer;
    position: relative;
    min-height: 52px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.day-cell:active { background: #f1f5f9; }
.day-cell.empty { cursor: default; }
.day-cell.today { background: #eff6ff; box-shadow: inset 0 0 0 2px var(--primary); }
.day-cell.has-note::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #22c55e;
}

.day-number {
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
}

.shift-tag {
    font-size: 11px;
    font-weight: 700;
    margin-top: 2px;
    line-height: 1.2;
}

.shift-label {
    font-size: 11px;
    font-weight: 700;
    margin-top: 2px;
    line-height: 1.3;
}

.tag-早番 { color: var(--early); }
.tag-遅番 { color: var(--late); }
.tag-中番 { color: #a16207; }
.tag-休み { color: var(--off); }
.tag-不明 { color: #9ca3af; }

.day-cell.day-off {
    background: rgba(239, 68, 68, 0.12);
}
.day-cell.day-off .day-number {
    color: var(--off);
    font-weight: 700;
}
.day-cell.day-off .shift-label {
    color: var(--off);
}

.day-count {
    font-size: 8px;
    color: var(--text-sub);
    margin-top: 1px;
}

.day-breakdown {
    font-size: 6px;
    color: var(--text-sub);
    margin-top: 0;
    white-space: nowrap;
    line-height: 1;
}

.day-budget {
    font-size: 7px;
    color: #16a34a;
    font-weight: 600;
    margin-top: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* 凡例 */
.legend {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-sub);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    display: inline-block;
}
.legend-dot.tag-早番 { background: var(--early); }
.legend-dot.tag-遅番 { background: var(--late); }
.legend-dot.tag-中番 { background: var(--mid); }
.legend-dot.tag-休み { background: var(--off); }

/* モーダル */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: flex-end;
    justify-content: center;
}
.modal.show { display: flex; }

.modal-content {
    background: var(--card);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 70vh;
    overflow-y: auto;
    padding: 20px;
    animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
    width: 32px; height: 32px;
    border: none; background: #f1f5f9;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

.modal-note {
    background: #f0fdf4;
    color: #166534;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 8px;
}

.modal-budget {
    background: #fefce8;
    color: #a16207;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
}

.modal-summary {
    background: #f1f5f9;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
}

.shift-row {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.shift-row:last-child { border-bottom: none; }
.shift-row.is-me { background: #eff6ff; margin: 0 -20px; padding: 10px 20px; border-radius: 6px; }

.shift-name { font-weight: 600; min-width: 50px; font-size: 14px; }
.shift-type-badge {
    font-size: 11px; font-weight: 700; color: #fff;
    padding: 2px 8px; border-radius: 4px;
}
.shift-time { color: var(--text-sub); font-size: 13px; margin-left: auto; }
.no-shifts { color: var(--text-sub); text-align: center; padding: 20px; }

/* ボトムナビ */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    gap: 0;
    padding: 8px 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-sub);
    padding: 4px 32px;
    transition: color 0.15s;
}
.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 10px; margin-top: 2px; }

/* ボタン */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: #2563eb; }
.btn-secondary { background: #f1f5f9; color: var(--text); margin-top: 8px; }
.btn-danger { background: #fee2e2; color: #dc2626; margin-top: 8px; }

/* データ管理 */
.data-manage {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* アップロード */
.upload-step { margin-top: 8px; }

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: var(--card);
}
.upload-area:active { background: #f1f5f9; }
.upload-icon { font-size: 48px; }
.upload-hint { font-size: 12px; color: var(--text-sub); }

.preview-img {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 12px;
}

/* ローディング */
.loading {
    text-align: center;
    padding: 60px 20px;
    background: var(--card);
    border-radius: var(--radius);
}

.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-hint { font-size: 12px; color: var(--text-sub); margin-top: 8px; }

/* 結果 */
.result-header { margin-bottom: 12px; }
.result-header h3 { font-size: 18px; font-weight: 700; }

.name-select {
    background: var(--card);
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.name-select label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.name-select select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    background: #fff;
}

.result-preview {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.result-section { margin-bottom: 12px; }
.result-section h4 { font-size: 14px; font-weight: 600; margin-bottom: 8px; color: var(--text-sub); }
.result-note { font-size: 13px; padding: 4px 0; color: #166534; }
.result-staff { font-size: 14px; padding: 4px 0; }

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* 成功 */
.success-message {
    text-align: center;
    padding: 40px 20px;
    background: var(--card);
    border-radius: var(--radius);
}
.success-icon {
    width: 60px; height: 60px;
    background: #22c55e;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin: 0 auto 16px;
}
.success-message p { margin-bottom: 20px; font-size: 16px; }

/* エラー */
.error-area {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 16px;
    color: #dc2626;
    text-align: center;
}
.error-area p { margin-bottom: 12px; }

/* ログイン */
.login-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px 24px;
    margin-top: 80px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.login-title {
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 24px;
}
.login-error {
    background: #fef2f2;
    color: #dc2626;
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
    text-align: center;
    margin-bottom: 16px;
}
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}
.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
}
.btn-full { width: 100%; margin-top: 8px; }

/* 編集ボタン */
.edit-btn {
    width: 28px; height: 28px;
    border: none; background: #f1f5f9;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.edit-btn:active { background: #e2e8f0; }

/* 編集モーダル */
.edit-form { padding: 4px 0; }
.edit-name {
    font-size: 16px; font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.edit-type-buttons {
    display: flex; gap: 8px;
}
.type-btn {
    flex: 1;
    padding: 10px 0;
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    color: #fff;
    transition: border-color 0.15s, transform 0.1s;
}
.type-btn.selected {
    border-color: var(--text);
    transform: scale(1.05);
}
.edit-time-row {
    display: flex; align-items: center; gap: 8px;
}
.edit-time-row input[type="time"] {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
}
.edit-time-row span {
    font-size: 16px; color: var(--text-sub);
}

/* 元画像 */
.source-image-btn {
    margin-top: 12px;
}
.source-image {
    width: 100%;
    border-radius: 8px;
}
.image-modal-body {
    min-height: 100px;
}
