* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #fafafa;
    --panel-bg: #ffffff;
    --border: #000000;
    --border-light: #cccccc;
    --text: #000000;
    --text-light: #444444;
    --accent: #000000;
    --accent-hover: #333333;
    --danger: #000000;
    --success: #000000;
    --warning: #000000;
}

body {
    font-family: 'Times New Roman', Times, Georgia, serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    line-height: 1.6;
    letter-spacing: 0.02em;
}

.container {
    display: flex;
    height: 100vh;
}

/* Left Panel - Spreadsheet */
.left-panel {
    width: 420px;
    background: var(--panel-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 2px solid var(--border);
    background: var(--panel-bg);
}

.panel-header h2 {
    font-size: 18px;
    font-weight: normal;
    font-style: italic;
    letter-spacing: 0.05em;
}

/* Generic hide utility (modals have their own .modal.hidden rule).
   Uses !important so it always wins over element rules like
   .stat-row/.chart-section { display: flex } that appear later in this file
   and would otherwise override it (equal specificity, later rule wins). */
.hidden {
    display: none !important;
}

/* Feeding/Poop view toggle button in the panel header. */
.view-toggle {
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0;
    font-family: inherit;
    font-size: 11px;
    letter-spacing: 0.05em;
    padding: 5px 10px;
    cursor: pointer;
}

.view-toggle:hover {
    background: var(--text);
    color: white;
}

.spreadsheet-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

#feed-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

#feed-table thead,
#poop-table thead {
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
}

#feed-table th,
#poop-table th {
    padding: 6px 4px;
    text-align: left;
    font-weight: normal;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    /* Let header labels wrap instead of spilling into the next column
       (fixed table layout clips/overflows otherwise — was why SPITTLE and
       NOTES ran together). */
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
}

/* Date is wide enough to show the full value now that the Add button no longer
   occupies a column in this row. Notes spans columns 5+6. */
#feed-table th:nth-child(1) { width: 112px; }
#feed-table th:nth-child(2) { width: 98px; }
#feed-table th:nth-child(3) { width: 36px; }
#feed-table th:nth-child(4) { width: 56px; }
#feed-table th:nth-child(5) { width: 64px; }
#feed-table th:nth-child(6) { width: 28px; }

#feed-table {
    table-layout: fixed;
    font-size: 12px;
}

#feed-table td,
#poop-table td {
    padding: 4px 4px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
}

#feed-table tr,
#poop-table tr {
    position: relative;
}

#feed-table tbody tr:hover,
#poop-table tbody tr:hover {
    background: #f0f0f0;
}

#feed-table input,
#feed-table select,
#poop-table input,
#poop-table select {
    width: 100%;
    padding: 6px 4px;
    border: 1px solid transparent;
    background: transparent;
    font-size: 13px;
    font-family: inherit;
}

#feed-table input:focus,
#feed-table select:focus,
#poop-table input:focus,
#poop-table select:focus {
    outline: none;
    border-color: var(--accent);
    background: white;
}

#feed-table input[type="date"],
#poop-table input[type="date"] {
    width: 100%;
}

#feed-table input[type="number"],
#poop-table input[type="number"] {
    width: 100%;
    text-align: right;
}

#feed-table select,
#poop-table select {
    cursor: pointer;
}

.row-actions {
    text-align: center;
}

/* Custom 12-hour time picker (hour / minute / AM-PM dropdowns) */
.time-picker {
    display: flex;
    align-items: center;
    gap: 2px;
}

.time-picker .time-colon {
    font-size: 13px;
}

/* Picker inside a new-entry table row: compact white-boxed selects. */
#feed-table .time-picker,
#poop-table .time-picker {
    gap: 2px;
}

#feed-table .time-picker .time-colon,
#poop-table .time-picker .time-colon {
    margin: 0;
}

#feed-table .time-picker .time-select,
#poop-table .time-picker .time-select {
    width: auto;
    min-width: 0;
    padding: 4px 3px;
    border: 1px solid var(--border);
    background: white;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    /* Hide the native dropdown arrow so it can't overlap the digits in these
       narrow selects; the colons keep the hour:minute:ampm grouping clear. */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    text-align: center;
    text-align-last: center;
}

