* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: #f5f5f5;
    color: #333;
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.page-header h1 {
    margin: 0;
    font-size: 1.5rem;
}

.nav-links {
    display: flex;
    gap: 10px;
}

.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin-bottom: 20px;
}

.card h2 {
    margin-top: 0;
    font-size: 1.2rem;
    color: #444;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.form-group {
    flex: 1;
    min-width: 180px;
    display: flex;
    flex-direction: column;
}

.form-group-wide {
    flex: 2;
}

label {
    font-size: 0.9rem;
    margin-bottom: 5px;
    color: #555;
}

input[type="text"],
input[type="date"],
input[type="number"] {
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    min-height: 44px;
}

input[readonly] {
    background: #f0f0f0;
}

input:focus {
    outline: none;
    border-color: #007bff;
}

.panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    margin: 15px 0;
}

.panel {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 12px;
}

.panel h3 {
    margin-top: 0;
    font-size: 1rem;
    color: #555;
}

.item-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 220px;
    overflow-y: auto;
}

.item {
    padding: 10px 8px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 44px;
}

.item:last-child {
    border-bottom: none;
}

.item:hover {
    background: #e9f3ff;
}

.item strong {
    font-weight: 600;
}

.item span {
    font-size: 0.85rem;
    color: #666;
}

.empty {
    color: #888;
    font-size: 0.9rem;
    margin: 0;
}

.actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
}

.btn-primary {
    background: #007bff;
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #0056b3;
}

.btn-primary:disabled {
    background: #7fb8ff;
    cursor: not-allowed;
}

.btn-secondary {
    background: #6c757d;
    color: #fff;
    font-size: 0.9rem;
}

.btn-secondary:hover {
    background: #545b62;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
    background: #e9ecef;
    color: #333;
    margin-left: 8px;
    min-height: 36px;
}

.btn-small:hover {
    background: #d6d8db;
}

select {
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    background: #fff;
    min-height: 44px;
}

.tree {
    list-style: none;
    margin: 0;
    padding: 0;
}

.tree li {
    margin: 6px 0;
}

.tree ul {
    list-style: none;
    margin: 6px 0 6px 20px;
    padding: 0;
}

.tree-name,
.tree-form,
.tree-pack {
    cursor: pointer;
    font-weight: 600;
}

.tree-name:hover,
.tree-form:hover,
.tree-pack:hover {
    color: #007bff;
}

.tree-usage {
    display: flex;
    flex-direction: column;
    padding: 6px;
    background: #f8f9fa;
    border-radius: 4px;
}

.tree-usage small {
    color: #666;
}

.alert {
    padding: 12px 15px;
    border-radius: 4px;
    margin-bottom: 15px;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.hint {
    color: #666;
    font-size: 0.9rem;
    margin-top: 0;
    margin-bottom: 15px;
}

.receipt-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.receipt-tab {
    padding: 10px 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #f8f9fa;
    cursor: pointer;
    font-size: 0.95rem;
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 44px;
}

.receipt-tab:hover {
    background: #e9ecef;
}

.receipt-tab.active {
    background: #007bff;
    border-color: #007bff;
    color: #fff;
}

.receipt-tab-add {
    font-weight: bold;
    padding: 10px 14px;
}

.receipt-tab-content {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 15px;
}

.receipt-tab-content h3 {
    margin-top: 0;
    font-size: 1rem;
    color: #555;
}

.receipt-divider {
    border: none;
    border-top: 1px solid #e0e0e0;
    margin: 15px 0;
}

.drug-columns {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    align-items: start;
}

.drug-column {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 12px;
    min-height: 300px;
}

.column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.column-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #555;
}

.column-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.column-form input,
.column-form select {
    width: 100%;
    padding: 8px 10px;
    font-size: 0.95rem;
    min-height: 44px;
}

.column-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 400px;
    overflow-y: auto;
}

.column-item {
    padding: 10px 8px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.15s;
    min-height: 44px;
}

.column-item:last-child {
    border-bottom: none;
}

.column-item:hover {
    background: #e9f3ff;
}

.column-item.selected {
    background: #d4edda;
}

.column-item .item-label {
    display: block;
    font-weight: 500;
    word-break: break-word;
}

.column-item .item-meta {
    display: block;
    font-size: 0.85rem;
    color: #666;
}

.item-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.inline-edit {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.inline-edit input,
.inline-edit select {
    width: 100%;
    padding: 8px 10px;
    min-height: 44px;
}

.inline-edit-actions {
    display: flex;
    gap: 6px;
}

.btn-small.btn-primary {
    background: #007bff;
    color: #fff;
}

.btn-small.btn-primary:hover:not(:disabled) {
    background: #0056b3;
}

.btn-small.btn-danger {
    background: #dc3545;
    color: #fff;
}

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

.history-card {
    margin-top: 20px;
}

.history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    min-height: 60px;
}

.history-item {
    padding: 12px 10px;
    border-bottom: 1px solid #eee;
    cursor: default;
}

.history-item:last-child {
    border-bottom: none;
}

.history-item:hover {
    background: #f8f9fa;
}

.history-empty {
    text-align: center;
    padding: 20px 0;
}

.history-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.history-meta strong {
    font-weight: 600;
}

.history-meta span {
    font-size: 0.8rem;
    color: #888;
    white-space: nowrap;
}

.history-drugs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 4px 0;
}

.history-drug {
    font-size: 0.85rem;
    color: #555;
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
}

.history-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.history-actions .btn-small {
    margin-left: 0;
}

/* 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: 1000;
    padding: 20px;
}

.modal-content {
    background: #fff;
    border-radius: 8px;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.pdf-preview {
    flex: 1;
    min-height: 400px;
    border: none;
    width: 100%;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #eee;
}

@media (max-width: 900px) {
    .drug-columns {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .form-row {
        flex-direction: column;
        gap: 10px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .drug-columns {
        grid-template-columns: 1fr;
    }

    .modal-content {
        max-height: 95vh;
    }

    .pdf-preview {
        min-height: 300px;
    }
}
