:root {
    --bg-color: #f4f4f4;
    --table-header-bg: #ddeedd;
    --border-color: #ccc;
    --row-height: 32px; /* Slightly taller for mobile touch targets, but compact visually */
    --primary-color: #2c3e50;
    --accent-color: #2980b9;
    --danger-color: #e74c3c;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
    background: var(--bg-color);
    height: 100vh;
    overflow: hidden; /* Prevent body scroll */
    font-size: 13px;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Control Panel */
.control-panel {
    padding: 8px;
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 4px;
}
.row:last-child { margin-bottom: 0; }

.spacer { flex: 1; }

button {
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
    border: 1px solid #999;
    border-radius: 4px;
    background: #eee;
}
button.primary { background: var(--accent-color); color: white; border: none; }
button.danger { background: var(--danger-color); color: white; border: none; }

input[type="text"] {
    padding: 4px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

/* Table */
.table-wrapper {
    flex: 1;
    overflow: auto; /* Internal scrolling */
    background: #fff;
    position: relative;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    min-width: 600px; /* Ensure horizontal scroll on small phones */
}

thead th {
    position: sticky;
    top: 0;
    background: var(--table-header-bg);
    border-bottom: 2px solid #aaa;
    z-index: 10;
    padding: 4px;
    font-weight: bold;
    font-size: 11px;
    text-align: left;
    height: var(--row-height);
}

tbody tr {
    height: var(--row-height);
    border-bottom: 1px solid #eee;
}
tbody tr:hover { background: #f9f9f9; }

td {
    padding: 2px 4px;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tooltip on hover for name inputs if truncated? 
   Native title attribute handles this partially, 
   but let's ensure inputs inside small cells don't break layout */

/* Sortable Headers */
th.col-name, th.col-rent {
    transition: background-color 0.2s;
    user-select: none;
}
th.col-name:hover, th.col-rent:hover {
    background-color: #d0e0d0;
}

/* Column Widths */
.col-check { width: 45px; text-align: center; padding: 2px; }
.col-name { width: 18%; min-width: 100px; } 
.col-rent { width: 70px; min-width: 70px; } 
.col-note { width: 12%; min-width: 60px; } 
.col-keyinfo { width: 12%; min-width: 60px; }
.col-vendor { width: 15%; min-width: 90px; }
.col-contact { width: 18%; min-width: 100px; }
.col-date { width: 8%; min-width: 70px; }
.col-files { width: 10%; min-width: 80px; text-align: center; }
.col-action { width: 50px; text-align: center; }

/* Inputs inside table */
td input, td select {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 12px;
    padding: 2px;
}
td input:focus, td select:focus {
    background: #eef;
    outline: none;
}

/* Vendor Combobox */
.vendor-combo {
    position: relative;
    width: 100%;
    margin: 0;
    padding: 0;
    line-height: 1;
    border: none;
    outline: none;
}
td .vendor-combo-input,
td .vendor-combo-input:focus {
    width: 100%;
    border: none !important;
    outline: none !important;
    background: transparent;
    font-size: 12px;
    padding: 2px;
    margin: 0;
    cursor: text;
    box-sizing: border-box;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
}
td .vendor-combo-input:focus {
    background: #eef;
}
.vendor-combo-dropdown {
    position: fixed;
    background: #fff;
    border: 1px solid #ccc;
    max-height: 180px;
    overflow-y: auto;
    z-index: 10000;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.vendor-combo-item {
    padding: 4px 6px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.vendor-combo-item:hover {
    background: #e8f0fe;
}
.vendor-combo-item.selected {
    background: #d0e0f0;
    font-weight: bold;
}

/* File Drop Area */
.file-drop-zone {
    border: 1px dashed #ccc;
    border-radius: 4px;
    text-align: center;
    color: #888;
    cursor: pointer;
    font-size: 10px;
    height: 24px;
    line-height: 22px;
    overflow: hidden;
}
.file-drop-zone.has-file {
    background: #e0f7fa;
    color: #006064;
    border-style: solid;
}
.file-drop-zone.dragover {
    background: #ffecb3;
    border-color: orange;
}

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal.hidden { display: none; }

.modal-content {
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-content.large {
    max-width: 800px;
}

/* Resizable Preview Modal */
#modal-preview .modal-content {
    resize: both;
    overflow: hidden; /* Required for resize handle */
    width: 80vw;
    height: 80vh;
    max-width: 98vw;
    max-height: 98vh;
    min-width: 300px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
}

#preview-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* Tabs in Modal */
.modal-header-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 15px;
}
.tab-btn {
    flex: 1;
    padding: 10px;
    background: #eee;
    border: none;
    border-radius: 4px 4px 0 0;
    font-weight: bold;
    color: #666;
    margin-right: 2px;
}
.tab-btn.active {
    background: var(--accent-color);
    color: white;
}
.tab-desc {
    font-size: 11px;
    color: #666;
    margin: -5px 0 10px 0;
}

textarea#textarea-bulk {
    width: 100%;
    height: 150px;
    font-size: 11px;
    margin-bottom: 10px;
}

.log-area {
    margin-top: 10px;
    background: #f8f8f8;
    border: 1px solid #ddd;
    padding: 8px;
    height: 150px;
    overflow-y: auto;
    font-size: 11px;
    white-space: pre-wrap;
}

.log-add { color: blue; }
.log-merge { color: green; font-weight: bold; }
.log-skip { color: #999; }

/* Vendor Search */
.vendor-search-row {
    margin: 8px 0 4px;
}
.vendor-search-row input {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 13px;
}

/* Vendor List */
#vendor-list {
    list-style: none;
    padding: 0;
    margin: 10px 0;
    max-height: 200px;
    overflow-y: auto;
}
#vendor-list li {
    display: flex;
    align-items: center;
    gap: 6px;
    border-bottom: 1px solid #eee;
    padding: 4px;
}
.vendor-edit-name {
    flex: 1;
    min-width: 0;
    padding: 3px 5px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 12px;
}
.vendor-edit-contact {
    width: 120px;
    padding: 3px 5px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 12px;
}
.vendor-edit-name:focus,
.vendor-edit-contact:focus {
    border-color: var(--accent-color);
    outline: none;
    background: #f0f6ff;
}

/* Save Button */
.save-btn {
    font-weight: bold;
    color: white;
    background: #e74c3c; /* Red */
    border: 1px solid #c0392b;
    min-width: 100px;
}
.save-btn:disabled {
    background: #eee;
    color: #555;
    border: 1px solid #ccc;
    cursor: default;
}
.save-btn.dirty {
    background: #d9534f; /* Active Red */
    border-color: #d43f3a;
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.8; }
    100% { opacity: 1; }
}

/* Worker Input */
.save-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.warning-text {
    color: var(--danger-color);
    font-weight: bold;
    font-size: 11px;
    animation: flash 2s infinite;
}
@keyframes flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.warning-text.hidden { display: none; }

.worker-input-group {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
}
#input-worker {
    width: 100px;
    padding: 2px 4px;
}

#btn-add-suumo {
    background-color: #9acd32; /* YellowGreen */
    color: white;
    border: none;
}
#btn-add-suumo:hover {
    background-color: #8bc34a;
}