#feed-table .time-picker .time-select:focus,
#poop-table .time-picker .time-select:focus {
    outline: none;
    border-color: var(--text);
}

/* Picker inside the edit modal: match the other modal fields */
.modal-content .time-picker {
    gap: 6px;
}

.modal-content .time-picker .time-select {
    width: auto;
    flex: 1 1 0;
    min-width: 0;
    padding: 12px 6px;
    border: 1px solid var(--border);
    border-radius: 0;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}

/* Ensure notes and spittle columns handle overflow */
#feed-table .history-row td:nth-child(4),
#feed-table .history-row td:nth-child(5) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Expanded row shows full content */
#feed-table .history-row.expanded td:nth-child(4),
#feed-table .history-row.expanded td:nth-child(5) {
    white-space: normal;
    word-wrap: break-word;
    overflow: visible;
    text-overflow: clip;
}

.feed-row.history-row {
    cursor: pointer;
}

.feed-row.history-row:active {
    background: #e8e8e8;
}

.row-actions button {
    padding: 4px 6px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    background: transparent;
    color: var(--text-light);
}

.row-actions button:hover {
    background: var(--bg);
}

.row-actions .btn-save {
    color: var(--success);
}

.row-actions .btn-save:hover {
    background: #e8f5e9;
}

.row-actions .btn-delete {
    color: var(--danger);
}

.row-actions .btn-delete:hover {
    background: #ffebee;
}

.feed-row {
    transition: background 0.15s;
}

.feed-row:hover {
    background: #fafafa;
}


/* New entry row - distinct styling */
.feed-row.new-row {
    background: #f5f5f5;
    border-bottom: 1px solid var(--border);
}

.feed-row.new-row td {
    padding: 5px 4px;
    vertical-align: middle;
}

.feed-row.new-row input,
.feed-row.new-row select {
    background: white;
    border: 1px solid var(--border);
    border-radius: 0;
    font-family: inherit;
    font-size: 12px;
    padding: 3px 4px;
}

/* Give every control in the fields row the SAME box height and middle
   alignment so date / time / mL / spittle / notes line up cleanly, and keep
   the row compact. box-sizing makes the heights match despite differing
   borders/padding. */
.new-row-fields td > input,
.new-row-fields td > select,
.new-row-fields .time-picker .time-select {
    box-sizing: border-box;
    height: 28px;
    vertical-align: middle;
    margin: 0;
}

.new-row-fields .time-picker {
    height: 28px;
}

.feed-row.new-row input:focus,
.feed-row.new-row select:focus {
    border-color: var(--border);
    outline: 1px solid var(--border);
    outline-offset: 1px;
}

/* The Add button now lives on its own full-width row beneath the inputs, so it
   spans the table and the five input cells keep their column alignment. */
.new-row-action td {
    padding: 4px 4px 8px;
}

.feed-row.new-row .btn-add {
    background: var(--text);
    color: white;
    padding: 6px 14px;
    border-radius: 0;
    font-weight: normal;
    font-family: inherit;
    font-size: 11px;
    letter-spacing: 0.05em;
    border: 1px solid var(--border);
    cursor: pointer;
}

/* On its own dedicated row (feeding entry), the Add button spans full width. */
.new-row-action .btn-add {
    width: 100%;
}

/* Don't double-draw the divider between the fields row and its action row. */
.new-row-fields td {
    border-bottom: none;
}

/* Poop table mirrors the feeding table: fixed layout with Date / Time / Notes
   columns (the 4th is the action/edit column). */
#poop-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 12px;
}

#poop-table th:nth-child(1) { width: 112px; }
#poop-table th:nth-child(2) { width: 98px; }
#poop-table th:nth-child(3) { width: auto; }
#poop-table th:nth-child(4) { width: 28px; }

.feed-row.new-row .btn-add:hover {
    background: white;
    color: var(--text);
}

