/* =====================================================
   KANA :: ESTIMATE UI — REBUILD (STABLE)
   HTML NON-TOUCH / TABLE SAFE
   ===================================================== */

/* ---------- Tokens ---------- */
:root {
    --bg: radial-gradient(900px 400px at 50% -10%, #eef2ff 0%, #f8fafc 45%, #eef2f7 100%);
    --panel: #ffffff;
    --sub-bg: #f8fafc;

    --text: #0f172a;
    --muted: #64748b;
    --line: rgba(15, 23, 42, .08);

    --accent: #4f46e5;
    --accent-soft: rgba(99, 102, 241, .18);

    --r-lg: 18px;
    --r-md: 12px;

    --shadow-main:
        0 32px 72px rgba(15, 23, 42, .18),
        0 2px 0 rgba(255, 255, 255, .9) inset;

    --shadow-sub:
        0 8px 18px rgba(15, 23, 42, .12);
}

/* ---------- Base ---------- */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 40px;
    font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    background: var(--bg);
    color: var(--text);
}



/* ---------- Heading ---------- */
h1 {
    font-size: 26px;
    margin: 0 0 20px;
    letter-spacing: .02em;
}

/* ---------- Buttons ---------- */
button {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: .15s;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sub);
}

/* ---------- Table ---------- */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--panel);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-main);
    overflow: hidden;
}

thead th {
    padding: 14px;
    font-size: 12px;
    color: #475569;
    background: linear-gradient(to bottom, #f9fafb, #f1f5f9);
    border-bottom: 1px solid var(--line);
}

tbody td {
    padding: 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

/* ---------- Inputs ---------- */
input,
select {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: #fff;
}

input:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    outline: none;
}

input[readonly] {
    background: #f1f5f9;
    font-weight: 600;
}

/* 数値 */
.qty,
.cost,
.price,
.h,
.u,
.parent-subtotal,
.sub-subtotal {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* =====================================================
   MAIN ROW
   ===================================================== */
tbody tr:not(.sub-row) td {
    background: linear-gradient(to bottom, #fff, #f8fafc);
    font-weight: 600;
}

tbody tr:not(.sub-row) td:first-child {
    position: relative;
}

tbody tr:not(.sub-row) td:first-child::before {
    content: "MAIN";
    position: absolute;
    top: -8px;
    left: 0;
    font-size: 10px;
    letter-spacing: .12em;
    color: var(--accent);
    font-weight: 700;
}

/* ---------- price block (横並び固定) ---------- */
.price-block {
    display: grid;
    grid-template-columns: auto 110px auto 120px auto;
    gap: 10px;
    align-items: center;
}

.price-block .field {
    display: contents;
}

.price-block .cap {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.price-block input {
    width: 110px;
    text-align: right;
}

/* 操作列 */
td:last-child {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    white-space: nowrap;
}

/* =====================================================
   SUB ROW = CARD STACK
   ===================================================== */
.sub-row td {
    background: linear-gradient(to right, #f8fafc, #f1f5f9);
    position: relative;
    box-shadow: var(--shadow-sub);
}

/* card shape */
.sub-row td:first-child {
    border-top-left-radius: 14px;
    border-bottom-left-radius: 14px;
    border-left: 4px solid var(--accent-soft);
}

.sub-row td:last-child {
    border-top-right-radius: 14px;
    border-bottom-right-radius: 14px;
}

/* visual stack */
.sub-row+.sub-row td {
    transform: translateY(-6px);
}

.sub-row {
    position: relative;
    z-index: 1;
}

.sub-row+.sub-row {
    z-index: 2;
}

.sub-row+.sub-row+.sub-row {
    z-index: 3;
}

tbody tr:not(.sub-row)+.sub-row td {
    transform: none;
}

.sub-row:hover td {
    box-shadow: 0 14px 30px rgba(15, 23, 42, .2);
    z-index: 10;
}

/* ---------- sub: time & unit inline ---------- */
.sub-row td:nth-child(2) {
    display: flex;
    align-items: center;
    gap: 14px;
    white-space: nowrap;
}

.sub-row td:nth-child(2) input {
    width: 90px;
}

/* ---------- conditions ---------- */
.sub-row label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 12px;
    font-size: 12px;
    color: var(--muted);
}

label input[type="checkbox"] {
    margin: 0;
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* ---------- totals ---------- */
.parent-subtotal {
    font-size: 16px;
    font-weight: 700;
}

.sub-subtotal {
    font-size: 14px;
    font-weight: 700;
}

.total {
    margin-top: 24px;
    padding: 18px 22px;
    background: linear-gradient(135deg, #111827, #1f2937);
    color: #fff;
    border-radius: var(--r-lg);
    font-size: 26px;
    font-weight: 800;
    letter-spacing: .06em;
}

/* ---------- maintenance ---------- */
body.maintenance-on table {
    box-shadow:
        var(--shadow-main),
        0 0 0 2px rgba(99, 102, 241, .35),
        0 0 40px rgba(99, 102, 241, .25);
}

/* ---------- responsive ---------- */
@media (max-width: 960px) {
    body {
        padding: 20px;
    }

    .price-block {
        grid-template-columns: 1fr;
    }
}

/* =====================================================
   MOBILE MODE — CARD INPUT
   ===================================================== */
@media (max-width: 768px) {

    thead {
        display: none;
    }

    table,
    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    tbody tr {
        margin-bottom: 18px;
    }

    /* MAIN row */
    tbody tr:not(.sub-row) td {
        background: #fff;
        border-bottom: none;
        padding: 10px 14px;
    }

    /* SUB row = card */
    .sub-row td {
        background: var(--sub-bg);
        margin: 0;
        box-shadow: var(--shadow-sub);
    }

    .sub-row td+td {
        border-top: 1px dashed var(--line);
    }

    /* 各セルを縦並びに */
    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
    }

    td input,
    td select {
        max-width: 60%;
    }

    /* price block 縦積み */
    .price-block {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    /* 操作ボタン */
    td:last-child {
        justify-content: flex-start;
    }

    /* 合計は常に目立たせる */
    .total {
        font-size: 22px;
        text-align: center;
    }
}


.estimate {
    max-width: 1100px;
    max-height: 82vh;
    overflow-y: auto;
    margin: 0 auto;
}


.item-card {
    background: #fff;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, .18);
    margin-bottom: 24px;
}

.item-header {
    display: grid;
    grid-template-columns: 140px 1fr 1fr 100px;
    gap: 12px;
    margin-bottom: 16px;
}

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

.subtasks {
    display: flex;
    flex-direction: column;
    gap: 0px;
}

.sub-card {
    background: #f8fafc;
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .12);
    display: grid;
    grid-template-columns: 160px 1fr 1fr 120px auto;
    gap: 12px;
    align-items: center;
}

.sub-total {
    font-weight: 700;
    text-align: right;
}