* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", sans-serif; background: #f4f6f8; color: #222; }
.hidden { display: none !important; }

.login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-box { background: #fff; padding: 40px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.1); width: 320px; text-align: center; }
.login-box h1 { font-size: 18px; margin-bottom: 20px; }
.login-box input { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; }
.login-box button { width: 100%; padding: 10px; background: #2c5282; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
.error { color: #c53030; font-size: 13px; min-height: 18px; }

.app { display: flex; height: 100vh; }
.sidebar { width: 220px; background: #1a2332; color: #fff; display: flex; flex-direction: column; padding: 16px 0; flex-shrink: 0; }
.sidebar h2 { font-size: 16px; padding: 0 16px 12px; margin: 0; border-bottom: 1px solid #2d3a4f; }
.sidebar nav { flex: 1; display: flex; flex-direction: column; margin-top: 8px; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; color: #cbd5e0; text-decoration: none; padding: 10px 16px; font-size: 14px; }
.sidebar nav a:hover, .sidebar nav a.active { background: #2c5282; color: #fff; }
.sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; fill: currentColor; }
.logout { margin: 12px 16px 0; padding: 8px; background: #4a5568; color: #fff; border: none; border-radius: 4px; cursor: pointer; }

.main-content { flex: 1; padding: 24px; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
h3 { margin-top: 0; flex-shrink: 0; }

.table-wrap { overflow: auto; max-width: 100%; flex: 1; min-height: 200px; border: 1px solid #e2e8f0; border-radius: 4px; }
table { width: 100%; border-collapse: collapse; background: #fff; font-size: 12px; }
th, td { border: 1px solid #e2e8f0; padding: 5px 7px; text-align: left; white-space: nowrap; }
th { background: #edf2f7; position: sticky; top: 0; z-index: 1; }
tr:hover { background: #f9fafb; }
td[contenteditable="true"] { cursor: text; }
td[contenteditable="true"]:focus { outline: 2px solid #2c5282; outline-offset: -2px; background: #fffbea; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; flex-shrink: 0; }
.toolbar input, .toolbar select { padding: 6px; border: 1px solid #ccc; border-radius: 4px; }
button { padding: 6px 14px; background: #2c5282; color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 13px; }
button.secondary { background: #718096; }
button.danger { background: #c53030; }
button:hover { opacity: .9; }
button:disabled { opacity: .5; cursor: not-allowed; }

.upload-box { background: #fff; border-radius: 8px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 20px; flex-shrink: 0; }
.upload-box .file-list { font-size: 12px; color: #718096; margin-top: 8px; }
.status-line { font-size: 13px; margin-top: 10px; }
.status-line.ok { color: #2f855a; }
.status-line.err { color: #c53030; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #cbd5e0; border-top-color: #2c5282; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; padding: 24px; border-radius: 8px; width: 640px; max-height: 85vh; overflow-y: auto; }
.modal h3 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.form-grid label { display: flex; flex-direction: column; font-size: 12px; color: #4a5568; gap: 4px; }
.form-grid input, .form-grid select, .form-grid textarea { padding: 6px; border: 1px solid #ccc; border-radius: 4px; font-size: 13px; }
.modal-actions { margin-top: 16px; display: flex; gap: 8px; justify-content: flex-end; }

/* ---- 請求管理 追加分 ---- */
.login-sub { margin: -12px 0 18px; color: #718096; font-size: 13px; }
.me { padding: 10px 16px 0; font-size: 12px; color: #a0aec0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-shrink: 0; }
.page-head h3 { margin: 0; font-size: 20px; }
.card { background: #fff; border-radius: 8px; padding: 16px 20px; box-shadow: 0 1px 3px rgba(0,0,0,.08); margin-bottom: 16px; flex-shrink: 0; }
.muted { color: #718096; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.clickable { cursor: pointer; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 11px; color: #fff; }
.badge.draft { background: #a0aec0; } .badge.circulating { background: #dd6b20; } .badge.approved { background: #2f855a; } .badge.paid { background: #2c5282; }
.progress { display: inline-block; min-width: 54px; }
.progress.done { color: #2f855a; font-weight: 600; }
.mine { background: #fff5f5; color: #c53030; border-radius: 8px; padding: 1px 7px; font-size: 11px; margin-left: 4px; }
button.ghost { background: #fff; color: #2c5282; border: 1px solid #2c5282; }
button.big { padding: 12px 28px; font-size: 15px; }
button.ok { background: #2f855a; }
button.sm { padding: 2px 8px; font-size: 11px; }

.detail { display: grid; grid-template-columns: minmax(300px, 1fr) minmax(420px, 1.1fr); gap: 16px; flex: 1; min-height: 0; }
.viewer { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; min-height: 480px; }
.viewer iframe, .viewer .imgwrap { flex: 1; width: 100%; border: 0; min-height: 0; }
.viewer .imgwrap { overflow: auto; } .viewer img { max-width: 100%; display: block; }
.viewer .empty { margin: auto; color: #a0aec0; }
.side { overflow-y: auto; min-height: 0; padding-right: 4px; }
.hdr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.hdr-grid label { display: flex; flex-direction: column; font-size: 11px; color: #4a5568; gap: 3px; }
.hdr-grid input, .hdr-grid select { padding: 6px; border: 1px solid #cbd5e0; border-radius: 4px; font-size: 13px; }
.hdr-grid .full { grid-column: 1 / -1; }
.items { width: 100%; }
.items td { white-space: normal; vertical-align: middle; }
.items input { width: 100%; padding: 4px 6px; border: 1px solid #cbd5e0; border-radius: 3px; font-size: 12px; }
.items input.amt { text-align: right; width: 96px; }
.items tr.mineRow { background: #fffaf0; }

/* 印鑑 */
.hanko { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%; font-size: 12px; font-weight: 700; margin: 1px 3px 1px 0; border: 2px solid #cbd5e0; color: #a0aec0; border-style: dashed; background: #fff; user-select: none; }
.hanko.done { border: 2px solid #c53030; color: #c53030; border-style: solid; transform: rotate(-8deg); background: #fff5f5; }
.hanko.me { cursor: pointer; border-color: #2c5282; color: #2c5282; }
.hanko.me.done { border-color: #c53030; color: #c53030; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #edf2f7; border-radius: 10px; padding: 2px 4px 2px 9px; font-size: 11px; margin: 1px 3px 1px 0; }
.chip b { cursor: pointer; color: #a0aec0; padding: 0 4px; } .chip b:hover { color: #c53030; }
.items select.addas { font-size: 11px; padding: 2px; border: 1px solid #cbd5e0; border-radius: 3px; }

.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin-top: 10px; }
.checklist .who { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 8px; border-radius: 4px; background: #f7fafc; border: 1px solid #e2e8f0; }
.checklist .who.on { background: #f0fff4; border-color: #9ae6b4; color: #22543d; }
.checkbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.matrix td, .matrix th { text-align: center; }
.matrix td.l, .matrix th.l { text-align: left; }
.cell-ok { color: #2f855a; font-weight: 700; } .cell-ng { color: #cbd5e0; }
.cell-ok small { font-weight: 400; color: #c53030; }
.warn { background: #fffaf0; border: 1px solid #fbd38d; color: #744210; border-radius: 6px; padding: 8px 12px; font-size: 12px; margin-bottom: 12px; }
.err-box { background: #fff5f5; border: 1px solid #feb2b2; color: #9b2c2c; border-radius: 6px; padding: 8px 12px; font-size: 12px; margin-top: 8px; white-space: pre-wrap; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px 16px; }
.settings-grid label { display: flex; flex-direction: column; font-size: 11px; color: #4a5568; gap: 3px; }
.settings-grid input, .settings-grid select { padding: 6px; border: 1px solid #cbd5e0; border-radius: 4px; font-size: 13px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; } .checks label { flex-direction: row; align-items: center; gap: 5px; font-size: 13px; color: #222; }
@media (max-width: 1150px) { .app { flex-direction: column; height: auto; } .sidebar { width: 100%; } .detail { grid-template-columns: 1fr; } }