/* Historical rows - read-only display */
.feed-row.history-row td {
    padding: 4px 4px;
    font-size: 12px;
}

.feed-row.history-row:hover {
    background: #f0f0f0;
}

.history-time {
    font-weight: normal;
}

.history-amount {
    font-weight: normal;
    color: var(--text);
}

.history-spittle {
    color: var(--text);
    font-size: 11px;
    font-style: italic;
}

.history-notes {
    color: var(--text-light);
    font-size: 11px;
    font-style: italic;
}

/* Three-dot menu button */
.btn-menu {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}

.btn-menu:hover {
    background: var(--bg);
    color: var(--text);
}

.date-separator {
    background: var(--bg);
    font-weight: normal;
    font-size: 11px;
    font-style: italic;
    color: var(--text);
}

.date-separator td {
    padding: 6px 4px !important;
    border-bottom: 1px solid var(--border-light);
    letter-spacing: 0.03em;
}

/* Main Panel */
.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow: hidden;
}

.stats-section {
    margin-bottom: 12px;
}

.stats-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 11px;
    font-style: italic;
    color: var(--text-light);
}

.stats-header select {
    padding: 3px 6px;
    border: 1px solid var(--border-light);
    border-radius: 0;
    font-size: 11px;
    font-weight: normal;
    font-family: inherit;
}

.stat-row {
    display: flex;
    gap: 8px;
}

.stat-card {
    flex: 1;
    background: transparent;
    border: none;
    padding: 8px 12px;
    text-align: center;
}

.stat-label {
    font-size: 11px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.stat-value {
    font-size: 16px;
    font-weight: normal;
    color: var(--text);
    margin: 4px 0;
}

.stat-controls {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.stat-controls select {
    padding: 2px 4px;
    border: 1px solid var(--border-light);
    border-radius: 0;
    font-size: 10px;
    font-family: inherit;
}

.stat-card-wide {
    flex: 1.5;
}

.day-night-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin: 4px 0;
    font-size: 10px;
    color: var(--text-light);
}

.day-night-controls .time-picker {
    gap: 1px;
}

.day-night-controls .time-select {
    padding: 2px 4px;
    border: 1px solid var(--border-light);
    border-radius: 0;
    font-size: 10px;
    font-family: inherit;
    cursor: pointer;
    background: white;
    color: var(--text);
    /* Same fix as the new-entry picker: drop the native arrow so it can't
       obscure the digits in these tiny selects. */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    text-align: center;
    text-align-last: center;
}

.day-night-controls .time-colon {
    font-size: 10px;
}

.day-night-stats {
    display: flex;
    justify-content: center;
    gap: 16px;
    font-size: 11px;
}

.day-night-column {
    text-align: center;
}

.day-night-column .label {
    font-weight: normal;
    color: var(--text);
    margin-bottom: 2px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.day-night-column .total {
    font-size: 15px;
    font-weight: normal;
    color: var(--text);
}

.day-night-column .details {
    font-size: 11px;
    color: var(--text-light);
}

.chart-section {
    flex: 1;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chart-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
    justify-content: center;
}

.tab-btn {
    padding: 6px 16px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 0;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
}

.tab-btn:not(:first-child) {
    border-left: none;
}

.tab-btn.active {
    background: var(--text);
    color: white;
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    justify-content: center;
}

.nav-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 0;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
}

.nav-btn:hover {
    background: var(--text);
    color: white;
}

#chart-date-label {
    font-weight: 600;
    min-width: 100px;
    text-align: center;
    font-size: 14px;
}

#chart-container,
#poop-chart-container {
    flex: 1;
    /* min-height:0 lets the container shrink to fit the space left after the
       tabs/controls rows. A non-zero min-height (it used to be 250px) forces
       the container taller than its box, pushing the SVG's x-axis and the
       bottom of the y-axis out below the chart border. */
    min-height: 0;
    overflow: hidden;
}

/* Modal */
.modal {
    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: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 0;
    border: 2px solid var(--border);
    min-width: 300px;
    max-width: 380px;
}

