/* css/style.css */

/* ===== リセット・共通 ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
                 "Noto Sans JP", sans-serif;
    background-color: #f5f5f5;
    color: #333;
    min-height: 100dvh;
    padding-bottom: 40px;
}

/* ===== PIN入力画面 ===== */
.pin-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 0;
}

.pin-container {
    background: #fff;
    border-radius: 16px;
    padding: 40px 32px;
    width: 100%;
    max-width: 360px;
    margin: 20px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.app-title {
    font-size: 2rem;
    font-weight: 700;
    color: #1a73e8;
    letter-spacing: 0.08em;
}

.app-subtitle {
    font-size: 0.85rem;
    color: #888;
    margin-top: 4px;
    margin-bottom: 32px;
}

.error-message {
    background: #fdecea;
    color: #d32f2f;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.pin-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.pin-label {
    font-size: 0.9rem;
    font-weight: 600;
    text-align: left;
}

.pin-input {
    font-size: 1.5rem;
    text-align: center;
    letter-spacing: 0.3em;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s;
}

.pin-input:focus {
    border-color: #1a73e8;
}

.pin-submit {
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: #1a73e8;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.pin-submit:hover {
    background: #1557b0;
}

.pin-submit:active {
    background: #0d47a1;
}

/* ===== ヘッダー ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1a73e8;
    color: #fff;
    padding: 10px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.1rem;
    letter-spacing: 0.05em;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.8);
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.nav-btn.active {
    background: rgba(255, 255, 255, 0.95);
    color: #1a73e8;
    font-weight: 600;
}

.nav-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.3);
}

.logout-link {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.8rem;
    margin-left: 4px;
}

.logout-link:hover {
    color: #fff;
}

/* ===== タブコンテンツ ===== */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===== セクション ===== */
.section {
    background: #fff;
    margin: 12px;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.section-title {
    font-size: 1rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 12px;
}

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-title-row .section-title {
    margin-bottom: 0;
}

/* ===== 現在の作業状況 ===== */
.current-work-section {
    padding: 0;
    overflow: hidden;
}

.current-work {
    padding: 20px 16px;
    text-align: center;
    transition: background 0.3s;
}

.current-work.idle {
    background: #f8f9fa;
}

.current-work.active {
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
}

.current-work-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #888;
    margin-bottom: 8px;
}

.current-work-info {
    font-size: 0.95rem;
    color: #555;
}

.current-work.active .current-work-info {
    color: #2e7d32;
}

.cw-client {
    font-weight: 700;
    display: block;
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.cw-project {
    display: block;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.cw-tasktype {
    display: inline-block;
    background: rgba(46, 125, 50, 0.15);
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.8rem;
    margin-top: 4px;
}

.cw-detail {
    display: block;
    font-size: 0.8rem;
    color: #666;
    margin-top: 6px;
}

.current-work-timer {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #2e7d32;
    margin-top: 8px;
}

.btn-stop {
    margin-top: 12px;
    background: #d32f2f;
    color: #fff;
    border: none;
    padding: 10px 32px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-stop:hover {
    background: #b71c1c;
}

/* ===== フォーム共通 ===== */
.record-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
}

.form-row {
    display: flex;
    gap: 12px;
    width: 100%;
    min-width: 0;
}

.form-group.half {
    flex: 1;
    min-width: 0;
}

.form-select,
.form-input,
.form-textarea {
    font-size: 0.95rem;
    padding: 10px 12px;
    border: 1.5px solid #ddd;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s;
    background: #fff;
    font-family: inherit;
    width: 100%;
}

input[type="datetime-local"] {
    min-width: 0;
    max-width: 100%;
}

.form-select:focus,
.form-input:focus,
.form-textarea:focus {
    border-color: #1a73e8;
}

.form-textarea {
    resize: vertical;
}

.date-input {
    width: auto;
    font-size: 0.85rem;
    padding: 6px 10px;
}

.select-or-new {
    display: flex;
    gap: 8px;
}

.select-or-new .form-select {
    flex: 1;
}

.new-input {
    flex: 0 0 40%;
    font-size: 0.85rem;
}

/* ===== ボタン ===== */
.btn {
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn-start {
    background: #1a73e8;
    color: #fff;
}

.btn-start:hover {
    background: #1557b0;
}

.btn-manual {
    background: #5c6bc0;
    color: #fff;
}

.btn-manual:hover {
    background: #3f51b5;
}

.btn-cancel {
    background: #eee;
    color: #333;
}

.btn-cancel:hover {
    background: #ddd;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.85rem;
    background: #1a73e8;
    color: #fff;
    border-radius: 6px;
}

.btn-small:hover {
    background: #1557b0;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 4px 8px;
    border-radius: 4px;
    color: #888;
    transition: background 0.2s, color 0.2s;
}

.btn-icon:hover {
    background: #f0f0f0;
    color: #333;
}

.btn-deactivate:hover {
    color: #d32f2f;
    background: #fdecea;
}

.btn-activate:hover {
    color: #2e7d32;
    background: #e8f5e9;
}

.hidden {
    display: none !important;
}

/* ===== 作業一覧 ===== */
.records-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.empty-message {
    text-align: center;
    color: #999;
    font-size: 0.9rem;
    padding: 20px 0;
}

.record-item {
    background: #fafafa;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 12px;
    position: relative;
}

.record-item.record-active {
    border-color: #4caf50;
    background: #f1f8f1;
}

.record-time {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 6px;
}

.record-duration {
    margin-left: 8px;
    font-weight: 600;
    color: #1a73e8;
}

.record-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}

.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

.tag-client {
    background: #e3f2fd;
    color: #1565c0;
}

.tag-project {
    background: #f3e5f5;
    color: #7b1fa2;
}

.tag-tasktype {
    background: #fff3e0;
    color: #e65100;
}

.record-detail {
    font-size: 0.8rem;
    color: #777;
    margin-top: 4px;
}

.record-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 2px;
}

.records-summary {
    text-align: right;
    font-size: 0.9rem;
    color: #555;
    padding-top: 12px;
    margin-top: 8px;
    border-top: 1px solid #eee;
}

/* ===== 管理画面 ===== */
.admin-add-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.admin-add-row .form-select,
.admin-add-row .form-input {
    flex: 1;
    min-width: 0;
}

.admin-add-row .btn-small {
    flex-shrink: 0;
}

.admin-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.admin-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #fafafa;
    border-radius: 6px;
    border: 1px solid #eee;
}

.admin-item.inactive {
    opacity: 0.5;
}

.admin-item-name {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 500;
}

.admin-item-sub {
    font-size: 0.75rem;
    color: #999;
    flex-shrink: 0;
}

.badge-inactive {
    font-size: 0.7rem;
    background: #eee;
    color: #999;
    padding: 1px 6px;
    border-radius: 4px;
}

.admin-item-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

/* ===== 設定 ===== */
.settings-block {
    margin-bottom: 20px;
}

.settings-block:last-child {
    margin-bottom: 0;
}

.settings-label {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: #555;
}

.settings-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.settings-form .form-input {
    flex: 1;
    min-width: 120px;
}

/* ===== モーダル ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal {
    background: #fff;
    border-radius: 12px;
    padding: 24px 20px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.modal-actions .btn {
    flex: 1;
}

/* ===== トースト通知 ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 300;
    transition: opacity 0.3s;
    max-width: 90%;
    text-align: center;
}

.toast.success {
    background: #2e7d32;
    color: #fff;
}

.toast.error {
    background: #d32f2f;
    color: #fff;
}

.toast.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ===== レスポンシブ ===== */
@media (max-width: 480px) {
    .section {
        margin: 8px;
        padding: 14px;
    }

    .select-or-new {
        flex-direction: column;
    }

    .new-input {
        flex: auto;
    }

    .form-row {
        flex-direction: column;
        gap: 8px;
    }

    .form-group.half {
        width: 100%;
    }

    .admin-add-row {
        flex-direction: column;
    }

    .settings-form {
        flex-direction: column;
    }

    .current-work-timer {
        font-size: 1.6rem;
    }
}

/* ===== ドラッグ＆ドロップ並べ替え ===== */
.drag-handle {
    cursor: grab;
    color: #bbb;
    font-size: 1.1rem;
    padding: 4px 6px;
    user-select: none;
    flex-shrink: 0;
    line-height: 1;
    transition: color 0.2s;
}

.drag-handle:hover {
    color: #666;
}

.drag-handle:active {
    cursor: grabbing;
}

.admin-item[draggable="true"] {
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.admin-item.dragging {
    opacity: 0.5;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: scale(1.02);
    z-index: 10;
    position: relative;
}

.admin-item.drag-over {
    border-top: 3px solid #1a73e8;
    padding-top: 5px;
}

.sortable-list {
    touch-action: pan-x;
}

/* ===== モード切り替え ===== */
.mode-toggle {
    display: flex;
    gap: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #1a73e8;
}

.mode-btn {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    background: #fff;
    color: #1a73e8;
}

.mode-btn.active {
    background: #1a73e8;
    color: #fff;
}

.mode-btn:not(.active):hover {
    background: #e8f0fe;
}

/* ===== ステップ式UI ===== */
.step-section {
    position: relative;
}

.step {
    display: none;
}

.step.active {
    display: block;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.step-title {
    font-size: 1rem;
    font-weight: 700;
    color: #333;
    flex: 1;
}

.step-indicator {
    font-size: 0.75rem;
    color: #999;
    flex-shrink: 0;
    background: #f0f0f0;
    padding: 2px 10px;
    border-radius: 10px;
}

.btn-back {
    background: none;
    border: 1.5px solid #ddd;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85rem;
    color: #666;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.2s, color 0.2s;
}

.btn-back:hover {
    border-color: #1a73e8;
    color: #1a73e8;
}

/* 選択済みタグ表示 */
.step-selected {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
}

.selected-tag {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
}

.selected-tag.tag-client {
    background: #e3f2fd;
    color: #1565c0;
}

.selected-tag.tag-project {
    background: #f3e5f5;
    color: #7b1fa2;
}

.selected-tag.tag-tasktype {
    background: #fff3e0;
    color: #e65100;
}

/* タグボタングリッド */
.tag-button-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}

.tag-btn {
    padding: 14px 12px;
    font-size: 0.9rem;
    font-weight: 600;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    background: #fff;
    color: #333;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.1s;
    text-align: center;
    word-break: break-all;
}

.tag-btn:hover {
    border-color: #bbb;
    background: #fafafa;
}

.tag-btn:active {
    transform: scale(0.97);
}

.tag-btn-client:hover,
.tag-btn-client.selected {
    border-color: #1565c0;
    background: #e3f2fd;
    color: #1565c0;
}

.tag-btn-project:hover,
.tag-btn-project.selected {
    border-color: #7b1fa2;
    background: #f3e5f5;
    color: #7b1fa2;
}

.tag-btn-tasktype:hover,
.tag-btn-tasktype.selected {
    border-color: #e65100;
    background: #fff3e0;
    color: #e65100;
}

/* 送信ボタン（大） */
.btn-large {
    width: 100%;
    padding: 16px;
    font-size: 1.1rem;
    margin-top: 8px;
}

/* ===== レスポンシブ追加 ===== */
@media (max-width: 480px) {
    .tag-button-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .tag-btn {
        padding: 12px 8px;
        font-size: 0.85rem;
    }

    .step-header {
        flex-wrap: wrap;
    }
}

/* ===== 履歴ヘッダーアクション ===== */
.history-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-icon-label {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #1a73e8;
    background: #e8f0fe;
    border: 1.5px solid #1a73e8;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.btn-icon-label:hover {
    background: #1a73e8;
    color: #fff;
}

.btn-icon-label:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.icon-mail {
    font-size: 1.1rem;
    line-height: 1;
}

@media (max-width: 480px) {
    .history-actions {
        gap: 6px;
    }

    .btn-icon-label span:last-child {
        display: none;
    }

    .btn-icon-label {
        padding: 6px 10px;
    }
}
