:root {
    --accent: #b5443c;
    --accent-dark: #8f342d;
    --bg: #faf7f2;
    --panel: #ffffff;
    --border: #e3dcd0;
    --text: #2c2622;
    --muted: #7a7267;
    --pos: #2e7d32;
    --neg: #c62828;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.app-header {
    background: var(--accent);
    color: #fff;
    padding: 0.8rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.brand { font-weight: bold; font-size: 1.15rem; }

.main-nav { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.main-nav a {
    color: #fff;
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.92rem;
    opacity: 0.88;
}

.main-nav a:hover { background: rgba(255,255,255,0.15); opacity: 1; }
.main-nav a.active { background: rgba(255,255,255,0.25); opacity: 1; font-weight: bold; }

.container {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 0 1.2rem 3rem;
}

.app-footer {
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    padding: 1.5rem;
}

h1 { font-size: 1.5rem; margin-bottom: 0.3rem; }
h2 { font-size: 1.15rem; margin-top: 2rem; color: var(--accent-dark); border-bottom: 2px solid var(--border); padding-bottom: 0.3rem;}
.subtitle { color: var(--muted); margin-bottom: 1.5rem; }

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 1rem; }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.1rem;
}
.card .value { font-size: 1.6rem; font-weight: bold; color: var(--accent-dark); }
.card .label { color: var(--muted); font-size: 0.85rem; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; margin-top: 0.9rem; }
label:first-child { margin-top: 0; }

input[type=text], input[type=number], input[type=date], select, textarea {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    background: #fff;
    color: var(--text);
    font-family: inherit;
}

textarea { min-height: 60px; resize: vertical; }

.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 160px; }

button, .btn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.55rem 1.2rem;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    margin-top: 1.2rem;
    display: inline-block;
    text-decoration: none;
}
button:hover, .btn:hover { background: var(--accent-dark); }
button.secondary, .btn.secondary { background: #6d675e; }
button.small { padding: 0.3rem 0.7rem; font-size: 0.82rem; margin-top: 0; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    font-size: 0.9rem;
}
table caption { text-align: left; font-weight: bold; margin-bottom: 0.5rem; }
th, td {
    border: 1px solid var(--border);
    padding: 0.5rem 0.6rem;
    text-align: right;
}
th:first-child, td:first-child, th.text, td.text { text-align: left; }
thead th {
    background: #f3ece1;
    color: var(--accent-dark);
    position: sticky;
    top: 0;
}
tbody tr:hover { background: #fbf5ec; }
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--border);}
.table-wrap table { border: none; }
.table-wrap th, .table-wrap td { border-left: none; border-right: none; }

.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }

.alert { padding: 0.7rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-success { background: #e6f4ea; color: #2e7d32; border: 1px solid #b7dfc0; }
.alert-error { background: #fdecea; color: #c62828; border: 1px solid #f5c6c2; }

.material-row { display: flex; gap: 0.7rem; align-items: flex-end; margin-bottom: 0.6rem; padding: 0.6rem; background: #faf7f2; border-radius: 6px; border: 1px solid var(--border); }
.material-row > div { flex: 1; }
.material-row .remove-row { flex: 0 0 auto; }
.remove-row { background: #c62828; padding: 0.5rem 0.7rem; margin-top: 0; }
.remove-row:hover { background: #a41f1f; }

.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; background: #f3ece1; color: var(--accent-dark); font-size: 0.78rem; }

.tag-group { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }

.process-fields { display: none; }
.process-fields.active { display: block; }

.chart-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 1.2rem; margin-top: 1rem; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

/* ==========================================================
   スマートフォン対応
   ========================================================== */

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 6px;
    margin: 0;
    padding: 0;
    cursor: pointer;
}
.nav-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: #fff;
    margin: 0 auto;
}

@media (max-width: 780px) {
    .app-header { padding: 0.7rem 1rem; }
    .brand { font-size: 1rem; }
    .nav-toggle { display: flex; }

    .main-nav {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 0.3rem;
        margin-top: 0.7rem;
    }
    .main-nav.open { display: flex; }
    .main-nav a {
        padding: 0.75rem 0.9rem;
        font-size: 1rem;
        background: rgba(255,255,255,0.08);
    }
    .main-nav a.active { background: rgba(255,255,255,0.25); }

    .container { padding: 0 0.8rem 2.5rem; margin: 1rem auto; }

    h1 { font-size: 1.25rem; }
    h2 { font-size: 1.05rem; }

    .panel { padding: 1rem; }

    /* フォーム項目は1カラムで縦積み、iOSの自動ズームを防ぐためfont-sizeは16px以上に */
    .form-row { flex-direction: column; gap: 0; }
    .form-row > div { min-width: 0; }

    input[type=text], input[type=number], input[type=date], select, textarea {
        font-size: 16px;
        padding: 0.65rem 0.7rem;
    }

    /* ボタンはタップしやすい大きさに、幅いっぱいに広げる */
    button, .btn {
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
    button.small, .btn.small { width: auto; min-height: 40px; padding: 0.5rem 0.9rem; }

    .material-row { flex-direction: column; align-items: stretch; gap: 0.5rem; }
    .material-row .remove-row { width: 100%; }

    table { font-size: 0.82rem; }
    th, td { padding: 0.45rem 0.55rem; white-space: nowrap; }

    .table-wrap { -webkit-overflow-scrolling: touch; }

    /* 資材一覧の非表示・削除ボタンは縦積みにして誤タップを防ぐ */
    td .material-actions { display: flex; flex-direction: column; gap: 0.4rem; }
    td .material-actions form { width: 100%; }
    td .material-actions button { width: 100%; }
    td .material-actions a { width: 100%; box-sizing: border-box; text-align: center; }

    .grid { grid-template-columns: 1fr 1fr; }
    .card { padding: 0.85rem; }
    .card .value { font-size: 1.3rem; }

    .chart-wrap { padding: 0.8rem; }
}

@media (max-width: 420px) {
    .grid { grid-template-columns: 1fr; }
}