.modal-content h3 {
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: normal;
    font-style: italic;
    letter-spacing: 0.05em;
}

.modal-content input,
.modal-content select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 0;
    font-size: 14px;
    font-family: inherit;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-buttons button {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 0;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    background: white;
    color: var(--text);
}

.modal-buttons button:hover {
    background: var(--text);
    color: white;
}

.modal-buttons button:first-child {
    background: white;
}

.modal-buttons button:last-child {
    background: var(--text);
    color: white;
}

.modal-buttons button:last-child:hover {
    background: white;
    color: var(--text);
}

.modal-buttons button.danger {
    background: white;
    color: var(--text);
    text-decoration: underline;
}

.modal-buttons button.danger:hover {
    background: var(--text);
    color: white;
}

.modal-buttons.three-buttons {
    gap: 8px;
}

.modal-buttons.three-buttons button {
    flex: none;
    padding: 10px 16px;
}

.modal-buttons.three-buttons button:first-child {
    margin-right: auto;
}

.error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 8px;
}

.error.hidden {
    display: none;
}

/* Chart Styles */
.line {
    fill: none;
    stroke: var(--text);
    stroke-width: 1.5;
}

.dot {
    fill: var(--text);
}

.density-area {
    fill: var(--text);
    opacity: 0.1;
}

.gap-bar {
    fill: var(--text);
    opacity: 0.75;
    cursor: pointer;
}

.gap-bar:hover {
    opacity: 1;
}

.axis text {
    font-size: 11px;
}

.axis path,
.axis line {
    stroke: var(--border);
}

.grid line {
    stroke: none;
}

.grid path {
    stroke-width: 0;
}

.tooltip {
    position: absolute;
    background: white;
    color: var(--text);
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 0;
    font-size: 13px;
    pointer-events: none;
    z-index: 50;
    font-family: 'Times New Roman', Times, Georgia, serif;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.1);
}

/* Responsive */
@media (max-width: 900px) {
    body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    .container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .left-panel {
        width: 100%;
        height: auto;
        max-height: 50vh;
        min-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .main-panel {
        width: 100%;
        flex: none;
        height: auto;
        min-height: 400px;
        overflow: visible;
    }

    /* Fixed-height chart box on mobile. With #chart-container at min-height:0
       the SVG fills exactly the space left after the tabs/controls rows, so
       nothing spills past this border. Tall enough to keep the plot usable. */
    .chart-section {
        flex: none;
        height: 380px;
    }

    .stat-row {
        flex-wrap: wrap;
    }

    .stat-card {
        min-width: calc(50% - 4px);
    }

    .stat-card-wide {
        min-width: 100%;
    }
}

@media (max-width: 500px) {
    .left-panel {
        max-height: 45vh;
    }

    .panel-header h2 {
        font-size: 14px;
    }

    #feed-table,
    #poop-table {
        font-size: 11px;
    }

    /* Date stays wide enough for the full value; the Add button is on its own
       row so the data columns don't have to make room for it. */
    #feed-table th:nth-child(1) { width: 100px; }
    #feed-table th:nth-child(2) { width: 84px; }
    #feed-table th:nth-child(3) { width: 30px; }
    #feed-table th:nth-child(4) { width: 48px; }
    #feed-table th:nth-child(5) { width: 52px; }
    #feed-table th:nth-child(6) { width: 26px; }

    #poop-table th:nth-child(1) { width: 100px; }
    #poop-table th:nth-child(2) { width: 84px; }
    #poop-table th:nth-child(3) { width: auto; }
    #poop-table th:nth-child(4) { width: 26px; }

    #feed-table .time-picker .time-select,
    #poop-table .time-picker .time-select {
        padding: 4px 2px;
        font-size: 12px;
    }

    .stat-card {
        min-width: 100%;
        padding: 6px 8px;
    }

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

    .day-night-controls {
        flex-wrap: wrap;
    }

    .nav-btn {
        padding: 4px 8px;
        font-size: 12px;
    }

    #chart-date-label {
        font-size: 12px;
        min-width: 80px;
    }
}
