/* CSS Custom Properties */
:root {
    --color-primary: #1a4d7c;
    --color-primary-dark: #0d3a5c;
    --color-cell: #b8d4e8;
    --color-cell-hover: #9ec5dd;
    --color-cell-filled: #7ab3d4;
    --color-orange: #e67e22;
    --color-bg: #ffffff;
    --color-text: #333333;
    --color-text-light: #ffffff;
    --color-border: #cccccc;
    --font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Base */
body {
    font-family: var(--font-main);
    background-color: #f5f5f5;
    color: var(--color-text);
    line-height: 1.4;
    min-height: 100vh;
    padding: 20px;
}

/* Container */
.container {
    max-width: 800px;
    margin: 0 auto;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
}

/* Header */
.header {
    background: var(--color-primary);
    color: var(--color-text-light);
    padding: 10px 15px;
}

.header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Input Section */
.input-section {
    padding: 15px;
    border-bottom: 1px solid var(--color-border);
}

.input-group {
    display: flex;
    gap: 10px;
}

.input-group input {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.9rem;
    border: 1px solid var(--color-border);
    outline: none;
}

.input-group input:focus {
    border-color: var(--color-primary);
}

/* Buttons */
.btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-add {
    background: var(--color-primary);
    color: white;
}

.btn-add:hover:not(:disabled) {
    background: var(--color-primary-dark);
}

.btn-clear {
    background: #dc3545;
    color: white;
}

.btn-clear:hover:not(:disabled) {
    background: #c82333;
}

/* Matrix Section */
.matrix-section {
    padding: 15px;
    overflow-x: auto;
}

.matrix-container {
    display: inline-block;
    min-width: 100%;
}

/* Matrix Table */
.matrix-table {
    border-collapse: collapse;
    font-size: 0.85rem;
}

.matrix-table td,
.matrix-table th {
    border: 1px solid var(--color-border);
    padding: 0;
    text-align: center;
    vertical-align: middle;
    min-width: 32px;
    height: 28px;
}

.matrix-table .item-row td {
    height: 28px;
    vertical-align: middle;
}

.matrix-table .item-row .cell-comparison {
    border: 1px solid var(--color-border);
}

.matrix-table .item-cell {
    border: none;
    text-align: left;
    padding: 2px 6px;
    white-space: nowrap;
}

.matrix-table .item-label {
    color: var(--color-orange);
    font-weight: 700;
}

.matrix-table .item-name {
    color: var(--color-text);
}

.matrix-table .item-delete {
    border: none;
    color: #999;
    cursor: pointer;
    padding: 0 6px;
    font-size: 1.1rem;
    text-align: center;
    background: transparent;
}

.matrix-table .item-delete:hover {
    color: #dc3545;
}

/* Matrix cells */
.matrix-table .spacer {
    border: none !important;
    background: transparent !important;
}

.matrix-table .cell-comparison {
    background: var(--color-cell);
    cursor: pointer;
    font-weight: 600;
    color: var(--color-primary-dark);
    min-width: 36px;
    width: 36px;
    text-align: center;
}

.matrix-table .cell-comparison:hover {
    background: var(--color-cell-hover);
}

.matrix-table .cell-comparison.filled {
    background: var(--color-cell-filled);
}

/* Header row */
.matrix-table .header-row td {
    background: var(--color-cell);
    font-weight: 600;
    color: var(--color-orange);
    border: 1px solid var(--color-border);
    min-width: 32px;
}

.matrix-table .header-row td:empty {
    background: transparent;
    border: none;
}

/* Count and Rank rows */
.matrix-table .count-row td,
.matrix-table .rank-row td {
    background: var(--color-cell);
    font-weight: 500;
    border: 1px solid var(--color-border);
}

.matrix-table .count-row td:empty,
.matrix-table .rank-row td:empty {
    background: transparent;
    border: none;
}

.matrix-table .count-row .label,
.matrix-table .rank-row .label {
    background: transparent;
    border: none;
    text-align: left;
    padding-left: 8px;
    color: var(--color-orange);
    font-weight: 600;
}

/* Results Section */
.results-section {
    margin: 0 15px 15px;
}

.results-header {
    background: var(--color-primary);
    color: var(--color-text-light);
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.9rem;
}

.results-list {
    border: 1px solid var(--color-border);
    border-top: none;
}

.result-row {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.85rem;
}

.result-row:last-child {
    border-bottom: none;
}

.result-rank {
    background: var(--color-cell);
    color: var(--color-orange);
    font-weight: 700;
    min-width: 28px;
    padding: 6px 8px;
    text-align: center;
    border-right: 1px solid var(--color-border);
}

.result-name {
    flex: 1;
    padding: 6px 10px;
    background: var(--color-cell);
}

.result-empty {
    color: #999;
}

/* Footer */
.footer {
    padding: 15px;
    text-align: center;
    border-top: 1px solid var(--color-border);
}

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

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    min-width: 280px;
    text-align: center;
}

.modal-title {
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--color-primary);
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.btn-modal {
    background: var(--color-cell);
    color: var(--color-text);
    padding: 12px 16px;
    font-weight: 500;
    border: 2px solid var(--color-border);
}

.btn-modal:hover {
    background: var(--color-cell-hover);
    border-color: var(--color-primary);
}

.btn-cancel {
    background: transparent;
    color: #666;
    font-size: 0.85rem;
}

.btn-cancel:hover {
    color: #333;
}

/* Responsive */
@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .matrix-table .item-name {
        max-width: 80px;
    }

    .modal {
        margin: 10px;
        min-width: auto;
        width: calc(100% - 20px);
    }
}