/* Filter Buttons */
.filter-group {
    display: flex;
    gap: 1px;
    background: #ddd;
    padding: 2px;
    border-radius: 4px;
    align-items: stretch;
}
.filter-btn {
    border: none;
    background: #f8f8f8;
    padding: 4px 10px;
    font-size: 11px;
    cursor: pointer;
    border-radius: 2px;
    color: #333;
}
.filter-btn:hover {
    background: #eee;
}
.filter-btn.active {
    background: #2c3e50;
    color: white;
    font-weight: bold;
}

/* Row Diff States */
tr.row-holmes { background-color: #fff3e0; } /* Light Orange Base */
tr.row-other { background-color: #ffebee; } /* Light Red Base */

tr.row-new { background-color: #e6f2ff; } /* Light Blue */
tr.row-modified { background-color: #fff8e1; } /* Light Yellow */
tr.row-deleted { 
    background-color: #ffebee; /* Light Red */
    opacity: 0.7;
    text-decoration: line-through; /* Strikethrough for deleted rows */
}
tr.row-deleted td input, tr.row-deleted td select {
    text-decoration: line-through;
    pointer-events: none; /* Disable inputs on deleted rows */
}

/* Cell Diff States */
td.cell-modified {
    background-color: #fff1b8; /* Slightly darker yellow for cell highlight */
    position: relative;
}
td.cell-modified::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 0; height: 0;
    border-style: solid;
    border-width: 0 6px 6px 0;
    border-color: transparent #f39c12 transparent transparent;
}

/* Merge Tag */
.tag-merge {
    font-size: 9px;
    background: #ffcc80;
    color: #e65100;
    padding: 1px 3px;
    border-radius: 2px;
    margin-left: 4px;
    vertical-align: middle;
}
.tag-badge {
    font-size: 9px;
    padding: 1px 3px;
    border-radius: 2px;
    color: white;
    margin-left: 4px;
    vertical-align: text-top;
}
.tag-badge.plus { background: #27ae60; }
.tag-badge.minus { background: #c0392b; }

/* Drag Handle */
.drag-handle {
    cursor: grab;
    color: #aaa;
    font-size: 16px;
    font-weight: bold;
    margin-right: 2px;
    vertical-align: middle;
    display: inline-block;
}
.drag-handle:active {
    cursor: grabbing;
    color: #666;
}
.sortable-ghost {
    opacity: 0.4;
    background: #f0f0f0;
}
.sortable-drag {
    cursor: grabbing;
}

/* Help Modal */
.help-content {
    height: 90vh;
    display: flex;
    flex-direction: column;
}
.help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}
.help-body {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #fff;
    font-size: 13px;
    line-height: 1.7;
    text-align: left;
    color: #333;
}
.help-body h4 {
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 5px;
    margin-top: 25px;
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 15px;
}
.help-body h5 {
    margin-top: 15px;
    margin-bottom: 8px;
    color: #555;
    font-size: 13px;
    font-weight: bold;
}
.help-body p { margin-bottom: 10px; }
.help-body ul, .help-body ol {
    padding-left: 25px;
    margin-bottom: 15px;
}
.help-body li { margin-bottom: 6px; }
.help-body strong { color: #c0392b; }

/* History Table */
.history-list-wrapper {
    max-height: 400px;
    overflow-y: auto;
}
#history-table {
    width: 100%;
    font-size: 12px;
}
#history-table th { background: #eee; text-align: left; padding: 4px; }
#history-table td { border-bottom: 1px solid #ddd; padding: 4px; }

/* Context Menu */
.context-menu {
    position: fixed;
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: 2px 2px 8px rgba(0,0,0,0.2);
    border-radius: 4px;
    z-index: 9999;
    min-width: 120px;
    overflow: hidden;
}
.context-menu.hidden { display: none; }

.menu-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    color: #333;
    transition: background 0.1s;
}
.menu-item:hover {
    background: #f0f0f0;
}
.menu-item:active {
    background: #e0e0e0;
}
.menu-separator {
    height: 1px;
    background: #ddd;
    margin: 4px 0;
}
.menu-item.hidden { display: none; }

/* Link in Cell */
a.cell-link {
    color: #0066cc;
    text-decoration: underline;
    cursor: pointer;
    font-weight: bold;
    display: block; /* Hit area */
}
a.cell-link:hover {
    color: #003366;
}

/* Mobile Adjustments */
@media (max-width: 600px) {
    .control-panel { font-size: 11px; }
    button { padding: 6px; }
    #input-search { width: 80px; }
    .header-top { margin-bottom: 8px; border-bottom: 1px dashed #ccc; padding-bottom: 4px; }
    .worker-input-group label { display: none; } /* Save space */
}

/* Print Styles */
@media print {
    body {
        height: auto;
        overflow: visible;
        background: white;
        margin: 8mm; /* Slightly increased margin as requested */
    }
    
    /* Hide UI controls - Enhanced list */
    header, .control-panel, .modal, .header-top, .secondary-controls, .danger-zone, .save-group, .row {
        display: none !important;
    }
    
    /* Ensure table is visible */
    .table-wrapper {
        overflow: visible !important;
        display: block !important;
    }

    /* Hide specific columns (Action, Files, Checkbox) */
    .col-check, .col-files, .col-action, 
    thead th.col-check, thead th.col-files, thead th.col-action {
        display: none !important;
    }

    /* Adjust remaining columns for print */
    .col-name { width: 20% !important; }
    .col-rent { width: 10% !important; }
    .col-note { width: 15% !important; }
    .col-keyinfo { width: 15% !important; }
    .col-vendor { width: 15% !important; }
    .col-contact { width: 15% !important; }
    .col-date { width: 10% !important; }

    table {
        width: 100% !important;
        min-width: 100% !important;
        border: 1px solid #000;
        border-collapse: collapse;
    }

    td, th {
        border: 1px solid #000;
        color: black;
        white-space: normal;
        overflow: visible;
        font-size: 10pt;
        padding: 4px;
    }

    /* Inputs in print */
    td input, td select {
        border: none;
        background: transparent;
        padding: 0;
        margin: 0;
        width: 100%; /* Fill cell */
        -webkit-appearance: none;
        appearance: none;
        font-size: inherit;
        color: black;
    }
    td select { background-image: none; }
    
    @page { margin: 8mm; }
}